FluidFramework
FluidFramework copied to clipboard
Allow more cases in Tree.is
Description
This makes 3 changes to Tree.is:
- calling Tree.is(node, SchemaNotUsedInTreeSchema) is no longer an error. This undocumented edge case could have been problematic, and is inconsistent since it would not fire if node was not a TreeNode.
- Tree.is now takes in ImplicitAllowedTypes, making cases like Tree.is(x, [schema.number, schema.string]) valid. THis is more performant and more concise then doing two separate checks and ORing them together. This also allows checking a node against an ImplicitAllowedTypes pulled from a FieldSchema which could be handy for some generic code.
- The implementation of Tree.schema and Tree.is have been rewritten to not rely on flex-schema as much, and fast path non-TreeNode inputs. This should make it more maintainable and more performant.
Interestingly #2 above is the only case that couldn't be covered by instanceof (assuming TypeScript 5.3): we could make instanceof do all narrowing currently done with Tree.is, except for this new case. The presence of this case thus seems to motivate keeping Tree.is if for no reason other than it can support this additional pattern which instancof cannot.
Reviewer Guidance
The review process is outlined on this wiki page.
This is a public API change, and thus needs extra review on the API and how it will impact customers.
⯅ @fluid-example/bundle-size-tests: +182 Bytes
| Metric Name | Baseline Size | Compare Size | Size Diff |
|---|---|---|---|
| aqueduct.js | 455.86 KB | 455.86 KB | ■ No change |
| azureClient.js | 552.43 KB | 552.43 KB | ■ No change |
| connectionState.js | 680 Bytes | 680 Bytes | ■ No change |
| containerRuntime.js | 258.9 KB | 258.9 KB | ■ No change |
| fluidFramework.js | 358 KB | 358.09 KB | ⯅ +91 Bytes |
| loader.js | 133.16 KB | 133.16 KB | ■ No change |
| map.js | 41.4 KB | 41.4 KB | ■ No change |
| matrix.js | 143.64 KB | 143.64 KB | ■ No change |
| odspClient.js | 520.77 KB | 520.77 KB | ■ No change |
| odspDriver.js | 97.1 KB | 97.1 KB | ■ No change |
| odspPrefetchSnapshot.js | 41.98 KB | 41.98 KB | ■ No change |
| sharedString.js | 161.32 KB | 161.32 KB | ■ No change |
| sharedTree.js | 357.99 KB | 358.08 KB | ⯅ +91 Bytes |
| Total Size | 3.2 MB | 3.2 MB | ⯅ +182 Bytes |
Baseline commit: 5a158353333bc43f2a23593a122e973fb6ffe45a
Generated by :no_entry_sign: dangerJS against ffabda265cf0d80a7426b5a943e922432867640b