-
Notifications
You must be signed in to change notification settings - Fork 549
refactor: Store data in unhydrated nodes directly instead of wrapping MapTree nodes #24739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ed52a5c
3d031e2
adec2a8
8a6c2a0
0e9c6d1
0d74576
5b2ca88
e812c58
1c6350c
29e0fad
3367466
78bdc8f
6c94fef
97aa5d7
234ff66
787f5c0
96b0472
b756abe
f11ccfe
0b364b0
ca39e57
ea9a42e
02f9245
07a47f8
db1306c
8d7531f
e320162
f45634c
dabd054
f0e50f3
900f39b
0936c25
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
"@fluidframework/tree": minor | ||
"fluid-framework": minor | ||
"__section": tree | ||
--- | ||
Defaulted identifier fields on unhydrated nodes are now enumerable | ||
Check failure on line 6 in .changeset/fruity-laws-rule.md
|
||
|
||
Previously, there was a special case for defaulted [identifier](https://fluidframework.com/docs/api/fluid-framework/schemafactory-class#identifier-property) fields on unhydrated nodes where they were not enumerable. | ||
Check failure on line 8 in .changeset/fruity-laws-rule.md
|
||
This special case has been removed: they are now enumerable independent of hydration status and defaulting. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,6 @@ import { isFluidHandle } from "@fluidframework/runtime-utils/internal"; | |
import { UsageError } from "@fluidframework/telemetry-utils/internal"; | ||
|
||
import type { TreeValue } from "../../core/index.js"; | ||
import type { NodeIdentifierManager } from "../../feature-libraries/index.js"; | ||
// This import is required for intellisense in @link doc comments on mouseover in VSCode. | ||
// eslint-disable-next-line unused-imports/no-unused-imports, @typescript-eslint/no-unused-vars | ||
import type { TreeAlpha } from "../../shared-tree/index.js"; | ||
|
@@ -26,6 +25,7 @@ import type { | |
TreeNodeSchemaClass, | ||
TreeNodeSchemaNonClass, | ||
TreeNodeSchemaBoth, | ||
UnhydratedFlexTreeNode, | ||
} from "../core/index.js"; | ||
import { isLazy } from "../flexList.js"; | ||
import { | ||
|
@@ -67,6 +67,10 @@ import { | |
|
||
import { createFieldSchemaUnsafe } from "./schemaFactoryRecursive.js"; | ||
import type { System_Unsafe, FieldSchemaAlphaUnsafe } from "./typesUnsafe.js"; | ||
import type { IIdCompressor } from "@fluidframework/id-compressor"; | ||
import { createIdCompressor } from "@fluidframework/id-compressor/internal"; | ||
import type { FlexTreeHydratedContextMinimal } from "../../feature-libraries/index.js"; | ||
import { mapTreeFromNodeData } from "../toMapTree.js"; | ||
|
||
/** | ||
* Gets the leaf domain schema compatible with a given {@link TreeValue}. | ||
|
@@ -296,9 +300,7 @@ export interface SchemaStatics { | |
) => System_Unsafe.FieldSchemaUnsafe<FieldKind.Required, T, TCustomMetadata>; | ||
} | ||
|
||
const defaultOptionalProvider: DefaultProvider = getDefaultProvider(() => { | ||
return undefined; | ||
}); | ||
const defaultOptionalProvider: DefaultProvider = getDefaultProvider(() => []); | ||
|
||
// The following overloads for optional and required are used to get around the fact that | ||
// the compiler can't infer that UnannotateImplicitAllowedTypes<T> is equal to T when T is known to extend ImplicitAllowedTypes | ||
|
@@ -1112,8 +1114,6 @@ export class SchemaFactory< | |
* | ||
* - A compressed form of the identifier can be accessed at runtime via the {@link TreeNodeApi.shortId|Tree.shortId()} API. | ||
* | ||
* - It will not be present in the object's iterable properties until explicitly read or until having been inserted into a tree. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This removal is the potentially breaking change noted in the changeset. |
||
* | ||
* However, a user may alternatively supply their own string as the identifier if desired (for example, if importing identifiers from another system). | ||
* In that case, if the user requires it to be unique, it is up to them to ensure uniqueness. | ||
* User-supplied identifiers may be read immediately, even before insertion into the tree. | ||
|
@@ -1122,10 +1122,19 @@ export class SchemaFactory< | |
*/ | ||
public get identifier(): FieldSchema<FieldKind.Identifier, typeof this.string> { | ||
const defaultIdentifierProvider: DefaultProvider = getDefaultProvider( | ||
(nodeKeyManager: NodeIdentifierManager) => { | ||
return nodeKeyManager.stabilizeNodeIdentifier( | ||
nodeKeyManager.generateLocalNodeIdentifier(), | ||
); | ||
( | ||
context: FlexTreeHydratedContextMinimal | "UseGlobalContext", | ||
): UnhydratedFlexTreeNode[] => { | ||
const id = | ||
context === "UseGlobalContext" | ||
? globalIdentifierAllocator.decompress( | ||
globalIdentifierAllocator.generateCompressedId(), | ||
) | ||
: context.nodeKeyManager.stabilizeNodeIdentifier( | ||
context.nodeKeyManager.generateLocalNodeIdentifier(), | ||
); | ||
|
||
return [mapTreeFromNodeData(id, this.string)]; | ||
}, | ||
); | ||
return createFieldSchema(FieldKind.Identifier, this.string, { | ||
|
@@ -1298,3 +1307,11 @@ export function structuralName<const T extends string>( | |
} | ||
return `${collectionName}<${inner}>`; | ||
} | ||
|
||
/** | ||
* Used to allocate default identifiers for unhydrated nodes when no context is available. | ||
* @remarks | ||
* The identifiers allocated by this will never be compressed to Short Ids. | ||
* Using this is only better than creating fully random V4 UUIDs because it reduces the entropy making it possible for things like text compression to work slightly better. | ||
*/ | ||
const globalIdentifierAllocator: IIdCompressor = createIdCompressor(); | ||
noencke marked this conversation as resolved.
Show resolved
Hide resolved
|
Uh oh!
There was an error while loading. Please reload this page.