FluidFramework icon indicating copy to clipboard operation
FluidFramework copied to clipboard

tree: Provide customized schema based instanceof behavior

Open CraigMacomber opened this issue 1 year ago • 2 comments

Description

instanceof should now work regardless of what the proxy does with the prototype chain. This makes structural lists and maps now work with it at runtime.

Currently instanceof structural;y named schema types only works at compile time with TreeNode not their actual schema classes. This is still a useful fix, and enables better support for instancof based narrowing of structual types in the future.

Reviewer Guidance

The review process is outlined on this wiki page.

CraigMacomber avatar Dec 18 '23 23:12 CraigMacomber

@fluid-example/bundle-size-tests: +572 Bytes
Metric NameBaseline SizeCompare SizeSize Diff
aqueduct.js 451.71 KB 451.71 KB No change
azureClient.js 550.21 KB 550.21 KB No change
connectionState.js 680 Bytes 680 Bytes No change
containerRuntime.js 255.74 KB 255.74 KB No change
fluidFramework.js 370.85 KB 371.13 KB +286 Bytes
loader.js 133.28 KB 133.28 KB No change
map.js 41.04 KB 41.04 KB No change
matrix.js 143.33 KB 143.33 KB No change
odspClient.js 518.28 KB 518.28 KB No change
odspDriver.js 97.19 KB 97.19 KB No change
odspPrefetchSnapshot.js 42.17 KB 42.17 KB No change
sharedString.js 159.84 KB 159.84 KB No change
sharedTree.js 370.83 KB 371.11 KB +286 Bytes
Total Size 3.21 MB 3.21 MB +572 Bytes

Baseline commit: c5ae39bb170f2a7596ca6a6726ee87e23003a2b4

Generated by :no_entry_sign: dangerJS against 8ce555c144e81eb00fdbd7e6a5769394d6c63dd7

msfluid-bot avatar Dec 18 '23 23:12 msfluid-bot

When this does get discussed, we should cover narrowing in general including:

  1. Will we be requiring es2022
  2. Will we be requiring TS 5.3
  3. How we want to select POJO mode (details in for how it currently works at https://github.com/microsoft/FluidFramework/blob/main/packages/dds/tree/src/simple-tree/schemaFactory.ts#L114-L144 ) and if we want to orthogonalize prototype swapping/hiding as its own distinct feature, supporting recursive POJO types across packages etc.
  4. How we will handle narrowing based on node kind (ex: do we want base classes for node kinds that we can use with instanceof and/or Tree.is)
  5. Do we want to support narrowing to other things, like sets of types (ex: allowedTypes) or structural sets of fields etc. and how that could work.
  6. Nominal node typing ( https://github.com/microsoft/FluidFramework/blob/main/packages/dds/tree/src/simple-tree/types.ts#L46-L69 )
  7. Type tag/constant field based narrowing

Related: (what versions of things we will target/require: https://dev.azure.com/fluidframework/internal/_workitems/edit/4730 )

CraigMacomber avatar Apr 03 '24 20:04 CraigMacomber

When this does get discussed, we should cover narrowing in general including:

  1. Will we be requiring es2022

We are currently on es2022, and have enabled the private brand on TreeNode. TreeNode has also been made to be type only exported, see https://github.com/microsoft/FluidFramework/pull/21351

  1. Will we be requiring TS 5.3

Yes.

  1. How we want to select POJO mode (details in for how it currently works at https://github.com/microsoft/FluidFramework/blob/main/packages/dds/tree/src/simple-tree/schemaFactory.ts#L114-L144 ) and if we want to orthogonalize prototype swapping/hiding as its own distinct feature, supporting recursive POJO types across packages etc.

This is still an open question.

  1. How we will handle narrowing based on node kind (ex: do we want base classes for node kinds that we can use with instanceof and/or Tree.is)

This is lower priority as we currently don't have use cases, and using Tree.schema(node).kind works for now.

  1. Do we want to support narrowing to other things, like sets of types (ex: allowedTypes) or structural sets of fields etc. and how that could work.

Tree.is is being kept which provides this functionality.

  1. Nominal node typing ( https://github.com/microsoft/FluidFramework/blob/main/packages/dds/tree/src/simple-tree/types.ts#L46-L69 )

https://github.com/microsoft/FluidFramework/pull/21351 provides that.

  1. Type tag/constant field based narrowing

This is planned work for post 2.0, but only handles separating unions, not down-casting from TreeNode.

Related: (what versions of things we will target/require: https://dev.azure.com/fluidframework/internal/_workitems/edit/4730 )

Thats done.

Internal doc tracking down casting design detailed above: https://microsoft.sharepoint-df.com/:fl:/g/contentstorage/CSP_22ee4cc9-dd0b-470b-8c5e-dc75391d129d/EaV2HmMcVkNKiiR4fKLbGvIB6Ndl8JMxEPDN6Z1YUYDbLA?e=2Um5mo&nav=cz0lMkZjb250ZW50c3RvcmFnZSUyRkNTUF8yMmVlNGNjOS1kZDBiLTQ3MGItOGM1ZS1kYzc1MzkxZDEyOWQmZD1iJTIxeGVzMC1kU3hpazY4cGc5MzUybVJKT0dGblZPSDdwdE9pWWt2QjhVZHBsSVlPd0lRWjBGbVE2YVR5OWNCcWVMNiZmPTAxUU5RQlFITkZPWVBHR0hDV0lORklVSkRZUFNSTldHWFMmYz0lMkYmYT1Mb29wQXBwJnA9JTQwZmx1aWR4JTJGbG9vcC1wYWdlLWNvbnRhaW5lciZ4PSU3QiUyMnclMjIlM0ElMjJUMFJUVUh4dGFXTnliM052Wm5RdWMyaGhjbVZ3YjJsdWRDMWtaaTVqYjIxOFlpRjRaWE13TFdSVGVHbHJOamh3Wnprek5USnRVa3BQUjBadVZrOUlOM0IwVDJsWmEzWkNPRlZrY0d4SldVOTNTVkZhTUVadFVUWmhWSGs1WTBKeFpVdzJmREF4VVU1UlFsRklUa3hFUnpkRk0wZENXVU0xUjFrM05VaFRSa0pDTWpKSlYwNCUzRCUyMiUyQyUyMmklMjIlM0ElMjJiMDQ5OGE5Mi03MzlhLTQ0YTMtOGQyNS03YTkxNzgwNjU0ZWIlMjIlN0Q%3D

CraigMacomber avatar Jun 12 '24 16:06 CraigMacomber