@fluidframework/tree 2.61.0-356312 → 2.61.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.d.ts.map +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/simple-tree/api/dirtyIndex.js +7 -7
- package/dist/simple-tree/api/dirtyIndex.js.map +1 -1
- package/dist/simple-tree/core/treeNodeKernel.js +4 -4
- package/dist/simple-tree/core/treeNodeKernel.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.d.ts.map +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/simple-tree/api/dirtyIndex.js +7 -7
- package/lib/simple-tree/api/dirtyIndex.js.map +1 -1
- package/lib/simple-tree/core/treeNodeKernel.js +4 -4
- package/lib/simple-tree/core/treeNodeKernel.js.map +1 -1
- package/package.json +20 -20
- package/src/packageVersion.ts +1 -1
- package/src/simple-tree/api/dirtyIndex.ts +7 -7
- package/src/simple-tree/core/treeNodeKernel.ts +4 -4
package/CHANGELOG.md
CHANGED
package/dist/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluidframework/tree";
|
|
8
|
-
export declare const pkgVersion = "2.61.0
|
|
8
|
+
export declare const pkgVersion = "2.61.0";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,yBAAyB,CAAC;AAC9C,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,yBAAyB,CAAC;AAC9C,eAAO,MAAM,UAAU,WAAW,CAAC"}
|
package/dist/packageVersion.js
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.pkgVersion = exports.pkgName = void 0;
|
|
10
10
|
exports.pkgName = "@fluidframework/tree";
|
|
11
|
-
exports.pkgVersion = "2.61.0
|
|
11
|
+
exports.pkgVersion = "2.61.0";
|
|
12
12
|
//# sourceMappingURL=packageVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,sBAAsB,CAAC;AACjC,QAAA,UAAU,GAAG,
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,sBAAsB,CAAC;AACjC,QAAA,UAAU,GAAG,QAAQ,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/tree\";\nexport const pkgVersion = \"2.61.0\";\n"]}
|
|
@@ -40,8 +40,8 @@ function createDirtyVisitor(forest, dirty) {
|
|
|
40
40
|
let parent;
|
|
41
41
|
return (0, index_js_1.createAnnouncedVisitor)({
|
|
42
42
|
beforeDetach: (src) => {
|
|
43
|
-
(0, internal_1.assert)(parent !== undefined,
|
|
44
|
-
(0, internal_1.assert)(parentField !== undefined,
|
|
43
|
+
(0, internal_1.assert)(parent !== undefined, 0xc48 /* Expected node */);
|
|
44
|
+
(0, internal_1.assert)(parentField !== undefined, 0xc49 /* Expected field */);
|
|
45
45
|
for (let parentIndex = src.start; parentIndex < src.end; parentIndex++) {
|
|
46
46
|
const path = {
|
|
47
47
|
parent,
|
|
@@ -62,8 +62,8 @@ function createDirtyVisitor(forest, dirty) {
|
|
|
62
62
|
}
|
|
63
63
|
},
|
|
64
64
|
afterAttach: (_, dst) => {
|
|
65
|
-
(0, internal_1.assert)(parent !== undefined,
|
|
66
|
-
(0, internal_1.assert)(parentField !== undefined,
|
|
65
|
+
(0, internal_1.assert)(parent !== undefined, 0xc4a /* Expected node */);
|
|
66
|
+
(0, internal_1.assert)(parentField !== undefined, 0xc4b /* Expected field */);
|
|
67
67
|
for (let parentIndex = dst.start; parentIndex < dst.end; parentIndex++) {
|
|
68
68
|
const path = {
|
|
69
69
|
parent,
|
|
@@ -83,7 +83,7 @@ function createDirtyVisitor(forest, dirty) {
|
|
|
83
83
|
}
|
|
84
84
|
},
|
|
85
85
|
enterNode(index) {
|
|
86
|
-
(0, internal_1.assert)(parentField !== undefined,
|
|
86
|
+
(0, internal_1.assert)(parentField !== undefined, 0xc4c /* Expected field */);
|
|
87
87
|
parent = {
|
|
88
88
|
parent,
|
|
89
89
|
parentField,
|
|
@@ -92,7 +92,7 @@ function createDirtyVisitor(forest, dirty) {
|
|
|
92
92
|
parentField = undefined;
|
|
93
93
|
},
|
|
94
94
|
exitNode() {
|
|
95
|
-
(0, internal_1.assert)(parent !== undefined,
|
|
95
|
+
(0, internal_1.assert)(parent !== undefined, 0xc4d /* Expected node */);
|
|
96
96
|
parentField = parent.parentField;
|
|
97
97
|
parent = parent.parent;
|
|
98
98
|
},
|
|
@@ -107,7 +107,7 @@ function createDirtyVisitor(forest, dirty) {
|
|
|
107
107
|
function getNodeAtPath(forest, path) {
|
|
108
108
|
const cursor = forest.allocateCursor();
|
|
109
109
|
forest.moveCursorToPath(path, cursor);
|
|
110
|
-
(0, internal_1.assert)(cursor.mode === 0 /* CursorLocationType.Nodes */,
|
|
110
|
+
(0, internal_1.assert)(cursor.mode === 0 /* CursorLocationType.Nodes */, 0xc4e /* attach should happen in a node */);
|
|
111
111
|
const anchor = cursor.buildAnchor();
|
|
112
112
|
const anchorNode = forest.anchors.locate(anchor);
|
|
113
113
|
cursor.free();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dirtyIndex.js","sourceRoot":"","sources":["../../../src/simple-tree/api/dirtyIndex.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAC7D,kDAO6B;AAC7B,+CAAgE;AAyBhE;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,eAAe,CAC9B,IAAwC,EACxC,KAAmB;IAEnB,MAAM,MAAM,GAAI,IAAwD,CAAC,QAAQ,CAAC,MAAM,CAAC;IACzF,MAAM,gBAAgB,GAAG,GAAqB,EAAE,CAAC,kBAAkB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACnF,MAAM,CAAC,wBAAwB,CAAC,gBAAgB,CAAC,CAAC;IAClD,OAAO,GAAG,EAAE;QACX,MAAM,CAAC,0BAA0B,CAAC,gBAAgB,CAAC,CAAC;IACrD,CAAC,CAAC;AACH,CAAC;AAVD,0CAUC;AAED,SAAS,kBAAkB,CAAC,MAAuB,EAAE,KAAmB;IACvE,uHAAuH;IACvH,6FAA6F;IAC7F,IAAI,WAAiC,CAAC;IACtC,IAAI,MAA0B,CAAC;IAE/B,OAAO,IAAA,iCAAsB,EAAC;QAC7B,YAAY,EAAE,CAAC,GAAG,EAAE,EAAE;YACrB,IAAA,iBAAM,EAAC,MAAM,KAAK,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"dirtyIndex.js","sourceRoot":"","sources":["../../../src/simple-tree/api/dirtyIndex.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAC7D,kDAO6B;AAC7B,+CAAgE;AAyBhE;;;;;;;;;;;;;;;G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ved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tcreateAnnouncedVisitor,\n\tCursorLocationType,\n\ttype AnnouncedVisitor,\n\ttype FieldKey,\n\ttype IEditableForest,\n\ttype UpPath,\n} from \"../../core/index.js\";\nimport { TreeNode, treeNodeFromAnchor } from \"../core/index.js\";\nimport type { TreeViewAlpha } from \"./tree.js\";\nimport type { SchematizingSimpleTreeView } from \"../../shared-tree/index.js\";\nimport type { ImplicitFieldSchema } from \"../fieldSchema.js\";\n\n/**\n * The status of a node in a that has been {@link trackDirtyNodes | tracked for changes}.\n * @remarks Nodes can be marked \"new\", \"changed\", or \"moved\", with \"new\" taking precedence over \"changed\" and \"changed\" taking precedence over \"moved\".\n * * \"new\": The node was added.\n * * \"changed\": A direct child was updated, added, removed, or moved (and the node is not \"new\").\n * * \"moved\": The node was moved between/within arrays (and the node is not \"new\" or \"changed\").\n * @alpha\n */\nexport type DirtyTreeStatus = \"new\" | \"changed\" | \"moved\";\n\n/**\n * A map-like interface for tracking the {@link DirtyTreeStatus | status} of nodes that have been {@link trackDirtyNodes | tracked for changes}.\n * @privateRemarks TODO: Replace this with `MapGetSet` from `@fluidframework/core-interfaces`.\n * @alpha\n */\nexport interface DirtyTreeMap {\n\tget(node: TreeNode): DirtyTreeStatus | undefined;\n\tset(node: TreeNode, status: DirtyTreeStatus): void;\n}\n\n/**\n * Registers a visitor on the view's forest that tracks which nodes are dirty.\n * @param view - The view to track dirty nodes on\n * @param dirty - A {@link DirtyTreeMap | map} that will be updated over time to reflect the {@link DirtyTreeStatus | status} of nodes as they change.\n * Nodes that have not changed will not be inserted/updated in the map.\n * @returns a cleanup function that should be called when the tracking is no longer needed.\n * @example\n * ```typescript\n * const dirty = new Map<TreeNode, DirtyTreeStatus>();\n * const stopTracking = trackDirtyNodes(view, dirty);\n * // ... make changes to the view ...\n * console.log(`The root of the tree is ${dirty.get(view.root) ?? \"unchanged\"}`);\n * stopTracking();\n * ```\n * @alpha\n */\nexport function trackDirtyNodes(\n\tview: TreeViewAlpha<ImplicitFieldSchema>,\n\tdirty: DirtyTreeMap,\n): () => void {\n\tconst forest = (view as SchematizingSimpleTreeView<ImplicitFieldSchema>).checkout.forest;\n\tconst announcedVisitor = (): AnnouncedVisitor => createDirtyVisitor(forest, dirty);\n\tforest.registerAnnouncedVisitor(announcedVisitor);\n\treturn () => {\n\t\tforest.deregisterAnnouncedVisitor(announcedVisitor);\n\t};\n}\n\nfunction createDirtyVisitor(forest: IEditableForest, dirty: DirtyTreeMap): AnnouncedVisitor {\n\t// When cursor is in Fields mode, `parentField` is the field and `parent` is the parent node above that field (if any).\n\t// When cursor is in Nodes mode, `parent` is the current node and `parentField` is undefined.\n\tlet parentField: FieldKey | undefined;\n\tlet parent: UpPath | undefined;\n\n\treturn createAnnouncedVisitor({\n\t\tbeforeDetach: (src) => {\n\t\t\tassert(parent !== undefined, 0xc48 /* Expected node */);\n\t\t\tassert(parentField !== undefined, 0xc49 /* Expected field */);\n\t\t\tfor (let parentIndex = src.start; parentIndex < src.end; parentIndex++) {\n\t\t\t\tconst path: UpPath = {\n\t\t\t\t\tparent,\n\t\t\t\t\tparentField,\n\t\t\t\t\tparentIndex,\n\t\t\t\t};\n\t\t\t\t// The only way a detached node can be re-attached (and become visible/usable again) is via a move, so mark it as moved ahead of time.\n\t\t\t\tconst node = getNodeAtPath(forest, path);\n\t\t\t\tif (node !== undefined && dirty.get(node) === undefined) {\n\t\t\t\t\t// Only mark the node as moved if it is not already marked as something else.\n\t\t\t\t\tdirty.set(node, \"moved\");\n\t\t\t\t}\n\t\t\t\t// Mark the parent as changed unless it is already marked as new.\n\t\t\t\tconst parentNode = getNodeAtPath(forest, parent);\n\t\t\t\tif (parentNode !== undefined && dirty.get(parentNode) !== \"new\") {\n\t\t\t\t\tdirty.set(parentNode, \"changed\");\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\tafterAttach: (_, dst) => {\n\t\t\tassert(parent !== undefined, 0xc4a /* Expected node */);\n\t\t\tassert(parentField !== undefined, 0xc4b /* Expected field */);\n\t\t\tfor (let parentIndex = dst.start; parentIndex < dst.end; parentIndex++) {\n\t\t\t\tconst path: UpPath = {\n\t\t\t\t\tparent,\n\t\t\t\t\tparentField,\n\t\t\t\t\tparentIndex,\n\t\t\t\t};\n\t\t\t\tconst node = getNodeAtPath(forest, path);\n\t\t\t\tif (node !== undefined && dirty.get(node) === undefined) {\n\t\t\t\t\t// Only mark the node as new if it is not already marked as something else - this ensures that a moved node is not marked as new (since nodes are marked move when detached).\n\t\t\t\t\tdirty.set(node, \"new\");\n\t\t\t\t}\n\t\t\t\t// Mark the parent as changed unless it is already marked as new.\n\t\t\t\tconst parentNode = getNodeAtPath(forest, parent);\n\t\t\t\tif (parentNode !== undefined && dirty.get(parentNode) !== \"new\") {\n\t\t\t\t\tdirty.set(parentNode, \"changed\");\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\tenterNode(index: number): void {\n\t\t\tassert(parentField !== undefined, 0xc4c /* Expected field */);\n\t\t\tparent = {\n\t\t\t\tparent,\n\t\t\t\tparentField,\n\t\t\t\tparentIndex: index,\n\t\t\t};\n\t\t\tparentField = undefined;\n\t\t},\n\t\texitNode(): void {\n\t\t\tassert(parent !== undefined, 0xc4d /* Expected node */);\n\t\t\tparentField = parent.parentField;\n\t\t\tparent = parent.parent;\n\t\t},\n\t\tenterField: (key: FieldKey) => {\n\t\t\tparentField = key;\n\t\t},\n\t\texitField(): void {\n\t\t\tparentField = undefined;\n\t\t},\n\t});\n}\n\nfunction getNodeAtPath(forest: IEditableForest, path: UpPath): TreeNode | undefined {\n\tconst cursor = forest.allocateCursor();\n\tforest.moveCursorToPath(path, cursor);\n\tassert(cursor.mode === CursorLocationType.Nodes, 0xc4e /* attach should happen in a node */);\n\tconst anchor = cursor.buildAnchor();\n\tconst anchorNode = forest.anchors.locate(anchor);\n\tcursor.free();\n\tif (anchorNode !== undefined) {\n\t\tconst node = treeNodeFromAnchor(anchorNode);\n\t\tif (node instanceof TreeNode) {\n\t\t\treturn node;\n\t\t}\n\t}\n\treturn undefined;\n}\n"]}
|
|
@@ -351,7 +351,7 @@ class KernelEventBuffer {
|
|
|
351
351
|
// Lazily bind event listeners to the source.
|
|
352
352
|
// If we do not have any existing listeners for this event, then we need to bind to the source.
|
|
353
353
|
if (!__classPrivateFieldGet(this, _KernelEventBuffer_events, "f").hasListeners(eventName)) {
|
|
354
|
-
(0, internal_1.assert)(!__classPrivateFieldGet(this, _KernelEventBuffer_disposeSourceListeners, "f").has(eventName),
|
|
354
|
+
(0, internal_1.assert)(!__classPrivateFieldGet(this, _KernelEventBuffer_disposeSourceListeners, "f").has(eventName), 0xc4f /* Should not have a dispose function without listeners */);
|
|
355
355
|
const off = __classPrivateFieldGet(this, _KernelEventBuffer_eventSource, "f").on(eventName, (args) => __classPrivateFieldGet(this, _KernelEventBuffer_instances, "m", _KernelEventBuffer_emit).call(this, eventName, args));
|
|
356
356
|
__classPrivateFieldGet(this, _KernelEventBuffer_disposeSourceListeners, "f").set(eventName, off);
|
|
357
357
|
}
|
|
@@ -387,7 +387,7 @@ class KernelEventBuffer {
|
|
|
387
387
|
if (__classPrivateFieldGet(this, _KernelEventBuffer_disposed, "f")) {
|
|
388
388
|
return;
|
|
389
389
|
}
|
|
390
|
-
(0, internal_1.assert)(__classPrivateFieldGet(this, _KernelEventBuffer_childrenChangedBuffer, "f").size === 0 && !__classPrivateFieldGet(this, _KernelEventBuffer_subTreeChangedBuffer, "f"),
|
|
390
|
+
(0, internal_1.assert)(__classPrivateFieldGet(this, _KernelEventBuffer_childrenChangedBuffer, "f").size === 0 && !__classPrivateFieldGet(this, _KernelEventBuffer_subTreeChangedBuffer, "f"), 0xc52 /* Buffered kernel events should have been flushed before disposing. */);
|
|
391
391
|
__classPrivateFieldGet(this, _KernelEventBuffer_disposeOnFlushListener, "f").call(this);
|
|
392
392
|
__classPrivateFieldGet(this, _KernelEventBuffer_disposeSourceListeners, "f").forEach((off) => off());
|
|
393
393
|
__classPrivateFieldGet(this, _KernelEventBuffer_disposeSourceListeners, "f").clear();
|
|
@@ -400,7 +400,7 @@ _KernelEventBuffer_disposed = new WeakMap(), _KernelEventBuffer_disposeOnFlushLi
|
|
|
400
400
|
__classPrivateFieldGet(this, _KernelEventBuffer_instances, "m", _KernelEventBuffer_assertNotDisposed).call(this);
|
|
401
401
|
switch (eventName) {
|
|
402
402
|
case "childrenChangedAfterBatch":
|
|
403
|
-
(0, internal_1.assert)(arg !== undefined,
|
|
403
|
+
(0, internal_1.assert)(arg !== undefined, 0xc50 /* childrenChangedAfterBatch should have arg */);
|
|
404
404
|
return __classPrivateFieldGet(this, _KernelEventBuffer_instances, "m", _KernelEventBuffer_handleChildrenChangedAfterBatch).call(this, arg.changedFields);
|
|
405
405
|
case "subtreeChangedAfterBatch":
|
|
406
406
|
return __classPrivateFieldGet(this, _KernelEventBuffer_instances, "m", _KernelEventBuffer_handleSubtreeChangedAfterBatch).call(this);
|
|
@@ -424,7 +424,7 @@ _KernelEventBuffer_disposed = new WeakMap(), _KernelEventBuffer_disposeOnFlushLi
|
|
|
424
424
|
__classPrivateFieldGet(this, _KernelEventBuffer_events, "f").emit("subtreeChangedAfterBatch");
|
|
425
425
|
}
|
|
426
426
|
}, _KernelEventBuffer_assertNotDisposed = function _KernelEventBuffer_assertNotDisposed() {
|
|
427
|
-
(0, internal_1.assert)(!__classPrivateFieldGet(this, _KernelEventBuffer_disposed, "f"),
|
|
427
|
+
(0, internal_1.assert)(!__classPrivateFieldGet(this, _KernelEventBuffer_disposed, "f"), 0xc51 /* Event handler disposed. */);
|
|
428
428
|
};
|
|
429
429
|
/**
|
|
430
430
|
* Narrows innerNode to either {@link UnhydratedFlexTreeNode} or {@link HydratedFlexTreeNode}.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"treeNodeKernel.js","sourceRoot":"","sources":["../../../src/simple-tree/core/treeNodeKernel.ts"],"names":[],"mappings":";AAAA;;;GAG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E,WAAwE,CAAC,MAAM,CAChF,QAAQ,CACR,CAAC;AACL,CAAC;AARD,0DAQC;AAED;;;;;GAKG;AACU,QAAA,iBAAiB,GAAG,IAAA,qBAAU,GAAmB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { createEmitter } from \"@fluid-internal/client-utils\";\nimport type { HasListeners, Listenable, Off } from \"@fluidframework/core-interfaces/internal\";\nimport {\n\tassert,\n\tfail,\n\tdebugAssert,\n\tunreachableCase,\n} from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\tanchorSlot,\n\ttype AnchorEvents,\n\ttype AnchorNode,\n\ttype AnchorSet,\n\ttype FieldKey,\n\ttype TreeValue,\n\ttype UpPath,\n} from \"../../core/index.js\";\nimport { getOrCreateHydratedFlexTreeNode } from \"../../feature-libraries/index.js\";\nimport {\n\tassertFlexTreeEntityNotFreed,\n\tContextSlot,\n\tflexTreeSlot,\n\tLazyEntity,\n\tTreeStatus,\n\ttreeStatusFromAnchorCache,\n\ttype FlexTreeNode,\n\ttype HydratedFlexTreeNode,\n} from \"../../feature-libraries/index.js\";\n\nimport type { Context, HydratedContext } from \"./context.js\";\nimport type { TreeNode } from \"./treeNode.js\";\nimport type { TreeNodeSchema } from \"./treeNodeSchema.js\";\nimport type { InternalTreeNode, Unhydrated } from \"./types.js\";\nimport { UnhydratedFlexTreeNode } from \"./unhydratedFlexTree.js\";\n\nconst treeNodeToKernel = new WeakMap<TreeNode, TreeNodeKernel>();\n\nexport function getKernel(node: TreeNode): TreeNodeKernel {\n\tconst kernel = treeNodeToKernel.get(node);\n\tassert(kernel !== undefined, 0x9b1 /* Expected tree node to have kernel */);\n\treturn kernel;\n}\n\n/**\n * Detects if the given 'candidate' is a TreeNode.\n *\n * @remarks\n * Supports both Hydrated and {@link Unhydrated} TreeNodes, both of which return true.\n *\n * Because the common usage is to check if a value being inserted/set is a TreeNode,\n * this function permits calling with primitives as well as objects.\n *\n * Primitives will always return false (as they are copies of data, not references to nodes).\n *\n * @param candidate - Value which may be a TreeNode\n * @returns true if the given 'candidate' is a hydrated TreeNode.\n */\nexport function isTreeNode(candidate: unknown): candidate is TreeNode | Unhydrated<TreeNode> {\n\treturn treeNodeToKernel.has(candidate as TreeNode);\n}\n\n/**\n * Returns a schema for a value if the value is a {@link TreeNode}.\n *\n * Returns undefined for other values.\n * @remarks\n * Does not give schema for a {@link TreeLeafValue}.\n */\nexport function tryGetTreeNodeSchema(value: unknown): undefined | TreeNodeSchema {\n\tconst kernel = treeNodeToKernel.get(value as TreeNode);\n\treturn kernel?.schema;\n}\n\n/** The {@link HydrationState} of a {@link TreeNodeKernel} before the kernel is hydrated */\ninterface UnhydratedState {\n\treadonly innerNode: UnhydratedFlexTreeNode;\n}\n\n/** The {@link HydrationState} of a {@link TreeNodeKernel} after the kernel is hydrated */\ninterface HydratedState {\n\t/** The flex node for this kernel (lazy - undefined if it has not yet been demanded) */\n\tinnerNode?: FlexTreeNode;\n\t/** The {@link AnchorNode} that this node is associated with. */\n\treadonly anchorNode: AnchorNode;\n\t/** All {@link Off | event deregistration functions} that should be run when the kernel is disposed. */\n\treadonly offAnchorNode: Set<Off>;\n}\n\n/** State within a {@link TreeNodeKernel} that is related to the hydration process */\ntype HydrationState = UnhydratedState | HydratedState;\n\n/** True if and only if the given {@link HydrationState} is post-hydration */\nfunction isHydrated(state: HydrationState): state is HydratedState {\n\treturn (state as Partial<HydratedState>).anchorNode !== undefined;\n}\n\n/**\n * Contains state and an internal API for managing {@link TreeNode}s.\n * @remarks All {@link TreeNode}s have an associated kernel object.\n * The kernel has the same lifetime as the node and spans both its unhydrated and hydrated states.\n */\nexport class TreeNodeKernel {\n\tprivate disposed = false;\n\n\t/**\n\t * Generation number which is incremented any time we have an edit on the node.\n\t * Used during iteration to make sure there has been no edits that were concurrently made.\n\t * @remarks\n\t * This is updated monotonically by this class when edits are applied.\n\t * TODO: update this when applying edits to unhydrated trees.\n\t *\n\t * If TypeScript supported making this immutable from outside the class without making it readonly from inside, that would be used here,\n\t * but they only way to do that is add a separate public accessor and make it private, which was deemed not worth the boilerplate, runtime overhead and bundle size.\n\t */\n\tpublic generationNumber: number = 0;\n\n\t#hydrationState: HydrationState;\n\n\t/**\n\t * Events registered before hydration.\n\t * @remarks\n\t * Since these are usually not used, they are allocated lazily as an optimization.\n\t * The laziness also avoids extra forwarding overhead for events from this kernel's anchor node and also avoids registering for events that are unneeded.\n\t * This means optimizations like skipping processing data in subtrees where no subtreeChanged events are subscribed to would be able to work,\n\t * since the kernel does not unconditionally subscribe to those events (like a design which simply forwards all events would).\n\t */\n\treadonly #eventBuffer: KernelEventBuffer;\n\n\t/**\n\t * Create a TreeNodeKernel which can be looked up with {@link getKernel}.\n\t *\n\t * @param initialContext - context from when this node was originally created. Only used when unhydrated.\n\t * @param innerNode - When unhydrated/raw or marinated the MapTreeNode. FlexTreeNode when cooked.\n\t * @remarks\n\t * Exactly one kernel per TreeNode should be created.\n\t */\n\tpublic constructor(\n\t\tpublic readonly node: TreeNode,\n\t\tpublic readonly schema: TreeNodeSchema,\n\t\tinnerNode: InnerNode,\n\t\tprivate readonly initialContext: Context,\n\t) {\n\t\tsplitInnerNodeType(innerNode);\n\n\t\tassert(!treeNodeToKernel.has(node), 0xa1a /* only one kernel per node can be made */);\n\t\ttreeNodeToKernel.set(node, this);\n\n\t\tif (innerNode instanceof UnhydratedFlexTreeNode) {\n\t\t\t// Unhydrated case\n\n\t\t\tdebugAssert(() => innerNode.treeNode === undefined);\n\t\t\tinnerNode.treeNode = node;\n\n\t\t\tthis.#hydrationState = {\n\t\t\t\tinnerNode,\n\t\t\t};\n\n\t\t\tthis.#eventBuffer = new KernelEventBuffer(innerNode.events);\n\t\t} else {\n\t\t\t// Hydrated case\n\t\t\tthis.#hydrationState = this.createHydratedState(innerNode.anchorNode);\n\t\t\tthis.#hydrationState.innerNode = innerNode;\n\n\t\t\tthis.#eventBuffer = new KernelEventBuffer(innerNode.anchorNode.events);\n\t\t}\n\t}\n\n\tpublic get context(): Context {\n\t\tif (isHydrated(this.#hydrationState)) {\n\t\t\t// This can't be cached on this.#hydrated during hydration since initial tree is hydrated before the context is cached on the anchorSet.\n\t\t\treturn (\n\t\t\t\tthis.#hydrationState?.anchorNode.anchorSet.slots.get(SimpleContextSlot) ??\n\t\t\t\tfail(0xb40 /* missing simple-tree context */)\n\t\t\t);\n\t\t}\n\t\treturn this.initialContext;\n\t}\n\n\t/**\n\t * Transition from {@link Unhydrated} to hydrated.\n\t * Bi-directionally associates the given hydrated TreeNode to the anchor node at the provided path.\n\t * @remarks\n\t * Happens at most once for any given node.\n\t * Cleans up mappings to {@link UnhydratedFlexTreeNode} - it is assumed that they are no longer needed once this node has an anchor node.\n\t */\n\tpublic hydrate(anchors: AnchorSet, path: UpPath): void {\n\t\tassert(!this.disposed, 0xa2a /* cannot hydrate a disposed node */);\n\t\tassert(!isHydrated(this.#hydrationState), 0xa2b /* hydration should only happen once */);\n\n\t\tconst anchor = anchors.track(path);\n\t\tconst anchorNode =\n\t\t\tanchors.locate(anchor) ?? fail(0xb42 /* Expected anchor node to be present */);\n\n\t\tthis.#hydrationState = this.createHydratedState(anchorNode);\n\t\tthis.#hydrationState.offAnchorNode.add(() => anchors.forget(anchor));\n\n\t\t// Lazily migrate existing event listeners to the anchor node\n\t\tthis.#eventBuffer.migrateEventSource(anchorNode.events);\n\t}\n\n\tprivate createHydratedState(anchorNode: AnchorNode): HydratedState {\n\t\tassert(\n\t\t\t!anchorNode.slots.has(simpleTreeNodeSlot),\n\t\t\t0x7f5 /* Cannot associate an flex node with multiple simple-tree nodes */,\n\t\t);\n\t\tanchorNode.slots.set(simpleTreeNodeSlot, this.node);\n\t\treturn {\n\t\t\tanchorNode,\n\t\t\toffAnchorNode: new Set([\n\t\t\t\tanchorNode.events.on(\"afterDestroy\", () => this.dispose()),\n\t\t\t\t// TODO: this should be triggered on change even for unhydrated nodes.\n\t\t\t\tanchorNode.events.on(\"childrenChanging\", () => {\n\t\t\t\t\tthis.generationNumber += 1;\n\t\t\t\t}),\n\t\t\t]),\n\t\t};\n\t}\n\n\tpublic getStatus(): TreeStatus {\n\t\tif (this.disposed) {\n\t\t\treturn TreeStatus.Deleted;\n\t\t}\n\t\tif (!isHydrated(this.#hydrationState)) {\n\t\t\treturn TreeStatus.New;\n\t\t}\n\n\t\t// TODO: Replace this check with the proper check against the cursor state when the cursor becomes part of the kernel\n\t\tconst flex = this.#hydrationState.anchorNode.slots.get(flexTreeSlot);\n\t\tif (flex !== undefined) {\n\t\t\tassert(flex instanceof LazyEntity, 0x9b4 /* Unexpected flex node implementation */);\n\t\t\tif (flex.isFreed()) {\n\t\t\t\treturn TreeStatus.Deleted;\n\t\t\t}\n\t\t}\n\n\t\treturn treeStatusFromAnchorCache(this.#hydrationState.anchorNode);\n\t}\n\n\tpublic get events(): Listenable<KernelEvents> {\n\t\treturn this.#eventBuffer;\n\t}\n\n\tpublic dispose(): void {\n\t\tdebugAssert(() => !this.disposed || \"Cannot dispose a disposed node\");\n\t\tthis.disposed = true;\n\t\tif (isHydrated(this.#hydrationState)) {\n\t\t\tfor (const off of this.#hydrationState.offAnchorNode) {\n\t\t\t\toff();\n\t\t\t}\n\t\t}\n\t\tthis.#eventBuffer.dispose();\n\t\t// TODO: go to the context and remove myself from withAnchors\n\t}\n\n\tpublic isHydrated(): this is { anchorNode: AnchorNode; context: HydratedContext } {\n\t\treturn isHydrated(this.#hydrationState);\n\t}\n\n\tpublic get anchorNode(): AnchorNode | undefined {\n\t\treturn isHydrated(this.#hydrationState) ? this.#hydrationState.anchorNode : undefined;\n\t}\n\n\t/**\n\t * Retrieves the flex node associated with the given target.\n\t * @remarks\n\t * For {@link Unhydrated} nodes, this returns the MapTreeNode.\n\t *\n\t * For hydrated nodes it returns a FlexTreeNode backed by the forest.\n\t * Note that for \"marinated\" nodes, this FlexTreeNode exists and returns it: it does not return the MapTreeNode which is the current InnerNode.\n\t *\n\t * @throws A {@link @fluidframework/telemetry-utils#UsageError} if the node has been deleted.\n\t */\n\tpublic getOrCreateInnerNode(): InnerNode {\n\t\tif (!isHydrated(this.#hydrationState)) {\n\t\t\tdebugAssert(\n\t\t\t\t() =>\n\t\t\t\t\tthis.#hydrationState.innerNode?.context.isDisposed() === false ||\n\t\t\t\t\t\"Unhydrated node should never be disposed\",\n\t\t\t);\n\t\t\treturn this.#hydrationState.innerNode; // Unhydrated case\n\t\t}\n\n\t\tif (this.disposed) {\n\t\t\tthrow new UsageError(\"Cannot access a deleted node.\");\n\t\t}\n\n\t\tif (this.#hydrationState.innerNode === undefined) {\n\t\t\t// Marinated case -> cooked\n\t\t\tconst anchorNode = this.#hydrationState.anchorNode;\n\t\t\t// This TreeNode is bound to an anchor node, but it may or may not have an actual flex node yet\n\t\t\tconst flexNode = anchorNode.slots.get(flexTreeSlot);\n\t\t\tif (flexNode !== undefined) {\n\t\t\t\t// If the flex node already exists, use it...\n\t\t\t\tthis.#hydrationState.innerNode = flexNode;\n\t\t\t} else {\n\t\t\t\t// ...otherwise, the flex node must be created\n\t\t\t\tconst context =\n\t\t\t\t\tanchorNode.anchorSet.slots.get(ContextSlot) ?? fail(0xb41 /* missing context */);\n\t\t\t\tconst cursor = context.checkout.forest.allocateCursor(\"getFlexNode\");\n\t\t\t\tcontext.checkout.forest.moveCursorToPath(anchorNode, cursor);\n\t\t\t\tthis.#hydrationState.innerNode = getOrCreateHydratedFlexTreeNode(context, cursor);\n\t\t\t\tcursor.free();\n\t\t\t\tassertFlexTreeEntityNotFreed(this.#hydrationState.innerNode);\n\t\t\t}\n\t\t}\n\n\t\treturn this.#hydrationState.innerNode;\n\t}\n\n\t/**\n\t * Retrieves the {@link UnhydratedFlexTreeNode} if unhydrated. otherwise undefined.\n\t */\n\tpublic getInnerNodeIfUnhydrated(): UnhydratedFlexTreeNode | undefined {\n\t\tif (isHydrated(this.#hydrationState)) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn this.#hydrationState.innerNode;\n\t}\n}\n\nconst kernelEvents = [\"childrenChangedAfterBatch\", \"subtreeChangedAfterBatch\"] as const;\n\ntype KernelEvents = Pick<AnchorEvents, (typeof kernelEvents)[number]>;\n\n// #region TreeNodeEventBuffer\n\n/**\n * Whether or not events from {@link TreeNodeKernel} should be buffered instead of emitted immediately.\n */\nlet bufferTreeEvents: boolean = false;\n\n/**\n * Call the provided callback with {@link TreeNode}s' events paused until after the callback's completion.\n *\n * Events that would otherwise have been emitted immediately are merged and buffered until after the\n * provided callback has been completed.\n *\n * @remarks\n * Note: this should be used with caution. User application behaviors are implicitly coupled to event timing.\n * Disrupting this timing can lead to unexpected behavior.\n */\nexport function withBufferedTreeEvents(callback: () => void): void {\n\tif (bufferTreeEvents) {\n\t\t// Already buffering - just run the callback\n\t\tcallback();\n\t} else {\n\t\tbufferTreeEvents = true;\n\t\ttry {\n\t\t\tcallback();\n\t\t} finally {\n\t\t\tbufferTreeEvents = false;\n\t\t\tflushEventsEmitter.emit(\"flush\");\n\t\t}\n\t}\n}\n\n/**\n * Event emitter to notify subscribers when tree events buffered due to {@link withBufferedTreeEvents} should be flushed.\n */\nconst flushEventsEmitter = createEmitter<{\n\tflush: () => void;\n}>();\n\n/**\n * Event emitter for {@link TreeNodeKernel}, which optionally buffers events based on {@link bufferTreeEvents}.\n * @remarks Listens to {@link flushEventsEmitter} to know when to flush any buffered events.\n */\nclass KernelEventBuffer implements Listenable<KernelEvents> {\n\t#disposed: boolean = false;\n\n\t/**\n\t * Listen to {@link flushEventsEmitter} to know when to flush buffered events.\n\t */\n\treadonly #disposeOnFlushListener = flushEventsEmitter.on(\"flush\", () => {\n\t\tthis.flush();\n\t});\n\n\treadonly #events = createEmitter<KernelEvents>();\n\n\t#eventSource: Listenable<KernelEvents> & HasListeners<KernelEvents>;\n\t#disposeSourceListeners: Map<keyof KernelEvents, Off> = new Map();\n\n\t/**\n\t * Buffer of fields that have changed since events were paused.\n\t * When events are flushed, a single {@link AnchorEvents.childrenChangedAfterBatch} event will be emitted\n\t * containing the accumulated set of changed fields.\n\t */\n\treadonly #childrenChangedBuffer: Set<FieldKey> = new Set();\n\n\t/**\n\t * Whether or not the subtree has changed since events were paused.\n\t * When events are flushed, a single {@link AnchorEvents.subTreeChanged} event will be emitted if and only\n\t * if the subtree has changed.\n\t */\n\t#subTreeChangedBuffer: boolean = false;\n\n\tpublic constructor(\n\t\t/**\n\t\t * Source of the kernel events.\n\t\t * Subscriptions will be created on-demand when listeners are added to this.events,\n\t\t * and those subscriptions will be cleaned up when all corresponding listeners have been removed.\n\t\t */\n\t\teventSource: Listenable<KernelEvents> & HasListeners<KernelEvents>,\n\t) {\n\t\tthis.#eventSource = eventSource;\n\t}\n\n\t/**\n\t * Migrate this event buffer to a new event source.\n\t *\n\t * @remarks\n\t * Cleans up any existing event subscriptions from the old source.\n\t * Binds events to the new source for each event with active listeners.\n\t */\n\tpublic migrateEventSource(\n\t\tnewSource: Listenable<KernelEvents> & HasListeners<KernelEvents>,\n\t): void {\n\t\t// Unsubscribe from the old source\n\t\tthis.#disposeSourceListeners.forEach((off) => off());\n\t\tthis.#disposeSourceListeners.clear();\n\n\t\tthis.#eventSource = newSource;\n\n\t\tif (this.#events.hasListeners(\"childrenChangedAfterBatch\")) {\n\t\t\tconst off = this.#eventSource.on(\"childrenChangedAfterBatch\", ({ changedFields }) =>\n\t\t\t\tthis.#emit(\"childrenChangedAfterBatch\", { changedFields }),\n\t\t\t);\n\t\t\tthis.#disposeSourceListeners.set(\"childrenChangedAfterBatch\", off);\n\t\t}\n\t\tif (this.#events.hasListeners(\"subtreeChangedAfterBatch\")) {\n\t\t\tconst off = this.#eventSource.on(\"subtreeChangedAfterBatch\", () =>\n\t\t\t\tthis.#emit(\"subtreeChangedAfterBatch\"),\n\t\t\t);\n\t\t\tthis.#disposeSourceListeners.set(\"subtreeChangedAfterBatch\", off);\n\t\t}\n\t}\n\n\tpublic on(eventName: keyof KernelEvents, listener: KernelEvents[typeof eventName]): Off {\n\t\t// Lazily bind event listeners to the source.\n\t\t// If we do not have any existing listeners for this event, then we need to bind to the source.\n\t\tif (!this.#events.hasListeners(eventName)) {\n\t\t\tassert(\n\t\t\t\t!this.#disposeSourceListeners.has(eventName),\n\t\t\t\t\"Should not have a dispose function without listeners\",\n\t\t\t);\n\n\t\t\tconst off = this.#eventSource.on(eventName, (args) => this.#emit(eventName, args));\n\t\t\tthis.#disposeSourceListeners.set(eventName, off);\n\t\t}\n\n\t\tthis.#events.on(eventName, listener);\n\t\treturn () => this.off(eventName, listener);\n\t}\n\n\tpublic off(eventName: keyof KernelEvents, listener: KernelEvents[typeof eventName]): void {\n\t\tthis.#events.off(eventName, listener);\n\n\t\t// If there are no remaining listeners for the event, unbind from the source\n\t\tif (!this.#events.hasListeners(eventName)) {\n\t\t\tconst off = this.#disposeSourceListeners.get(eventName);\n\t\t\toff?.();\n\t\t\tthis.#disposeSourceListeners.delete(eventName);\n\t\t}\n\t}\n\n\t#emit(\n\t\teventName: keyof KernelEvents,\n\t\targ?: {\n\t\t\tchangedFields: ReadonlySet<FieldKey>;\n\t\t},\n\t): void {\n\t\tthis.#assertNotDisposed();\n\t\tswitch (eventName) {\n\t\t\tcase \"childrenChangedAfterBatch\":\n\t\t\t\tassert(arg !== undefined, \"childrenChangedAfterBatch should have arg\");\n\t\t\t\treturn this.#handleChildrenChangedAfterBatch(arg.changedFields);\n\t\t\tcase \"subtreeChangedAfterBatch\":\n\t\t\t\treturn this.#handleSubtreeChangedAfterBatch();\n\t\t\tdefault:\n\t\t\t\tunreachableCase(eventName);\n\t\t}\n\t}\n\n\t#handleChildrenChangedAfterBatch(changedFields: ReadonlySet<FieldKey>): void {\n\t\tif (bufferTreeEvents) {\n\t\t\tfor (const fieldKey of changedFields) {\n\t\t\t\tthis.#childrenChangedBuffer.add(fieldKey);\n\t\t\t}\n\t\t} else {\n\t\t\tthis.#events.emit(\"childrenChangedAfterBatch\", { changedFields });\n\t\t}\n\t}\n\n\t#handleSubtreeChangedAfterBatch(): void {\n\t\tif (bufferTreeEvents) {\n\t\t\tthis.#subTreeChangedBuffer = true;\n\t\t} else {\n\t\t\tthis.#events.emit(\"subtreeChangedAfterBatch\");\n\t\t}\n\t}\n\n\t/**\n\t * Flushes any events buffered due to {@link withBufferedTreeEvents}.\n\t */\n\tpublic flush(): void {\n\t\tthis.#assertNotDisposed();\n\n\t\tif (this.#childrenChangedBuffer.size > 0) {\n\t\t\tthis.#events.emit(\"childrenChangedAfterBatch\", {\n\t\t\t\tchangedFields: this.#childrenChangedBuffer,\n\t\t\t});\n\t\t\tthis.#childrenChangedBuffer.clear();\n\t\t}\n\n\t\tif (this.#subTreeChangedBuffer) {\n\t\t\tthis.#events.emit(\"subtreeChangedAfterBatch\");\n\t\t\tthis.#subTreeChangedBuffer = false;\n\t\t}\n\t}\n\n\t#assertNotDisposed(): void {\n\t\tassert(!this.#disposed, \"Event handler disposed.\");\n\t}\n\n\tpublic dispose(): void {\n\t\tif (this.#disposed) {\n\t\t\treturn;\n\t\t}\n\n\t\tassert(\n\t\t\tthis.#childrenChangedBuffer.size === 0 && !this.#subTreeChangedBuffer,\n\t\t\t\"Buffered kernel events should have been flushed before disposing.\",\n\t\t);\n\n\t\tthis.#disposeOnFlushListener();\n\t\tthis.#disposeSourceListeners.forEach((off) => off());\n\t\tthis.#disposeSourceListeners.clear();\n\n\t\tthis.#childrenChangedBuffer.clear();\n\t\tthis.#subTreeChangedBuffer = false;\n\n\t\tthis.#disposed = true;\n\t}\n}\n\n// #endregion\n\n/**\n * For \"cooked\" nodes this is a HydratedFlexTreeNode thats a projection of forest content.\n * For {@link Unhydrated} nodes this is a UnhydratedFlexTreeNode.\n *\n * For \"marinated\" nodes, some code (ex: getOrCreateInnerNode) returns the FlexTreeNode thats a projection of forest content, and some code (ex: tryGetInnerNode) returns undefined.\n */\nexport type InnerNode = FlexTreeNode;\n\n/**\n * Narrows innerNode to either {@link UnhydratedFlexTreeNode} or {@link HydratedFlexTreeNode}.\n */\nexport function splitInnerNodeType(\n\tinnerNode: InnerNode,\n): asserts innerNode is UnhydratedFlexTreeNode | HydratedFlexTreeNode {\n\tassert(\n\t\tinnerNode instanceof UnhydratedFlexTreeNode || innerNode.isHydrated(),\n\t\t0xbc8 /* Invalid inner node type */,\n\t);\n}\n\n/**\n * An anchor slot which associates an anchor with its corresponding {@link TreeNode}, if there is one.\n * @remarks\n * For this to work, we have to require that there is at most a single view using a given AnchorSet.\n * FlexTree already has this assumption, and we also assume there is a single simple-tree per FlexTree, so this is valid.\n */\nexport const simpleTreeNodeSlot = anchorSlot<TreeNode>();\n\n/**\n * Dispose a TreeNode (if any) for an existing anchor without disposing the anchor.\n */\nexport function tryDisposeTreeNode(anchorNode: AnchorNode): void {\n\tconst treeNode = anchorNode.slots.get(simpleTreeNodeSlot);\n\tif (treeNode !== undefined) {\n\t\tconst kernel = getKernel(treeNode);\n\t\tkernel.dispose();\n\t\tanchorNode.slots.delete(simpleTreeNodeSlot);\n\t}\n}\n\n/**\n * Gets the {@link TreeNodeSchema} for the {@link InnerNode}.\n */\nexport function getSimpleNodeSchemaFromInnerNode(innerNode: InnerNode): TreeNodeSchema {\n\tconst context: Context = getSimpleContextFromInnerNode(innerNode);\n\treturn context.schema.get(innerNode.type) ?? fail(0xb3f /* missing schema from context */);\n}\n\n/**\n * Gets the {@link Context} for the {@link InnerNode}.\n */\nexport function getSimpleContextFromInnerNode(innerNode: InnerNode): Context {\n\tsplitInnerNodeType(innerNode);\n\tif (innerNode instanceof UnhydratedFlexTreeNode) {\n\t\treturn innerNode.simpleContext;\n\t}\n\n\tconst context = innerNode.anchorNode.anchorSet.slots.get(SimpleContextSlot);\n\tassert(context !== undefined, 0xa55 /* missing simple tree context */);\n\n\treturn context;\n}\n\n/**\n * Retrieves the flex node associated with the given target.\n * @remarks\n * For {@link Unhydrated} nodes, this returns the MapTreeNode.\n *\n * For hydrated nodes it returns a FlexTreeNode backed by the forest.\n * Note that for \"marinated\" nodes, this FlexTreeNode exists and returns it: it does not return the MapTreeNode which is the current InnerNode.\n *\n * @throws A {@link @fluidframework/telemetry-utils#UsageError} if the node has been deleted.\n */\nexport function getOrCreateInnerNode(treeNode: TreeNode): InnerNode {\n\tconst kernel = getKernel(treeNode);\n\treturn kernel.getOrCreateInnerNode();\n}\n\n/**\n * Gets a flex node from an anchor node\n */\nfunction flexNodeFromAnchor(anchorNode: AnchorNode): HydratedFlexTreeNode {\n\tconst flexNode = anchorNode.slots.get(flexTreeSlot);\n\tif (flexNode !== undefined) {\n\t\treturn flexNode; // If it does have a flex node, return it...\n\t} // ...otherwise, the flex node must be created\n\tconst context =\n\t\tanchorNode.anchorSet.slots.get(ContextSlot) ?? fail(0xb45 /* missing context */);\n\tconst cursor = context.checkout.forest.allocateCursor(\"getFlexNode\");\n\tcontext.checkout.forest.moveCursorToPath(anchorNode, cursor);\n\tconst newFlexNode = getOrCreateHydratedFlexTreeNode(context, cursor);\n\tcursor.free();\n\treturn newFlexNode;\n}\n\n/**\n * Gets a tree node from an anchor node\n */\nexport function treeNodeFromAnchor(anchorNode: AnchorNode): TreeNode | TreeValue {\n\tconst cached = anchorNode.slots.get(simpleTreeNodeSlot);\n\tif (cached !== undefined) {\n\t\treturn cached;\n\t}\n\n\tconst flexNode = flexNodeFromAnchor(anchorNode);\n\treturn createTreeNodeFromInner(flexNode);\n}\n\n/**\n * Constructs a TreeNode from an InnerNode.\n * @remarks\n * This does not do caching or validation: caller must ensure duplicate nodes for a given inner node are not created, and that the inner node is valid.\n */\nexport function createTreeNodeFromInner(innerNode: InnerNode): TreeNode | TreeValue {\n\tconst classSchema = getSimpleNodeSchemaFromInnerNode(innerNode);\n\tconst internal = innerNode as unknown as InternalTreeNode;\n\treturn typeof classSchema === \"function\"\n\t\t? new classSchema(internal)\n\t\t: (classSchema as { create(data: InternalTreeNode): TreeNode | TreeValue }).create(\n\t\t\t\tinternal,\n\t\t\t);\n}\n\n/**\n * Creating multiple simple tree contexts for the same branch, and thus with the same underlying AnchorSet does not work due to how TreeNode caching works.\n * This slot is used to detect if one already exists and error if creating a second.\n * @remarks\n * See also {@link ContextSlot} in which the flex-tree context is stored.\n */\nexport const SimpleContextSlot = anchorSlot<HydratedContext>();\n"]}
|
|
1
|
+
{"version":3,"file":"treeNodeKernel.js","sourceRoot":"","sources":["../../../src/simple-tree/core/treeNodeKernel.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;AAEH,+DAA6D;AAE7D,kEAK6C;AAC7C,uEAAsE;AAEtE,kDAQ6B;AAC7B,+DAAmF;AACnF,+DAS0C;AAM1C,mEAAiE;AAEjE,MAAM,gBAAgB,GAAG,IAAI,OAAO,EAA4B,CAAC;AAEjE,SAAgB,SAAS,CAAC,IAAc;IACvC,MAAM,MAAM,GAAG,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC1C,IAAA,iBAAM,EAAC,MAAM,KAAK,SAAS,EAAE,KAAK,CAAC,uCAAuC,CAAC,CAAC;IAC5E,OAAO,MAAM,CAAC;AACf,CAAC;AAJD,8BAIC;AAED;;;;;;;;;;;;;GAaG;AACH,SAAgB,UAAU,CAAC,SAAkB;IAC5C,OAAO,gBAAgB,CAAC,GAAG,CAAC,SAAqB,CAAC,CAAC;AACpD,CAAC;AAFD,gCAEC;AAED;;;;;;GAMG;AACH,SAAgB,oBAAoB,CAAC,KAAc;IAClD,MAAM,MAAM,GAAG,gBAAgB,CAAC,GAAG,CAAC,KAAiB,CAAC,CAAC;IACvD,OAAO,MAAM,EAAE,MAAM,CAAC;AACvB,CAAC;AAHD,oDAGC;AAoBD,6EAA6E;AAC7E,SAAS,UAAU,CAAC,KAAqB;IACxC,OAAQ,KAAgC,CAAC,UAAU,KAAK,SAAS,CAAC;AACnE,CAAC;AAED;;;;GAIG;AACH,MAAa,cAAc;IA2B1B;;;;;;;OAOG;IACH,YACiB,IAAc,EACd,MAAsB,EACtC,SAAoB,EACH,cAAuB;QAHxB,SAAI,GAAJ,IAAI,CAA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,CAAC,QAAQ,CAAC,CAAC;AAC1C,CAAC;AARD,gDAQC;AAED;;;;GAIG;AACH,SAAgB,uBAAuB,CAAC,SAAoB;IAC3D,MAAM,WAAW,GAAG,gCAAgC,CAAC,SAAS,CAAC,CAAC;IAChE,MAAM,QAAQ,GAAG,SAAwC,CAAC;IAC1D,OAAO,OAAO,WAAW,KAAK,UAAU;QACvC,CAAC,CAAC,IAAI,WAAW,CAAC,QAAQ,CAAC;QAC3B,CAAC,CAAE,WAAwE,CAAC,MAAM,CAChF,QAAQ,CACR,CAAC;AACL,CAAC;AARD,0DAQC;AAED;;;;;GAKG;AACU,QAAA,iBAAiB,GAAG,IAAA,qBAAU,GAAmB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { createEmitter } from \"@fluid-internal/client-utils\";\nimport type { HasListeners, Listenable, Off } from \"@fluidframework/core-interfaces/internal\";\nimport {\n\tassert,\n\tfail,\n\tdebugAssert,\n\tunreachableCase,\n} from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\tanchorSlot,\n\ttype AnchorEvents,\n\ttype AnchorNode,\n\ttype AnchorSet,\n\ttype FieldKey,\n\ttype TreeValue,\n\ttype UpPath,\n} from \"../../core/index.js\";\nimport { getOrCreateHydratedFlexTreeNode } from \"../../feature-libraries/index.js\";\nimport {\n\tassertFlexTreeEntityNotFreed,\n\tContextSlot,\n\tflexTreeSlot,\n\tLazyEntity,\n\tTreeStatus,\n\ttreeStatusFromAnchorCache,\n\ttype FlexTreeNode,\n\ttype HydratedFlexTreeNode,\n} from \"../../feature-libraries/index.js\";\n\nimport type { Context, HydratedContext } from \"./context.js\";\nimport type { TreeNode } from \"./treeNode.js\";\nimport type { TreeNodeSchema } from \"./treeNodeSchema.js\";\nimport type { InternalTreeNode, Unhydrated } from \"./types.js\";\nimport { UnhydratedFlexTreeNode } from \"./unhydratedFlexTree.js\";\n\nconst treeNodeToKernel = new WeakMap<TreeNode, TreeNodeKernel>();\n\nexport function getKernel(node: TreeNode): TreeNodeKernel {\n\tconst kernel = treeNodeToKernel.get(node);\n\tassert(kernel !== undefined, 0x9b1 /* Expected tree node to have kernel */);\n\treturn kernel;\n}\n\n/**\n * Detects if the given 'candidate' is a TreeNode.\n *\n * @remarks\n * Supports both Hydrated and {@link Unhydrated} TreeNodes, both of which return true.\n *\n * Because the common usage is to check if a value being inserted/set is a TreeNode,\n * this function permits calling with primitives as well as objects.\n *\n * Primitives will always return false (as they are copies of data, not references to nodes).\n *\n * @param candidate - Value which may be a TreeNode\n * @returns true if the given 'candidate' is a hydrated TreeNode.\n */\nexport function isTreeNode(candidate: unknown): candidate is TreeNode | Unhydrated<TreeNode> {\n\treturn treeNodeToKernel.has(candidate as TreeNode);\n}\n\n/**\n * Returns a schema for a value if the value is a {@link TreeNode}.\n *\n * Returns undefined for other values.\n * @remarks\n * Does not give schema for a {@link TreeLeafValue}.\n */\nexport function tryGetTreeNodeSchema(value: unknown): undefined | TreeNodeSchema {\n\tconst kernel = treeNodeToKernel.get(value as TreeNode);\n\treturn kernel?.schema;\n}\n\n/** The {@link HydrationState} of a {@link TreeNodeKernel} before the kernel is hydrated */\ninterface UnhydratedState {\n\treadonly innerNode: UnhydratedFlexTreeNode;\n}\n\n/** The {@link HydrationState} of a {@link TreeNodeKernel} after the kernel is hydrated */\ninterface HydratedState {\n\t/** The flex node for this kernel (lazy - undefined if it has not yet been demanded) */\n\tinnerNode?: FlexTreeNode;\n\t/** The {@link AnchorNode} that this node is associated with. */\n\treadonly anchorNode: AnchorNode;\n\t/** All {@link Off | event deregistration functions} that should be run when the kernel is disposed. */\n\treadonly offAnchorNode: Set<Off>;\n}\n\n/** State within a {@link TreeNodeKernel} that is related to the hydration process */\ntype HydrationState = UnhydratedState | HydratedState;\n\n/** True if and only if the given {@link HydrationState} is post-hydration */\nfunction isHydrated(state: HydrationState): state is HydratedState {\n\treturn (state as Partial<HydratedState>).anchorNode !== undefined;\n}\n\n/**\n * Contains state and an internal API for managing {@link TreeNode}s.\n * @remarks All {@link TreeNode}s have an associated kernel object.\n * The kernel has the same lifetime as the node and spans both its unhydrated and hydrated states.\n */\nexport class TreeNodeKernel {\n\tprivate disposed = false;\n\n\t/**\n\t * Generation number which is incremented any time we have an edit on the node.\n\t * Used during iteration to make sure there has been no edits that were concurrently made.\n\t * @remarks\n\t * This is updated monotonically by this class when edits are applied.\n\t * TODO: update this when applying edits to unhydrated trees.\n\t *\n\t * If TypeScript supported making this immutable from outside the class without making it readonly from inside, that would be used here,\n\t * but they only way to do that is add a separate public accessor and make it private, which was deemed not worth the boilerplate, runtime overhead and bundle size.\n\t */\n\tpublic generationNumber: number = 0;\n\n\t#hydrationState: HydrationState;\n\n\t/**\n\t * Events registered before hydration.\n\t * @remarks\n\t * Since these are usually not used, they are allocated lazily as an optimization.\n\t * The laziness also avoids extra forwarding overhead for events from this kernel's anchor node and also avoids registering for events that are unneeded.\n\t * This means optimizations like skipping processing data in subtrees where no subtreeChanged events are subscribed to would be able to work,\n\t * since the kernel does not unconditionally subscribe to those events (like a design which simply forwards all events would).\n\t */\n\treadonly #eventBuffer: KernelEventBuffer;\n\n\t/**\n\t * Create a TreeNodeKernel which can be looked up with {@link getKernel}.\n\t *\n\t * @param initialContext - context from when this node was originally created. Only used when unhydrated.\n\t * @param innerNode - When unhydrated/raw or marinated the MapTreeNode. FlexTreeNode when cooked.\n\t * @remarks\n\t * Exactly one kernel per TreeNode should be created.\n\t */\n\tpublic constructor(\n\t\tpublic readonly node: TreeNode,\n\t\tpublic readonly schema: TreeNodeSchema,\n\t\tinnerNode: InnerNode,\n\t\tprivate readonly initialContext: Context,\n\t) {\n\t\tsplitInnerNodeType(innerNode);\n\n\t\tassert(!treeNodeToKernel.has(node), 0xa1a /* only one kernel per node can be made */);\n\t\ttreeNodeToKernel.set(node, this);\n\n\t\tif (innerNode instanceof UnhydratedFlexTreeNode) {\n\t\t\t// Unhydrated case\n\n\t\t\tdebugAssert(() => innerNode.treeNode === undefined);\n\t\t\tinnerNode.treeNode = node;\n\n\t\t\tthis.#hydrationState = {\n\t\t\t\tinnerNode,\n\t\t\t};\n\n\t\t\tthis.#eventBuffer = new KernelEventBuffer(innerNode.events);\n\t\t} else {\n\t\t\t// Hydrated case\n\t\t\tthis.#hydrationState = this.createHydratedState(innerNode.anchorNode);\n\t\t\tthis.#hydrationState.innerNode = innerNode;\n\n\t\t\tthis.#eventBuffer = new KernelEventBuffer(innerNode.anchorNode.events);\n\t\t}\n\t}\n\n\tpublic get context(): Context {\n\t\tif (isHydrated(this.#hydrationState)) {\n\t\t\t// This can't be cached on this.#hydrated during hydration since initial tree is hydrated before the context is cached on the anchorSet.\n\t\t\treturn (\n\t\t\t\tthis.#hydrationState?.anchorNode.anchorSet.slots.get(SimpleContextSlot) ??\n\t\t\t\tfail(0xb40 /* missing simple-tree context */)\n\t\t\t);\n\t\t}\n\t\treturn this.initialContext;\n\t}\n\n\t/**\n\t * Transition from {@link Unhydrated} to hydrated.\n\t * Bi-directionally associates the given hydrated TreeNode to the anchor node at the provided path.\n\t * @remarks\n\t * Happens at most once for any given node.\n\t * Cleans up mappings to {@link UnhydratedFlexTreeNode} - it is assumed that they are no longer needed once this node has an anchor node.\n\t */\n\tpublic hydrate(anchors: AnchorSet, path: UpPath): void {\n\t\tassert(!this.disposed, 0xa2a /* cannot hydrate a disposed node */);\n\t\tassert(!isHydrated(this.#hydrationState), 0xa2b /* hydration should only happen once */);\n\n\t\tconst anchor = anchors.track(path);\n\t\tconst anchorNode =\n\t\t\tanchors.locate(anchor) ?? fail(0xb42 /* Expected anchor node to be present */);\n\n\t\tthis.#hydrationState = this.createHydratedState(anchorNode);\n\t\tthis.#hydrationState.offAnchorNode.add(() => anchors.forget(anchor));\n\n\t\t// Lazily migrate existing event listeners to the anchor node\n\t\tthis.#eventBuffer.migrateEventSource(anchorNode.events);\n\t}\n\n\tprivate createHydratedState(anchorNode: AnchorNode): HydratedState {\n\t\tassert(\n\t\t\t!anchorNode.slots.has(simpleTreeNodeSlot),\n\t\t\t0x7f5 /* Cannot associate an flex node with multiple simple-tree nodes */,\n\t\t);\n\t\tanchorNode.slots.set(simpleTreeNodeSlot, this.node);\n\t\treturn {\n\t\t\tanchorNode,\n\t\t\toffAnchorNode: new Set([\n\t\t\t\tanchorNode.events.on(\"afterDestroy\", () => this.dispose()),\n\t\t\t\t// TODO: this should be triggered on change even for unhydrated nodes.\n\t\t\t\tanchorNode.events.on(\"childrenChanging\", () => {\n\t\t\t\t\tthis.generationNumber += 1;\n\t\t\t\t}),\n\t\t\t]),\n\t\t};\n\t}\n\n\tpublic getStatus(): TreeStatus {\n\t\tif (this.disposed) {\n\t\t\treturn TreeStatus.Deleted;\n\t\t}\n\t\tif (!isHydrated(this.#hydrationState)) {\n\t\t\treturn TreeStatus.New;\n\t\t}\n\n\t\t// TODO: Replace this check with the proper check against the cursor state when the cursor becomes part of the kernel\n\t\tconst flex = this.#hydrationState.anchorNode.slots.get(flexTreeSlot);\n\t\tif (flex !== undefined) {\n\t\t\tassert(flex instanceof LazyEntity, 0x9b4 /* Unexpected flex node implementation */);\n\t\t\tif (flex.isFreed()) {\n\t\t\t\treturn TreeStatus.Deleted;\n\t\t\t}\n\t\t}\n\n\t\treturn treeStatusFromAnchorCache(this.#hydrationState.anchorNode);\n\t}\n\n\tpublic get events(): Listenable<KernelEvents> {\n\t\treturn this.#eventBuffer;\n\t}\n\n\tpublic dispose(): void {\n\t\tdebugAssert(() => !this.disposed || \"Cannot dispose a disposed node\");\n\t\tthis.disposed = true;\n\t\tif (isHydrated(this.#hydrationState)) {\n\t\t\tfor (const off of this.#hydrationState.offAnchorNode) {\n\t\t\t\toff();\n\t\t\t}\n\t\t}\n\t\tthis.#eventBuffer.dispose();\n\t\t// TODO: go to the context and remove myself from withAnchors\n\t}\n\n\tpublic isHydrated(): this is { anchorNode: AnchorNode; context: HydratedContext } {\n\t\treturn isHydrated(this.#hydrationState);\n\t}\n\n\tpublic get anchorNode(): AnchorNode | undefined {\n\t\treturn isHydrated(this.#hydrationState) ? this.#hydrationState.anchorNode : undefined;\n\t}\n\n\t/**\n\t * Retrieves the flex node associated with the given target.\n\t * @remarks\n\t * For {@link Unhydrated} nodes, this returns the MapTreeNode.\n\t *\n\t * For hydrated nodes it returns a FlexTreeNode backed by the forest.\n\t * Note that for \"marinated\" nodes, this FlexTreeNode exists and returns it: it does not return the MapTreeNode which is the current InnerNode.\n\t *\n\t * @throws A {@link @fluidframework/telemetry-utils#UsageError} if the node has been deleted.\n\t */\n\tpublic getOrCreateInnerNode(): InnerNode {\n\t\tif (!isHydrated(this.#hydrationState)) {\n\t\t\tdebugAssert(\n\t\t\t\t() =>\n\t\t\t\t\tthis.#hydrationState.innerNode?.context.isDisposed() === false ||\n\t\t\t\t\t\"Unhydrated node should never be disposed\",\n\t\t\t);\n\t\t\treturn this.#hydrationState.innerNode; // Unhydrated case\n\t\t}\n\n\t\tif (this.disposed) {\n\t\t\tthrow new UsageError(\"Cannot access a deleted node.\");\n\t\t}\n\n\t\tif (this.#hydrationState.innerNode === undefined) {\n\t\t\t// Marinated case -> cooked\n\t\t\tconst anchorNode = this.#hydrationState.anchorNode;\n\t\t\t// This TreeNode is bound to an anchor node, but it may or may not have an actual flex node yet\n\t\t\tconst flexNode = anchorNode.slots.get(flexTreeSlot);\n\t\t\tif (flexNode !== undefined) {\n\t\t\t\t// If the flex node already exists, use it...\n\t\t\t\tthis.#hydrationState.innerNode = flexNode;\n\t\t\t} else {\n\t\t\t\t// ...otherwise, the flex node must be created\n\t\t\t\tconst context =\n\t\t\t\t\tanchorNode.anchorSet.slots.get(ContextSlot) ?? fail(0xb41 /* missing context */);\n\t\t\t\tconst cursor = context.checkout.forest.allocateCursor(\"getFlexNode\");\n\t\t\t\tcontext.checkout.forest.moveCursorToPath(anchorNode, cursor);\n\t\t\t\tthis.#hydrationState.innerNode = getOrCreateHydratedFlexTreeNode(context, cursor);\n\t\t\t\tcursor.free();\n\t\t\t\tassertFlexTreeEntityNotFreed(this.#hydrationState.innerNode);\n\t\t\t}\n\t\t}\n\n\t\treturn this.#hydrationState.innerNode;\n\t}\n\n\t/**\n\t * Retrieves the {@link UnhydratedFlexTreeNode} if unhydrated. otherwise undefined.\n\t */\n\tpublic getInnerNodeIfUnhydrated(): UnhydratedFlexTreeNode | undefined {\n\t\tif (isHydrated(this.#hydrationState)) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn this.#hydrationState.innerNode;\n\t}\n}\n\nconst kernelEvents = [\"childrenChangedAfterBatch\", \"subtreeChangedAfterBatch\"] as const;\n\ntype KernelEvents = Pick<AnchorEvents, (typeof kernelEvents)[number]>;\n\n// #region TreeNodeEventBuffer\n\n/**\n * Whether or not events from {@link TreeNodeKernel} should be buffered instead of emitted immediately.\n */\nlet bufferTreeEvents: boolean = false;\n\n/**\n * Call the provided callback with {@link TreeNode}s' events paused until after the callback's completion.\n *\n * Events that would otherwise have been emitted immediately are merged and buffered until after the\n * provided callback has been completed.\n *\n * @remarks\n * Note: this should be used with caution. User application behaviors are implicitly coupled to event timing.\n * Disrupting this timing can lead to unexpected behavior.\n */\nexport function withBufferedTreeEvents(callback: () => void): void {\n\tif (bufferTreeEvents) {\n\t\t// Already buffering - just run the callback\n\t\tcallback();\n\t} else {\n\t\tbufferTreeEvents = true;\n\t\ttry {\n\t\t\tcallback();\n\t\t} finally {\n\t\t\tbufferTreeEvents = false;\n\t\t\tflushEventsEmitter.emit(\"flush\");\n\t\t}\n\t}\n}\n\n/**\n * Event emitter to notify subscribers when tree events buffered due to {@link withBufferedTreeEvents} should be flushed.\n */\nconst flushEventsEmitter = createEmitter<{\n\tflush: () => void;\n}>();\n\n/**\n * Event emitter for {@link TreeNodeKernel}, which optionally buffers events based on {@link bufferTreeEvents}.\n * @remarks Listens to {@link flushEventsEmitter} to know when to flush any buffered events.\n */\nclass KernelEventBuffer implements Listenable<KernelEvents> {\n\t#disposed: boolean = false;\n\n\t/**\n\t * Listen to {@link flushEventsEmitter} to know when to flush buffered events.\n\t */\n\treadonly #disposeOnFlushListener = flushEventsEmitter.on(\"flush\", () => {\n\t\tthis.flush();\n\t});\n\n\treadonly #events = createEmitter<KernelEvents>();\n\n\t#eventSource: Listenable<KernelEvents> & HasListeners<KernelEvents>;\n\t#disposeSourceListeners: Map<keyof KernelEvents, Off> = new Map();\n\n\t/**\n\t * Buffer of fields that have changed since events were paused.\n\t * When events are flushed, a single {@link AnchorEvents.childrenChangedAfterBatch} event will be emitted\n\t * containing the accumulated set of changed fields.\n\t */\n\treadonly #childrenChangedBuffer: Set<FieldKey> = new Set();\n\n\t/**\n\t * Whether or not the subtree has changed since events were paused.\n\t * When events are flushed, a single {@link AnchorEvents.subTreeChanged} event will be emitted if and only\n\t * if the subtree has changed.\n\t */\n\t#subTreeChangedBuffer: boolean = false;\n\n\tpublic constructor(\n\t\t/**\n\t\t * Source of the kernel events.\n\t\t * Subscriptions will be created on-demand when listeners are added to this.events,\n\t\t * and those subscriptions will be cleaned up when all corresponding listeners have been removed.\n\t\t */\n\t\teventSource: Listenable<KernelEvents> & HasListeners<KernelEvents>,\n\t) {\n\t\tthis.#eventSource = eventSource;\n\t}\n\n\t/**\n\t * Migrate this event buffer to a new event source.\n\t *\n\t * @remarks\n\t * Cleans up any existing event subscriptions from the old source.\n\t * Binds events to the new source for each event with active listeners.\n\t */\n\tpublic migrateEventSource(\n\t\tnewSource: Listenable<KernelEvents> & HasListeners<KernelEvents>,\n\t): void {\n\t\t// Unsubscribe from the old source\n\t\tthis.#disposeSourceListeners.forEach((off) => off());\n\t\tthis.#disposeSourceListeners.clear();\n\n\t\tthis.#eventSource = newSource;\n\n\t\tif (this.#events.hasListeners(\"childrenChangedAfterBatch\")) {\n\t\t\tconst off = this.#eventSource.on(\"childrenChangedAfterBatch\", ({ changedFields }) =>\n\t\t\t\tthis.#emit(\"childrenChangedAfterBatch\", { changedFields }),\n\t\t\t);\n\t\t\tthis.#disposeSourceListeners.set(\"childrenChangedAfterBatch\", off);\n\t\t}\n\t\tif (this.#events.hasListeners(\"subtreeChangedAfterBatch\")) {\n\t\t\tconst off = this.#eventSource.on(\"subtreeChangedAfterBatch\", () =>\n\t\t\t\tthis.#emit(\"subtreeChangedAfterBatch\"),\n\t\t\t);\n\t\t\tthis.#disposeSourceListeners.set(\"subtreeChangedAfterBatch\", off);\n\t\t}\n\t}\n\n\tpublic on(eventName: keyof KernelEvents, listener: KernelEvents[typeof eventName]): Off {\n\t\t// Lazily bind event listeners to the source.\n\t\t// If we do not have any existing listeners for this event, then we need to bind to the source.\n\t\tif (!this.#events.hasListeners(eventName)) {\n\t\t\tassert(\n\t\t\t\t!this.#disposeSourceListeners.has(eventName),\n\t\t\t\t0xc4f /* Should not have a dispose function without listeners */,\n\t\t\t);\n\n\t\t\tconst off = this.#eventSource.on(eventName, (args) => this.#emit(eventName, args));\n\t\t\tthis.#disposeSourceListeners.set(eventName, off);\n\t\t}\n\n\t\tthis.#events.on(eventName, listener);\n\t\treturn () => this.off(eventName, listener);\n\t}\n\n\tpublic off(eventName: keyof KernelEvents, listener: KernelEvents[typeof eventName]): void {\n\t\tthis.#events.off(eventName, listener);\n\n\t\t// If there are no remaining listeners for the event, unbind from the source\n\t\tif (!this.#events.hasListeners(eventName)) {\n\t\t\tconst off = this.#disposeSourceListeners.get(eventName);\n\t\t\toff?.();\n\t\t\tthis.#disposeSourceListeners.delete(eventName);\n\t\t}\n\t}\n\n\t#emit(\n\t\teventName: keyof KernelEvents,\n\t\targ?: {\n\t\t\tchangedFields: ReadonlySet<FieldKey>;\n\t\t},\n\t): void {\n\t\tthis.#assertNotDisposed();\n\t\tswitch (eventName) {\n\t\t\tcase \"childrenChangedAfterBatch\":\n\t\t\t\tassert(arg !== undefined, 0xc50 /* childrenChangedAfterBatch should have arg */);\n\t\t\t\treturn this.#handleChildrenChangedAfterBatch(arg.changedFields);\n\t\t\tcase \"subtreeChangedAfterBatch\":\n\t\t\t\treturn this.#handleSubtreeChangedAfterBatch();\n\t\t\tdefault:\n\t\t\t\tunreachableCase(eventName);\n\t\t}\n\t}\n\n\t#handleChildrenChangedAfterBatch(changedFields: ReadonlySet<FieldKey>): void {\n\t\tif (bufferTreeEvents) {\n\t\t\tfor (const fieldKey of changedFields) {\n\t\t\t\tthis.#childrenChangedBuffer.add(fieldKey);\n\t\t\t}\n\t\t} else {\n\t\t\tthis.#events.emit(\"childrenChangedAfterBatch\", { changedFields });\n\t\t}\n\t}\n\n\t#handleSubtreeChangedAfterBatch(): void {\n\t\tif (bufferTreeEvents) {\n\t\t\tthis.#subTreeChangedBuffer = true;\n\t\t} else {\n\t\t\tthis.#events.emit(\"subtreeChangedAfterBatch\");\n\t\t}\n\t}\n\n\t/**\n\t * Flushes any events buffered due to {@link withBufferedTreeEvents}.\n\t */\n\tpublic flush(): void {\n\t\tthis.#assertNotDisposed();\n\n\t\tif (this.#childrenChangedBuffer.size > 0) {\n\t\t\tthis.#events.emit(\"childrenChangedAfterBatch\", {\n\t\t\t\tchangedFields: this.#childrenChangedBuffer,\n\t\t\t});\n\t\t\tthis.#childrenChangedBuffer.clear();\n\t\t}\n\n\t\tif (this.#subTreeChangedBuffer) {\n\t\t\tthis.#events.emit(\"subtreeChangedAfterBatch\");\n\t\t\tthis.#subTreeChangedBuffer = false;\n\t\t}\n\t}\n\n\t#assertNotDisposed(): void {\n\t\tassert(!this.#disposed, 0xc51 /* Event handler disposed. */);\n\t}\n\n\tpublic dispose(): void {\n\t\tif (this.#disposed) {\n\t\t\treturn;\n\t\t}\n\n\t\tassert(\n\t\t\tthis.#childrenChangedBuffer.size === 0 && !this.#subTreeChangedBuffer,\n\t\t\t0xc52 /* Buffered kernel events should have been flushed before disposing. */,\n\t\t);\n\n\t\tthis.#disposeOnFlushListener();\n\t\tthis.#disposeSourceListeners.forEach((off) => off());\n\t\tthis.#disposeSourceListeners.clear();\n\n\t\tthis.#childrenChangedBuffer.clear();\n\t\tthis.#subTreeChangedBuffer = false;\n\n\t\tthis.#disposed = true;\n\t}\n}\n\n// #endregion\n\n/**\n * For \"cooked\" nodes this is a HydratedFlexTreeNode thats a projection of forest content.\n * For {@link Unhydrated} nodes this is a UnhydratedFlexTreeNode.\n *\n * For \"marinated\" nodes, some code (ex: getOrCreateInnerNode) returns the FlexTreeNode thats a projection of forest content, and some code (ex: tryGetInnerNode) returns undefined.\n */\nexport type InnerNode = FlexTreeNode;\n\n/**\n * Narrows innerNode to either {@link UnhydratedFlexTreeNode} or {@link HydratedFlexTreeNode}.\n */\nexport function splitInnerNodeType(\n\tinnerNode: InnerNode,\n): asserts innerNode is UnhydratedFlexTreeNode | HydratedFlexTreeNode {\n\tassert(\n\t\tinnerNode instanceof UnhydratedFlexTreeNode || innerNode.isHydrated(),\n\t\t0xbc8 /* Invalid inner node type */,\n\t);\n}\n\n/**\n * An anchor slot which associates an anchor with its corresponding {@link TreeNode}, if there is one.\n * @remarks\n * For this to work, we have to require that there is at most a single view using a given AnchorSet.\n * FlexTree already has this assumption, and we also assume there is a single simple-tree per FlexTree, so this is valid.\n */\nexport const simpleTreeNodeSlot = anchorSlot<TreeNode>();\n\n/**\n * Dispose a TreeNode (if any) for an existing anchor without disposing the anchor.\n */\nexport function tryDisposeTreeNode(anchorNode: AnchorNode): void {\n\tconst treeNode = anchorNode.slots.get(simpleTreeNodeSlot);\n\tif (treeNode !== undefined) {\n\t\tconst kernel = getKernel(treeNode);\n\t\tkernel.dispose();\n\t\tanchorNode.slots.delete(simpleTreeNodeSlot);\n\t}\n}\n\n/**\n * Gets the {@link TreeNodeSchema} for the {@link InnerNode}.\n */\nexport function getSimpleNodeSchemaFromInnerNode(innerNode: InnerNode): TreeNodeSchema {\n\tconst context: Context = getSimpleContextFromInnerNode(innerNode);\n\treturn context.schema.get(innerNode.type) ?? fail(0xb3f /* missing schema from context */);\n}\n\n/**\n * Gets the {@link Context} for the {@link InnerNode}.\n */\nexport function getSimpleContextFromInnerNode(innerNode: InnerNode): Context {\n\tsplitInnerNodeType(innerNode);\n\tif (innerNode instanceof UnhydratedFlexTreeNode) {\n\t\treturn innerNode.simpleContext;\n\t}\n\n\tconst context = innerNode.anchorNode.anchorSet.slots.get(SimpleContextSlot);\n\tassert(context !== undefined, 0xa55 /* missing simple tree context */);\n\n\treturn context;\n}\n\n/**\n * Retrieves the flex node associated with the given target.\n * @remarks\n * For {@link Unhydrated} nodes, this returns the MapTreeNode.\n *\n * For hydrated nodes it returns a FlexTreeNode backed by the forest.\n * Note that for \"marinated\" nodes, this FlexTreeNode exists and returns it: it does not return the MapTreeNode which is the current InnerNode.\n *\n * @throws A {@link @fluidframework/telemetry-utils#UsageError} if the node has been deleted.\n */\nexport function getOrCreateInnerNode(treeNode: TreeNode): InnerNode {\n\tconst kernel = getKernel(treeNode);\n\treturn kernel.getOrCreateInnerNode();\n}\n\n/**\n * Gets a flex node from an anchor node\n */\nfunction flexNodeFromAnchor(anchorNode: AnchorNode): HydratedFlexTreeNode {\n\tconst flexNode = anchorNode.slots.get(flexTreeSlot);\n\tif (flexNode !== undefined) {\n\t\treturn flexNode; // If it does have a flex node, return it...\n\t} // ...otherwise, the flex node must be created\n\tconst context =\n\t\tanchorNode.anchorSet.slots.get(ContextSlot) ?? fail(0xb45 /* missing context */);\n\tconst cursor = context.checkout.forest.allocateCursor(\"getFlexNode\");\n\tcontext.checkout.forest.moveCursorToPath(anchorNode, cursor);\n\tconst newFlexNode = getOrCreateHydratedFlexTreeNode(context, cursor);\n\tcursor.free();\n\treturn newFlexNode;\n}\n\n/**\n * Gets a tree node from an anchor node\n */\nexport function treeNodeFromAnchor(anchorNode: AnchorNode): TreeNode | TreeValue {\n\tconst cached = anchorNode.slots.get(simpleTreeNodeSlot);\n\tif (cached !== undefined) {\n\t\treturn cached;\n\t}\n\n\tconst flexNode = flexNodeFromAnchor(anchorNode);\n\treturn createTreeNodeFromInner(flexNode);\n}\n\n/**\n * Constructs a TreeNode from an InnerNode.\n * @remarks\n * This does not do caching or validation: caller must ensure duplicate nodes for a given inner node are not created, and that the inner node is valid.\n */\nexport function createTreeNodeFromInner(innerNode: InnerNode): TreeNode | TreeValue {\n\tconst classSchema = getSimpleNodeSchemaFromInnerNode(innerNode);\n\tconst internal = innerNode as unknown as InternalTreeNode;\n\treturn typeof classSchema === \"function\"\n\t\t? new classSchema(internal)\n\t\t: (classSchema as { create(data: InternalTreeNode): TreeNode | TreeValue }).create(\n\t\t\t\tinternal,\n\t\t\t);\n}\n\n/**\n * Creating multiple simple tree contexts for the same branch, and thus with the same underlying AnchorSet does not work due to how TreeNode caching works.\n * This slot is used to detect if one already exists and error if creating a second.\n * @remarks\n * See also {@link ContextSlot} in which the flex-tree context is stored.\n */\nexport const SimpleContextSlot = anchorSlot<HydratedContext>();\n"]}
|
package/lib/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluidframework/tree";
|
|
8
|
-
export declare const pkgVersion = "2.61.0
|
|
8
|
+
export declare const pkgVersion = "2.61.0";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,yBAAyB,CAAC;AAC9C,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,yBAAyB,CAAC;AAC9C,eAAO,MAAM,UAAU,WAAW,CAAC"}
|
package/lib/packageVersion.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,sBAAsB,CAAC;AAC9C,MAAM,CAAC,MAAM,UAAU,GAAG,
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,sBAAsB,CAAC;AAC9C,MAAM,CAAC,MAAM,UAAU,GAAG,QAAQ,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/tree\";\nexport const pkgVersion = \"2.61.0\";\n"]}
|
|
@@ -36,8 +36,8 @@ function createDirtyVisitor(forest, dirty) {
|
|
|
36
36
|
let parent;
|
|
37
37
|
return createAnnouncedVisitor({
|
|
38
38
|
beforeDetach: (src) => {
|
|
39
|
-
assert(parent !== undefined,
|
|
40
|
-
assert(parentField !== undefined,
|
|
39
|
+
assert(parent !== undefined, 0xc48 /* Expected node */);
|
|
40
|
+
assert(parentField !== undefined, 0xc49 /* Expected field */);
|
|
41
41
|
for (let parentIndex = src.start; parentIndex < src.end; parentIndex++) {
|
|
42
42
|
const path = {
|
|
43
43
|
parent,
|
|
@@ -58,8 +58,8 @@ function createDirtyVisitor(forest, dirty) {
|
|
|
58
58
|
}
|
|
59
59
|
},
|
|
60
60
|
afterAttach: (_, dst) => {
|
|
61
|
-
assert(parent !== undefined,
|
|
62
|
-
assert(parentField !== undefined,
|
|
61
|
+
assert(parent !== undefined, 0xc4a /* Expected node */);
|
|
62
|
+
assert(parentField !== undefined, 0xc4b /* Expected field */);
|
|
63
63
|
for (let parentIndex = dst.start; parentIndex < dst.end; parentIndex++) {
|
|
64
64
|
const path = {
|
|
65
65
|
parent,
|
|
@@ -79,7 +79,7 @@ function createDirtyVisitor(forest, dirty) {
|
|
|
79
79
|
}
|
|
80
80
|
},
|
|
81
81
|
enterNode(index) {
|
|
82
|
-
assert(parentField !== undefined,
|
|
82
|
+
assert(parentField !== undefined, 0xc4c /* Expected field */);
|
|
83
83
|
parent = {
|
|
84
84
|
parent,
|
|
85
85
|
parentField,
|
|
@@ -88,7 +88,7 @@ function createDirtyVisitor(forest, dirty) {
|
|
|
88
88
|
parentField = undefined;
|
|
89
89
|
},
|
|
90
90
|
exitNode() {
|
|
91
|
-
assert(parent !== undefined,
|
|
91
|
+
assert(parent !== undefined, 0xc4d /* Expected node */);
|
|
92
92
|
parentField = parent.parentField;
|
|
93
93
|
parent = parent.parent;
|
|
94
94
|
},
|
|
@@ -103,7 +103,7 @@ function createDirtyVisitor(forest, dirty) {
|
|
|
103
103
|
function getNodeAtPath(forest, path) {
|
|
104
104
|
const cursor = forest.allocateCursor();
|
|
105
105
|
forest.moveCursorToPath(path, cursor);
|
|
106
|
-
assert(cursor.mode === 0 /* CursorLocationType.Nodes */,
|
|
106
|
+
assert(cursor.mode === 0 /* CursorLocationType.Nodes */, 0xc4e /* attach should happen in a node */);
|
|
107
107
|
const anchor = cursor.buildAnchor();
|
|
108
108
|
const anchorNode = forest.anchors.locate(anchor);
|
|
109
109
|
cursor.free();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dirtyIndex.js","sourceRoot":"","sources":["../../../src/simple-tree/api/dirtyIndex.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAC7D,OAAO,EACN,sBAAsB,GAMtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAyBhE;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,eAAe,CAC9B,IAAwC,EACxC,KAAmB;IAEnB,MAAM,MAAM,GAAI,IAAwD,CAAC,QAAQ,CAAC,MAAM,CAAC;IAC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,CAAC;KACD,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,aAAa,CAAC,MAAuB,EAAE,IAAY;IAC3D,MAAM,MAAM,GAAG,MAAM,CAAC,cAAc,EAAE,CAAC;IACvC,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACtC,MAAM,CAAC,MAAM,CAAC,IAAI,qCAA6B,EAAE,KAAK,CAAC,oCAAoC,CAAC,CAAC;IAC7F,MAAM,MAAM,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;IACpC,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACjD,MAAM,CAAC,IAAI,EAAE,CAAC;IACd,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;QAC9B,MAAM,IAAI,GAAG,kBAAkB,CAAC,UAAU,CAAC,CAAC;QAC5C,IAAI,IAAI,YAAY,QAAQ,EAAE,CAAC;YAC9B,OAAO,IAAI,CAAC;QACb,CAAC;IACF,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tcreateAnnouncedVisitor,\n\tCursorLocationType,\n\ttype AnnouncedVisitor,\n\ttype FieldKey,\n\ttype IEditableForest,\n\ttype UpPath,\n} from \"../../core/index.js\";\nimport { TreeNode, treeNodeFromAnchor } from \"../core/index.js\";\nimport type { TreeViewAlpha } from \"./tree.js\";\nimport type { SchematizingSimpleTreeView } from \"../../shared-tree/index.js\";\nimport type { ImplicitFieldSchema } from \"../fieldSchema.js\";\n\n/**\n * The status of a node in a that has been {@link trackDirtyNodes | tracked for changes}.\n * @remarks Nodes can be marked \"new\", \"changed\", or \"moved\", with \"new\" taking precedence over \"changed\" and \"changed\" taking precedence over \"moved\".\n * * \"new\": The node was added.\n * * \"changed\": A direct child was updated, added, removed, or moved (and the node is not \"new\").\n * * \"moved\": The node was moved between/within arrays (and the node is not \"new\" or \"changed\").\n * @alpha\n */\nexport type DirtyTreeStatus = \"new\" | \"changed\" | \"moved\";\n\n/**\n * A map-like interface for tracking the {@link DirtyTreeStatus | status} of nodes that have been {@link trackDirtyNodes | tracked for changes}.\n * @privateRemarks TODO: Replace this with `MapGetSet` from `@fluidframework/core-interfaces`.\n * @alpha\n */\nexport interface DirtyTreeMap {\n\tget(node: TreeNode): DirtyTreeStatus | undefined;\n\tset(node: TreeNode, status: DirtyTreeStatus): void;\n}\n\n/**\n * Registers a visitor on the view's forest that tracks which nodes are dirty.\n * @param view - The view to track dirty nodes on\n * @param dirty - A {@link DirtyTreeMap | map} that will be updated over time to reflect the {@link DirtyTreeStatus | status} of nodes as they change.\n * Nodes that have not changed will not be inserted/updated in the map.\n * @returns a cleanup function that should be called when the tracking is no longer needed.\n * @example\n * ```typescript\n * const dirty = new Map<TreeNode, DirtyTreeStatus>();\n * const stopTracking = trackDirtyNodes(view, dirty);\n * // ... make changes to the view ...\n * console.log(`The root of the tree is ${dirty.get(view.root) ?? \"unchanged\"}`);\n * stopTracking();\n * ```\n * @alpha\n */\nexport function trackDirtyNodes(\n\tview: TreeViewAlpha<ImplicitFieldSchema>,\n\tdirty: DirtyTreeMap,\n): () => void {\n\tconst forest = (view as SchematizingSimpleTreeView<ImplicitFieldSchema>).checkout.forest;\n\tconst announcedVisitor = (): AnnouncedVisitor => createDirtyVisitor(forest, dirty);\n\tforest.registerAnnouncedVisitor(announcedVisitor);\n\treturn () => {\n\t\tforest.deregisterAnnouncedVisitor(announcedVisitor);\n\t};\n}\n\nfunction createDirtyVisitor(forest: IEditableForest, dirty: DirtyTreeMap): AnnouncedVisitor {\n\t// When cursor is in Fields mode, `parentField` is the field and `parent` is the parent node above that field (if any).\n\t// When cursor is in Nodes mode, `parent` is the current node and `parentField` is undefined.\n\tlet parentField: FieldKey | undefined;\n\tlet parent: UpPath | undefined;\n\n\treturn createAnnouncedVisitor({\n\t\tbeforeDetach: (src) => {\n\t\t\tassert(parent !== undefined, 0xc48 /* Expected node */);\n\t\t\tassert(parentField !== undefined, 0xc49 /* Expected field */);\n\t\t\tfor (let parentIndex = src.start; parentIndex < src.end; parentIndex++) {\n\t\t\t\tconst path: UpPath = {\n\t\t\t\t\tparent,\n\t\t\t\t\tparentField,\n\t\t\t\t\tparentIndex,\n\t\t\t\t};\n\t\t\t\t// The only way a detached node can be re-attached (and become visible/usable again) is via a move, so mark it as moved ahead of time.\n\t\t\t\tconst node = getNodeAtPath(forest, path);\n\t\t\t\tif (node !== undefined && dirty.get(node) === undefined) {\n\t\t\t\t\t// Only mark the node as moved if it is not already marked as something else.\n\t\t\t\t\tdirty.set(node, \"moved\");\n\t\t\t\t}\n\t\t\t\t// Mark the parent as changed unless it is already marked as new.\n\t\t\t\tconst parentNode = getNodeAtPath(forest, parent);\n\t\t\t\tif (parentNode !== undefined && dirty.get(parentNode) !== \"new\") {\n\t\t\t\t\tdirty.set(parentNode, \"changed\");\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\tafterAttach: (_, dst) => {\n\t\t\tassert(parent !== undefined, 0xc4a /* Expected node */);\n\t\t\tassert(parentField !== undefined, 0xc4b /* Expected field */);\n\t\t\tfor (let parentIndex = dst.start; parentIndex < dst.end; parentIndex++) {\n\t\t\t\tconst path: UpPath = {\n\t\t\t\t\tparent,\n\t\t\t\t\tparentField,\n\t\t\t\t\tparentIndex,\n\t\t\t\t};\n\t\t\t\tconst node = getNodeAtPath(forest, path);\n\t\t\t\tif (node !== undefined && dirty.get(node) === undefined) {\n\t\t\t\t\t// Only mark the node as new if it is not already marked as something else - this ensures that a moved node is not marked as new (since nodes are marked move when detached).\n\t\t\t\t\tdirty.set(node, \"new\");\n\t\t\t\t}\n\t\t\t\t// Mark the parent as changed unless it is already marked as new.\n\t\t\t\tconst parentNode = getNodeAtPath(forest, parent);\n\t\t\t\tif (parentNode !== undefined && dirty.get(parentNode) !== \"new\") {\n\t\t\t\t\tdirty.set(parentNode, \"changed\");\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\tenterNode(index: number): void {\n\t\t\tassert(parentField !== undefined, 0xc4c /* Expected field */);\n\t\t\tparent = {\n\t\t\t\tparent,\n\t\t\t\tparentField,\n\t\t\t\tparentIndex: index,\n\t\t\t};\n\t\t\tparentField = undefined;\n\t\t},\n\t\texitNode(): void {\n\t\t\tassert(parent !== undefined, 0xc4d /* Expected node */);\n\t\t\tparentField = parent.parentField;\n\t\t\tparent = parent.parent;\n\t\t},\n\t\tenterField: (key: FieldKey) => {\n\t\t\tparentField = key;\n\t\t},\n\t\texitField(): void {\n\t\t\tparentField = undefined;\n\t\t},\n\t});\n}\n\nfunction getNodeAtPath(forest: IEditableForest, path: UpPath): TreeNode | undefined {\n\tconst cursor = forest.allocateCursor();\n\tforest.moveCursorToPath(path, cursor);\n\tassert(cursor.mode === CursorLocationType.Nodes, 0xc4e /* attach should happen in a node */);\n\tconst anchor = cursor.buildAnchor();\n\tconst anchorNode = forest.anchors.locate(anchor);\n\tcursor.free();\n\tif (anchorNode !== undefined) {\n\t\tconst node = treeNodeFromAnchor(anchorNode);\n\t\tif (node instanceof TreeNode) {\n\t\t\treturn node;\n\t\t}\n\t}\n\treturn undefined;\n}\n"]}
|
|
@@ -343,7 +343,7 @@ class KernelEventBuffer {
|
|
|
343
343
|
// Lazily bind event listeners to the source.
|
|
344
344
|
// If we do not have any existing listeners for this event, then we need to bind to the source.
|
|
345
345
|
if (!__classPrivateFieldGet(this, _KernelEventBuffer_events, "f").hasListeners(eventName)) {
|
|
346
|
-
assert(!__classPrivateFieldGet(this, _KernelEventBuffer_disposeSourceListeners, "f").has(eventName),
|
|
346
|
+
assert(!__classPrivateFieldGet(this, _KernelEventBuffer_disposeSourceListeners, "f").has(eventName), 0xc4f /* Should not have a dispose function without listeners */);
|
|
347
347
|
const off = __classPrivateFieldGet(this, _KernelEventBuffer_eventSource, "f").on(eventName, (args) => __classPrivateFieldGet(this, _KernelEventBuffer_instances, "m", _KernelEventBuffer_emit).call(this, eventName, args));
|
|
348
348
|
__classPrivateFieldGet(this, _KernelEventBuffer_disposeSourceListeners, "f").set(eventName, off);
|
|
349
349
|
}
|
|
@@ -379,7 +379,7 @@ class KernelEventBuffer {
|
|
|
379
379
|
if (__classPrivateFieldGet(this, _KernelEventBuffer_disposed, "f")) {
|
|
380
380
|
return;
|
|
381
381
|
}
|
|
382
|
-
assert(__classPrivateFieldGet(this, _KernelEventBuffer_childrenChangedBuffer, "f").size === 0 && !__classPrivateFieldGet(this, _KernelEventBuffer_subTreeChangedBuffer, "f"),
|
|
382
|
+
assert(__classPrivateFieldGet(this, _KernelEventBuffer_childrenChangedBuffer, "f").size === 0 && !__classPrivateFieldGet(this, _KernelEventBuffer_subTreeChangedBuffer, "f"), 0xc52 /* Buffered kernel events should have been flushed before disposing. */);
|
|
383
383
|
__classPrivateFieldGet(this, _KernelEventBuffer_disposeOnFlushListener, "f").call(this);
|
|
384
384
|
__classPrivateFieldGet(this, _KernelEventBuffer_disposeSourceListeners, "f").forEach((off) => off());
|
|
385
385
|
__classPrivateFieldGet(this, _KernelEventBuffer_disposeSourceListeners, "f").clear();
|
|
@@ -392,7 +392,7 @@ _KernelEventBuffer_disposed = new WeakMap(), _KernelEventBuffer_disposeOnFlushLi
|
|
|
392
392
|
__classPrivateFieldGet(this, _KernelEventBuffer_instances, "m", _KernelEventBuffer_assertNotDisposed).call(this);
|
|
393
393
|
switch (eventName) {
|
|
394
394
|
case "childrenChangedAfterBatch":
|
|
395
|
-
assert(arg !== undefined,
|
|
395
|
+
assert(arg !== undefined, 0xc50 /* childrenChangedAfterBatch should have arg */);
|
|
396
396
|
return __classPrivateFieldGet(this, _KernelEventBuffer_instances, "m", _KernelEventBuffer_handleChildrenChangedAfterBatch).call(this, arg.changedFields);
|
|
397
397
|
case "subtreeChangedAfterBatch":
|
|
398
398
|
return __classPrivateFieldGet(this, _KernelEventBuffer_instances, "m", _KernelEventBuffer_handleSubtreeChangedAfterBatch).call(this);
|
|
@@ -416,7 +416,7 @@ _KernelEventBuffer_disposed = new WeakMap(), _KernelEventBuffer_disposeOnFlushLi
|
|
|
416
416
|
__classPrivateFieldGet(this, _KernelEventBuffer_events, "f").emit("subtreeChangedAfterBatch");
|
|
417
417
|
}
|
|
418
418
|
}, _KernelEventBuffer_assertNotDisposed = function _KernelEventBuffer_assertNotDisposed() {
|
|
419
|
-
assert(!__classPrivateFieldGet(this, _KernelEventBuffer_disposed, "f"),
|
|
419
|
+
assert(!__classPrivateFieldGet(this, _KernelEventBuffer_disposed, "f"), 0xc51 /* Event handler disposed. */);
|
|
420
420
|
};
|
|
421
421
|
/**
|
|
422
422
|
* Narrows innerNode to either {@link UnhydratedFlexTreeNode} or {@link HydratedFlexTreeNode}.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"treeNodeKernel.js","sourceRoot":"","sources":["../../../src/simple-tree/core/treeNodeKernel.ts"],"names":[],"mappings":"AAAA;;;GAGG;;;;;;;;;;;;;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAE7D,OAAO,EACN,MAAM,EACN,IAAI,EACJ,WAAW,EACX,eAAe,GACf,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAEtE,OAAO,EACN,UAAU,GAOV,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,+BAA+B,EAAE,MAAM,kCAAkC,CAAC;AACnF,OAAO,EACN,4BAA4B,EAC5B,WAAW,EACX,YAAY,EACZ,UAAU,EACV,UAAU,EACV,yBAAyB,GAGzB,MAAM,kCAAkC,CAAC;AAM1C,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAEjE,MAAM,gBAAgB,GAAG,IAAI,OAAO,EAA4B,CAAC;AAEjE,MAAM,UAAU,SAAS,CAAC,IAAc;IACvC,MAAM,MAAM,GAAG,gBAAgB,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AAW,GAAG,+BAA+B,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACrE,MAAM,CAAC,IAAI,EAAE,CAAC;IACd,OAAO,WAAW,CAAC;AACpB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,UAAsB;IACxD,MAAM,MAAM,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;IACxD,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QAC1B,OAAO,MAAM,CAAC;IACf,CAAC;IAED,MAAM,QAAQ,GAAG,kBAAkB,CAAC,UAAU,CAAC,CAAC;IAChD,OAAO,uBAAuB,CAAC,QAAQ,CAAC,CAAC;AAC1C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CAAC,SAAoB;IAC3D,MAAM,WAAW,GAAG,gCAAgC,CAAC,SAAS,CAAC,CAAC;IAChE,MAAM,QAAQ,GAAG,SAAwC,CAAC;IAC1D,OAAO,OAAO,WAAW,KAAK,UAAU;QACvC,CAAC,CAAC,IAAI,WAAW,CAAC,QAAQ,CAAC;QAC3B,CAAC,CAAE,WAAwE,CAAC,MAAM,CAChF,QAAQ,CACR,CAAC;AACL,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,UAAU,EAAmB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { createEmitter } from \"@fluid-internal/client-utils\";\nimport type { HasListeners, Listenable, Off } from \"@fluidframework/core-interfaces/internal\";\nimport {\n\tassert,\n\tfail,\n\tdebugAssert,\n\tunreachableCase,\n} from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\tanchorSlot,\n\ttype AnchorEvents,\n\ttype AnchorNode,\n\ttype AnchorSet,\n\ttype FieldKey,\n\ttype TreeValue,\n\ttype UpPath,\n} from \"../../core/index.js\";\nimport { getOrCreateHydratedFlexTreeNode } from \"../../feature-libraries/index.js\";\nimport {\n\tassertFlexTreeEntityNotFreed,\n\tContextSlot,\n\tflexTreeSlot,\n\tLazyEntity,\n\tTreeStatus,\n\ttreeStatusFromAnchorCache,\n\ttype FlexTreeNode,\n\ttype HydratedFlexTreeNode,\n} from \"../../feature-libraries/index.js\";\n\nimport type { Context, HydratedContext } from \"./context.js\";\nimport type { TreeNode } from \"./treeNode.js\";\nimport type { TreeNodeSchema } from \"./treeNodeSchema.js\";\nimport type { InternalTreeNode, Unhydrated } from \"./types.js\";\nimport { UnhydratedFlexTreeNode } from \"./unhydratedFlexTree.js\";\n\nconst treeNodeToKernel = new WeakMap<TreeNode, TreeNodeKernel>();\n\nexport function getKernel(node: TreeNode): TreeNodeKernel {\n\tconst kernel = treeNodeToKernel.get(node);\n\tassert(kernel !== undefined, 0x9b1 /* Expected tree node to have kernel */);\n\treturn kernel;\n}\n\n/**\n * Detects if the given 'candidate' is a TreeNode.\n *\n * @remarks\n * Supports both Hydrated and {@link Unhydrated} TreeNodes, both of which return true.\n *\n * Because the common usage is to check if a value being inserted/set is a TreeNode,\n * this function permits calling with primitives as well as objects.\n *\n * Primitives will always return false (as they are copies of data, not references to nodes).\n *\n * @param candidate - Value which may be a TreeNode\n * @returns true if the given 'candidate' is a hydrated TreeNode.\n */\nexport function isTreeNode(candidate: unknown): candidate is TreeNode | Unhydrated<TreeNode> {\n\treturn treeNodeToKernel.has(candidate as TreeNode);\n}\n\n/**\n * Returns a schema for a value if the value is a {@link TreeNode}.\n *\n * Returns undefined for other values.\n * @remarks\n * Does not give schema for a {@link TreeLeafValue}.\n */\nexport function tryGetTreeNodeSchema(value: unknown): undefined | TreeNodeSchema {\n\tconst kernel = treeNodeToKernel.get(value as TreeNode);\n\treturn kernel?.schema;\n}\n\n/** The {@link HydrationState} of a {@link TreeNodeKernel} before the kernel is hydrated */\ninterface UnhydratedState {\n\treadonly innerNode: UnhydratedFlexTreeNode;\n}\n\n/** The {@link HydrationState} of a {@link TreeNodeKernel} after the kernel is hydrated */\ninterface HydratedState {\n\t/** The flex node for this kernel (lazy - undefined if it has not yet been demanded) */\n\tinnerNode?: FlexTreeNode;\n\t/** The {@link AnchorNode} that this node is associated with. */\n\treadonly anchorNode: AnchorNode;\n\t/** All {@link Off | event deregistration functions} that should be run when the kernel is disposed. */\n\treadonly offAnchorNode: Set<Off>;\n}\n\n/** State within a {@link TreeNodeKernel} that is related to the hydration process */\ntype HydrationState = UnhydratedState | HydratedState;\n\n/** True if and only if the given {@link HydrationState} is post-hydration */\nfunction isHydrated(state: HydrationState): state is HydratedState {\n\treturn (state as Partial<HydratedState>).anchorNode !== undefined;\n}\n\n/**\n * Contains state and an internal API for managing {@link TreeNode}s.\n * @remarks All {@link TreeNode}s have an associated kernel object.\n * The kernel has the same lifetime as the node and spans both its unhydrated and hydrated states.\n */\nexport class TreeNodeKernel {\n\tprivate disposed = false;\n\n\t/**\n\t * Generation number which is incremented any time we have an edit on the node.\n\t * Used during iteration to make sure there has been no edits that were concurrently made.\n\t * @remarks\n\t * This is updated monotonically by this class when edits are applied.\n\t * TODO: update this when applying edits to unhydrated trees.\n\t *\n\t * If TypeScript supported making this immutable from outside the class without making it readonly from inside, that would be used here,\n\t * but they only way to do that is add a separate public accessor and make it private, which was deemed not worth the boilerplate, runtime overhead and bundle size.\n\t */\n\tpublic generationNumber: number = 0;\n\n\t#hydrationState: HydrationState;\n\n\t/**\n\t * Events registered before hydration.\n\t * @remarks\n\t * Since these are usually not used, they are allocated lazily as an optimization.\n\t * The laziness also avoids extra forwarding overhead for events from this kernel's anchor node and also avoids registering for events that are unneeded.\n\t * This means optimizations like skipping processing data in subtrees where no subtreeChanged events are subscribed to would be able to work,\n\t * since the kernel does not unconditionally subscribe to those events (like a design which simply forwards all events would).\n\t */\n\treadonly #eventBuffer: KernelEventBuffer;\n\n\t/**\n\t * Create a TreeNodeKernel which can be looked up with {@link getKernel}.\n\t *\n\t * @param initialContext - context from when this node was originally created. Only used when unhydrated.\n\t * @param innerNode - When unhydrated/raw or marinated the MapTreeNode. FlexTreeNode when cooked.\n\t * @remarks\n\t * Exactly one kernel per TreeNode should be created.\n\t */\n\tpublic constructor(\n\t\tpublic readonly node: TreeNode,\n\t\tpublic readonly schema: TreeNodeSchema,\n\t\tinnerNode: InnerNode,\n\t\tprivate readonly initialContext: Context,\n\t) {\n\t\tsplitInnerNodeType(innerNode);\n\n\t\tassert(!treeNodeToKernel.has(node), 0xa1a /* only one kernel per node can be made */);\n\t\ttreeNodeToKernel.set(node, this);\n\n\t\tif (innerNode instanceof UnhydratedFlexTreeNode) {\n\t\t\t// Unhydrated case\n\n\t\t\tdebugAssert(() => innerNode.treeNode === undefined);\n\t\t\tinnerNode.treeNode = node;\n\n\t\t\tthis.#hydrationState = {\n\t\t\t\tinnerNode,\n\t\t\t};\n\n\t\t\tthis.#eventBuffer = new KernelEventBuffer(innerNode.events);\n\t\t} else {\n\t\t\t// Hydrated case\n\t\t\tthis.#hydrationState = this.createHydratedState(innerNode.anchorNode);\n\t\t\tthis.#hydrationState.innerNode = innerNode;\n\n\t\t\tthis.#eventBuffer = new KernelEventBuffer(innerNode.anchorNode.events);\n\t\t}\n\t}\n\n\tpublic get context(): Context {\n\t\tif (isHydrated(this.#hydrationState)) {\n\t\t\t// This can't be cached on this.#hydrated during hydration since initial tree is hydrated before the context is cached on the anchorSet.\n\t\t\treturn (\n\t\t\t\tthis.#hydrationState?.anchorNode.anchorSet.slots.get(SimpleContextSlot) ??\n\t\t\t\tfail(0xb40 /* missing simple-tree context */)\n\t\t\t);\n\t\t}\n\t\treturn this.initialContext;\n\t}\n\n\t/**\n\t * Transition from {@link Unhydrated} to hydrated.\n\t * Bi-directionally associates the given hydrated TreeNode to the anchor node at the provided path.\n\t * @remarks\n\t * Happens at most once for any given node.\n\t * Cleans up mappings to {@link UnhydratedFlexTreeNode} - it is assumed that they are no longer needed once this node has an anchor node.\n\t */\n\tpublic hydrate(anchors: AnchorSet, path: UpPath): void {\n\t\tassert(!this.disposed, 0xa2a /* cannot hydrate a disposed node */);\n\t\tassert(!isHydrated(this.#hydrationState), 0xa2b /* hydration should only happen once */);\n\n\t\tconst anchor = anchors.track(path);\n\t\tconst anchorNode =\n\t\t\tanchors.locate(anchor) ?? fail(0xb42 /* Expected anchor node to be present */);\n\n\t\tthis.#hydrationState = this.createHydratedState(anchorNode);\n\t\tthis.#hydrationState.offAnchorNode.add(() => anchors.forget(anchor));\n\n\t\t// Lazily migrate existing event listeners to the anchor node\n\t\tthis.#eventBuffer.migrateEventSource(anchorNode.events);\n\t}\n\n\tprivate createHydratedState(anchorNode: AnchorNode): HydratedState {\n\t\tassert(\n\t\t\t!anchorNode.slots.has(simpleTreeNodeSlot),\n\t\t\t0x7f5 /* Cannot associate an flex node with multiple simple-tree nodes */,\n\t\t);\n\t\tanchorNode.slots.set(simpleTreeNodeSlot, this.node);\n\t\treturn {\n\t\t\tanchorNode,\n\t\t\toffAnchorNode: new Set([\n\t\t\t\tanchorNode.events.on(\"afterDestroy\", () => this.dispose()),\n\t\t\t\t// TODO: this should be triggered on change even for unhydrated nodes.\n\t\t\t\tanchorNode.events.on(\"childrenChanging\", () => {\n\t\t\t\t\tthis.generationNumber += 1;\n\t\t\t\t}),\n\t\t\t]),\n\t\t};\n\t}\n\n\tpublic getStatus(): TreeStatus {\n\t\tif (this.disposed) {\n\t\t\treturn TreeStatus.Deleted;\n\t\t}\n\t\tif (!isHydrated(this.#hydrationState)) {\n\t\t\treturn TreeStatus.New;\n\t\t}\n\n\t\t// TODO: Replace this check with the proper check against the cursor state when the cursor becomes part of the kernel\n\t\tconst flex = this.#hydrationState.anchorNode.slots.get(flexTreeSlot);\n\t\tif (flex !== undefined) {\n\t\t\tassert(flex instanceof LazyEntity, 0x9b4 /* Unexpected flex node implementation */);\n\t\t\tif (flex.isFreed()) {\n\t\t\t\treturn TreeStatus.Deleted;\n\t\t\t}\n\t\t}\n\n\t\treturn treeStatusFromAnchorCache(this.#hydrationState.anchorNode);\n\t}\n\n\tpublic get events(): Listenable<KernelEvents> {\n\t\treturn this.#eventBuffer;\n\t}\n\n\tpublic dispose(): void {\n\t\tdebugAssert(() => !this.disposed || \"Cannot dispose a disposed node\");\n\t\tthis.disposed = true;\n\t\tif (isHydrated(this.#hydrationState)) {\n\t\t\tfor (const off of this.#hydrationState.offAnchorNode) {\n\t\t\t\toff();\n\t\t\t}\n\t\t}\n\t\tthis.#eventBuffer.dispose();\n\t\t// TODO: go to the context and remove myself from withAnchors\n\t}\n\n\tpublic isHydrated(): this is { anchorNode: AnchorNode; context: HydratedContext } {\n\t\treturn isHydrated(this.#hydrationState);\n\t}\n\n\tpublic get anchorNode(): AnchorNode | undefined {\n\t\treturn isHydrated(this.#hydrationState) ? this.#hydrationState.anchorNode : undefined;\n\t}\n\n\t/**\n\t * Retrieves the flex node associated with the given target.\n\t * @remarks\n\t * For {@link Unhydrated} nodes, this returns the MapTreeNode.\n\t *\n\t * For hydrated nodes it returns a FlexTreeNode backed by the forest.\n\t * Note that for \"marinated\" nodes, this FlexTreeNode exists and returns it: it does not return the MapTreeNode which is the current InnerNode.\n\t *\n\t * @throws A {@link @fluidframework/telemetry-utils#UsageError} if the node has been deleted.\n\t */\n\tpublic getOrCreateInnerNode(): InnerNode {\n\t\tif (!isHydrated(this.#hydrationState)) {\n\t\t\tdebugAssert(\n\t\t\t\t() =>\n\t\t\t\t\tthis.#hydrationState.innerNode?.context.isDisposed() === false ||\n\t\t\t\t\t\"Unhydrated node should never be disposed\",\n\t\t\t);\n\t\t\treturn this.#hydrationState.innerNode; // Unhydrated case\n\t\t}\n\n\t\tif (this.disposed) {\n\t\t\tthrow new UsageError(\"Cannot access a deleted node.\");\n\t\t}\n\n\t\tif (this.#hydrationState.innerNode === undefined) {\n\t\t\t// Marinated case -> cooked\n\t\t\tconst anchorNode = this.#hydrationState.anchorNode;\n\t\t\t// This TreeNode is bound to an anchor node, but it may or may not have an actual flex node yet\n\t\t\tconst flexNode = anchorNode.slots.get(flexTreeSlot);\n\t\t\tif (flexNode !== undefined) {\n\t\t\t\t// If the flex node already exists, use it...\n\t\t\t\tthis.#hydrationState.innerNode = flexNode;\n\t\t\t} else {\n\t\t\t\t// ...otherwise, the flex node must be created\n\t\t\t\tconst context =\n\t\t\t\t\tanchorNode.anchorSet.slots.get(ContextSlot) ?? fail(0xb41 /* missing context */);\n\t\t\t\tconst cursor = context.checkout.forest.allocateCursor(\"getFlexNode\");\n\t\t\t\tcontext.checkout.forest.moveCursorToPath(anchorNode, cursor);\n\t\t\t\tthis.#hydrationState.innerNode = getOrCreateHydratedFlexTreeNode(context, cursor);\n\t\t\t\tcursor.free();\n\t\t\t\tassertFlexTreeEntityNotFreed(this.#hydrationState.innerNode);\n\t\t\t}\n\t\t}\n\n\t\treturn this.#hydrationState.innerNode;\n\t}\n\n\t/**\n\t * Retrieves the {@link UnhydratedFlexTreeNode} if unhydrated. otherwise undefined.\n\t */\n\tpublic getInnerNodeIfUnhydrated(): UnhydratedFlexTreeNode | undefined {\n\t\tif (isHydrated(this.#hydrationState)) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn this.#hydrationState.innerNode;\n\t}\n}\n\nconst kernelEvents = [\"childrenChangedAfterBatch\", \"subtreeChangedAfterBatch\"] as const;\n\ntype KernelEvents = Pick<AnchorEvents, (typeof kernelEvents)[number]>;\n\n// #region TreeNodeEventBuffer\n\n/**\n * Whether or not events from {@link TreeNodeKernel} should be buffered instead of emitted immediately.\n */\nlet bufferTreeEvents: boolean = false;\n\n/**\n * Call the provided callback with {@link TreeNode}s' events paused until after the callback's completion.\n *\n * Events that would otherwise have been emitted immediately are merged and buffered until after the\n * provided callback has been completed.\n *\n * @remarks\n * Note: this should be used with caution. User application behaviors are implicitly coupled to event timing.\n * Disrupting this timing can lead to unexpected behavior.\n */\nexport function withBufferedTreeEvents(callback: () => void): void {\n\tif (bufferTreeEvents) {\n\t\t// Already buffering - just run the callback\n\t\tcallback();\n\t} else {\n\t\tbufferTreeEvents = true;\n\t\ttry {\n\t\t\tcallback();\n\t\t} finally {\n\t\t\tbufferTreeEvents = false;\n\t\t\tflushEventsEmitter.emit(\"flush\");\n\t\t}\n\t}\n}\n\n/**\n * Event emitter to notify subscribers when tree events buffered due to {@link withBufferedTreeEvents} should be flushed.\n */\nconst flushEventsEmitter = createEmitter<{\n\tflush: () => void;\n}>();\n\n/**\n * Event emitter for {@link TreeNodeKernel}, which optionally buffers events based on {@link bufferTreeEvents}.\n * @remarks Listens to {@link flushEventsEmitter} to know when to flush any buffered events.\n */\nclass KernelEventBuffer implements Listenable<KernelEvents> {\n\t#disposed: boolean = false;\n\n\t/**\n\t * Listen to {@link flushEventsEmitter} to know when to flush buffered events.\n\t */\n\treadonly #disposeOnFlushListener = flushEventsEmitter.on(\"flush\", () => {\n\t\tthis.flush();\n\t});\n\n\treadonly #events = createEmitter<KernelEvents>();\n\n\t#eventSource: Listenable<KernelEvents> & HasListeners<KernelEvents>;\n\t#disposeSourceListeners: Map<keyof KernelEvents, Off> = new Map();\n\n\t/**\n\t * Buffer of fields that have changed since events were paused.\n\t * When events are flushed, a single {@link AnchorEvents.childrenChangedAfterBatch} event will be emitted\n\t * containing the accumulated set of changed fields.\n\t */\n\treadonly #childrenChangedBuffer: Set<FieldKey> = new Set();\n\n\t/**\n\t * Whether or not the subtree has changed since events were paused.\n\t * When events are flushed, a single {@link AnchorEvents.subTreeChanged} event will be emitted if and only\n\t * if the subtree has changed.\n\t */\n\t#subTreeChangedBuffer: boolean = false;\n\n\tpublic constructor(\n\t\t/**\n\t\t * Source of the kernel events.\n\t\t * Subscriptions will be created on-demand when listeners are added to this.events,\n\t\t * and those subscriptions will be cleaned up when all corresponding listeners have been removed.\n\t\t */\n\t\teventSource: Listenable<KernelEvents> & HasListeners<KernelEvents>,\n\t) {\n\t\tthis.#eventSource = eventSource;\n\t}\n\n\t/**\n\t * Migrate this event buffer to a new event source.\n\t *\n\t * @remarks\n\t * Cleans up any existing event subscriptions from the old source.\n\t * Binds events to the new source for each event with active listeners.\n\t */\n\tpublic migrateEventSource(\n\t\tnewSource: Listenable<KernelEvents> & HasListeners<KernelEvents>,\n\t): void {\n\t\t// Unsubscribe from the old source\n\t\tthis.#disposeSourceListeners.forEach((off) => off());\n\t\tthis.#disposeSourceListeners.clear();\n\n\t\tthis.#eventSource = newSource;\n\n\t\tif (this.#events.hasListeners(\"childrenChangedAfterBatch\")) {\n\t\t\tconst off = this.#eventSource.on(\"childrenChangedAfterBatch\", ({ changedFields }) =>\n\t\t\t\tthis.#emit(\"childrenChangedAfterBatch\", { changedFields }),\n\t\t\t);\n\t\t\tthis.#disposeSourceListeners.set(\"childrenChangedAfterBatch\", off);\n\t\t}\n\t\tif (this.#events.hasListeners(\"subtreeChangedAfterBatch\")) {\n\t\t\tconst off = this.#eventSource.on(\"subtreeChangedAfterBatch\", () =>\n\t\t\t\tthis.#emit(\"subtreeChangedAfterBatch\"),\n\t\t\t);\n\t\t\tthis.#disposeSourceListeners.set(\"subtreeChangedAfterBatch\", off);\n\t\t}\n\t}\n\n\tpublic on(eventName: keyof KernelEvents, listener: KernelEvents[typeof eventName]): Off {\n\t\t// Lazily bind event listeners to the source.\n\t\t// If we do not have any existing listeners for this event, then we need to bind to the source.\n\t\tif (!this.#events.hasListeners(eventName)) {\n\t\t\tassert(\n\t\t\t\t!this.#disposeSourceListeners.has(eventName),\n\t\t\t\t\"Should not have a dispose function without listeners\",\n\t\t\t);\n\n\t\t\tconst off = this.#eventSource.on(eventName, (args) => this.#emit(eventName, args));\n\t\t\tthis.#disposeSourceListeners.set(eventName, off);\n\t\t}\n\n\t\tthis.#events.on(eventName, listener);\n\t\treturn () => this.off(eventName, listener);\n\t}\n\n\tpublic off(eventName: keyof KernelEvents, listener: KernelEvents[typeof eventName]): void {\n\t\tthis.#events.off(eventName, listener);\n\n\t\t// If there are no remaining listeners for the event, unbind from the source\n\t\tif (!this.#events.hasListeners(eventName)) {\n\t\t\tconst off = this.#disposeSourceListeners.get(eventName);\n\t\t\toff?.();\n\t\t\tthis.#disposeSourceListeners.delete(eventName);\n\t\t}\n\t}\n\n\t#emit(\n\t\teventName: keyof KernelEvents,\n\t\targ?: {\n\t\t\tchangedFields: ReadonlySet<FieldKey>;\n\t\t},\n\t): void {\n\t\tthis.#assertNotDisposed();\n\t\tswitch (eventName) {\n\t\t\tcase \"childrenChangedAfterBatch\":\n\t\t\t\tassert(arg !== undefined, \"childrenChangedAfterBatch should have arg\");\n\t\t\t\treturn this.#handleChildrenChangedAfterBatch(arg.changedFields);\n\t\t\tcase \"subtreeChangedAfterBatch\":\n\t\t\t\treturn this.#handleSubtreeChangedAfterBatch();\n\t\t\tdefault:\n\t\t\t\tunreachableCase(eventName);\n\t\t}\n\t}\n\n\t#handleChildrenChangedAfterBatch(changedFields: ReadonlySet<FieldKey>): void {\n\t\tif (bufferTreeEvents) {\n\t\t\tfor (const fieldKey of changedFields) {\n\t\t\t\tthis.#childrenChangedBuffer.add(fieldKey);\n\t\t\t}\n\t\t} else {\n\t\t\tthis.#events.emit(\"childrenChangedAfterBatch\", { changedFields });\n\t\t}\n\t}\n\n\t#handleSubtreeChangedAfterBatch(): void {\n\t\tif (bufferTreeEvents) {\n\t\t\tthis.#subTreeChangedBuffer = true;\n\t\t} else {\n\t\t\tthis.#events.emit(\"subtreeChangedAfterBatch\");\n\t\t}\n\t}\n\n\t/**\n\t * Flushes any events buffered due to {@link withBufferedTreeEvents}.\n\t */\n\tpublic flush(): void {\n\t\tthis.#assertNotDisposed();\n\n\t\tif (this.#childrenChangedBuffer.size > 0) {\n\t\t\tthis.#events.emit(\"childrenChangedAfterBatch\", {\n\t\t\t\tchangedFields: this.#childrenChangedBuffer,\n\t\t\t});\n\t\t\tthis.#childrenChangedBuffer.clear();\n\t\t}\n\n\t\tif (this.#subTreeChangedBuffer) {\n\t\t\tthis.#events.emit(\"subtreeChangedAfterBatch\");\n\t\t\tthis.#subTreeChangedBuffer = false;\n\t\t}\n\t}\n\n\t#assertNotDisposed(): void {\n\t\tassert(!this.#disposed, \"Event handler disposed.\");\n\t}\n\n\tpublic dispose(): void {\n\t\tif (this.#disposed) {\n\t\t\treturn;\n\t\t}\n\n\t\tassert(\n\t\t\tthis.#childrenChangedBuffer.size === 0 && !this.#subTreeChangedBuffer,\n\t\t\t\"Buffered kernel events should have been flushed before disposing.\",\n\t\t);\n\n\t\tthis.#disposeOnFlushListener();\n\t\tthis.#disposeSourceListeners.forEach((off) => off());\n\t\tthis.#disposeSourceListeners.clear();\n\n\t\tthis.#childrenChangedBuffer.clear();\n\t\tthis.#subTreeChangedBuffer = false;\n\n\t\tthis.#disposed = true;\n\t}\n}\n\n// #endregion\n\n/**\n * For \"cooked\" nodes this is a HydratedFlexTreeNode thats a projection of forest content.\n * For {@link Unhydrated} nodes this is a UnhydratedFlexTreeNode.\n *\n * For \"marinated\" nodes, some code (ex: getOrCreateInnerNode) returns the FlexTreeNode thats a projection of forest content, and some code (ex: tryGetInnerNode) returns undefined.\n */\nexport type InnerNode = FlexTreeNode;\n\n/**\n * Narrows innerNode to either {@link UnhydratedFlexTreeNode} or {@link HydratedFlexTreeNode}.\n */\nexport function splitInnerNodeType(\n\tinnerNode: InnerNode,\n): asserts innerNode is UnhydratedFlexTreeNode | HydratedFlexTreeNode {\n\tassert(\n\t\tinnerNode instanceof UnhydratedFlexTreeNode || innerNode.isHydrated(),\n\t\t0xbc8 /* Invalid inner node type */,\n\t);\n}\n\n/**\n * An anchor slot which associates an anchor with its corresponding {@link TreeNode}, if there is one.\n * @remarks\n * For this to work, we have to require that there is at most a single view using a given AnchorSet.\n * FlexTree already has this assumption, and we also assume there is a single simple-tree per FlexTree, so this is valid.\n */\nexport const simpleTreeNodeSlot = anchorSlot<TreeNode>();\n\n/**\n * Dispose a TreeNode (if any) for an existing anchor without disposing the anchor.\n */\nexport function tryDisposeTreeNode(anchorNode: AnchorNode): void {\n\tconst treeNode = anchorNode.slots.get(simpleTreeNodeSlot);\n\tif (treeNode !== undefined) {\n\t\tconst kernel = getKernel(treeNode);\n\t\tkernel.dispose();\n\t\tanchorNode.slots.delete(simpleTreeNodeSlot);\n\t}\n}\n\n/**\n * Gets the {@link TreeNodeSchema} for the {@link InnerNode}.\n */\nexport function getSimpleNodeSchemaFromInnerNode(innerNode: InnerNode): TreeNodeSchema {\n\tconst context: Context = getSimpleContextFromInnerNode(innerNode);\n\treturn context.schema.get(innerNode.type) ?? fail(0xb3f /* missing schema from context */);\n}\n\n/**\n * Gets the {@link Context} for the {@link InnerNode}.\n */\nexport function getSimpleContextFromInnerNode(innerNode: InnerNode): Context {\n\tsplitInnerNodeType(innerNode);\n\tif (innerNode instanceof UnhydratedFlexTreeNode) {\n\t\treturn innerNode.simpleContext;\n\t}\n\n\tconst context = innerNode.anchorNode.anchorSet.slots.get(SimpleContextSlot);\n\tassert(context !== undefined, 0xa55 /* missing simple tree context */);\n\n\treturn context;\n}\n\n/**\n * Retrieves the flex node associated with the given target.\n * @remarks\n * For {@link Unhydrated} nodes, this returns the MapTreeNode.\n *\n * For hydrated nodes it returns a FlexTreeNode backed by the forest.\n * Note that for \"marinated\" nodes, this FlexTreeNode exists and returns it: it does not return the MapTreeNode which is the current InnerNode.\n *\n * @throws A {@link @fluidframework/telemetry-utils#UsageError} if the node has been deleted.\n */\nexport function getOrCreateInnerNode(treeNode: TreeNode): InnerNode {\n\tconst kernel = getKernel(treeNode);\n\treturn kernel.getOrCreateInnerNode();\n}\n\n/**\n * Gets a flex node from an anchor node\n */\nfunction flexNodeFromAnchor(anchorNode: AnchorNode): HydratedFlexTreeNode {\n\tconst flexNode = anchorNode.slots.get(flexTreeSlot);\n\tif (flexNode !== undefined) {\n\t\treturn flexNode; // If it does have a flex node, return it...\n\t} // ...otherwise, the flex node must be created\n\tconst context =\n\t\tanchorNode.anchorSet.slots.get(ContextSlot) ?? fail(0xb45 /* missing context */);\n\tconst cursor = context.checkout.forest.allocateCursor(\"getFlexNode\");\n\tcontext.checkout.forest.moveCursorToPath(anchorNode, cursor);\n\tconst newFlexNode = getOrCreateHydratedFlexTreeNode(context, cursor);\n\tcursor.free();\n\treturn newFlexNode;\n}\n\n/**\n * Gets a tree node from an anchor node\n */\nexport function treeNodeFromAnchor(anchorNode: AnchorNode): TreeNode | TreeValue {\n\tconst cached = anchorNode.slots.get(simpleTreeNodeSlot);\n\tif (cached !== undefined) {\n\t\treturn cached;\n\t}\n\n\tconst flexNode = flexNodeFromAnchor(anchorNode);\n\treturn createTreeNodeFromInner(flexNode);\n}\n\n/**\n * Constructs a TreeNode from an InnerNode.\n * @remarks\n * This does not do caching or validation: caller must ensure duplicate nodes for a given inner node are not created, and that the inner node is valid.\n */\nexport function createTreeNodeFromInner(innerNode: InnerNode): TreeNode | TreeValue {\n\tconst classSchema = getSimpleNodeSchemaFromInnerNode(innerNode);\n\tconst internal = innerNode as unknown as InternalTreeNode;\n\treturn typeof classSchema === \"function\"\n\t\t? new classSchema(internal)\n\t\t: (classSchema as { create(data: InternalTreeNode): TreeNode | TreeValue }).create(\n\t\t\t\tinternal,\n\t\t\t);\n}\n\n/**\n * Creating multiple simple tree contexts for the same branch, and thus with the same underlying AnchorSet does not work due to how TreeNode caching works.\n * This slot is used to detect if one already exists and error if creating a second.\n * @remarks\n * See also {@link ContextSlot} in which the flex-tree context is stored.\n */\nexport const SimpleContextSlot = anchorSlot<HydratedContext>();\n"]}
|
|
1
|
+
{"version":3,"file":"treeNodeKernel.js","sourceRoot":"","sources":["../../../src/simple-tree/core/treeNodeKernel.ts"],"names":[],"mappings":"AAAA;;;GAGG;;;;;;;;;;;;;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAE7D,OAAO,EACN,MAAM,EACN,IAAI,EACJ,WAAW,EACX,eAAe,GACf,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAEtE,OAAO,EACN,UAAU,GAOV,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,+BAA+B,EAAE,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ributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { createEmitter } from \"@fluid-internal/client-utils\";\nimport type { HasListeners, Listenable, Off } from \"@fluidframework/core-interfaces/internal\";\nimport {\n\tassert,\n\tfail,\n\tdebugAssert,\n\tunreachableCase,\n} from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\tanchorSlot,\n\ttype AnchorEvents,\n\ttype AnchorNode,\n\ttype AnchorSet,\n\ttype FieldKey,\n\ttype TreeValue,\n\ttype UpPath,\n} from \"../../core/index.js\";\nimport { getOrCreateHydratedFlexTreeNode } from \"../../feature-libraries/index.js\";\nimport {\n\tassertFlexTreeEntityNotFreed,\n\tContextSlot,\n\tflexTreeSlot,\n\tLazyEntity,\n\tTreeStatus,\n\ttreeStatusFromAnchorCache,\n\ttype FlexTreeNode,\n\ttype HydratedFlexTreeNode,\n} from \"../../feature-libraries/index.js\";\n\nimport type { Context, HydratedContext } from \"./context.js\";\nimport type { TreeNode } from \"./treeNode.js\";\nimport type { TreeNodeSchema } from \"./treeNodeSchema.js\";\nimport type { InternalTreeNode, Unhydrated } from \"./types.js\";\nimport { UnhydratedFlexTreeNode } from \"./unhydratedFlexTree.js\";\n\nconst treeNodeToKernel = new WeakMap<TreeNode, TreeNodeKernel>();\n\nexport function getKernel(node: TreeNode): TreeNodeKernel {\n\tconst kernel = treeNodeToKernel.get(node);\n\tassert(kernel !== undefined, 0x9b1 /* Expected tree node to have kernel */);\n\treturn kernel;\n}\n\n/**\n * Detects if the given 'candidate' is a TreeNode.\n *\n * @remarks\n * Supports both Hydrated and {@link Unhydrated} TreeNodes, both of which return true.\n *\n * Because the common usage is to check if a value being inserted/set is a TreeNode,\n * this function permits calling with primitives as well as objects.\n *\n * Primitives will always return false (as they are copies of data, not references to nodes).\n *\n * @param candidate - Value which may be a TreeNode\n * @returns true if the given 'candidate' is a hydrated TreeNode.\n */\nexport function isTreeNode(candidate: unknown): candidate is TreeNode | Unhydrated<TreeNode> {\n\treturn treeNodeToKernel.has(candidate as TreeNode);\n}\n\n/**\n * Returns a schema for a value if the value is a {@link TreeNode}.\n *\n * Returns undefined for other values.\n * @remarks\n * Does not give schema for a {@link TreeLeafValue}.\n */\nexport function tryGetTreeNodeSchema(value: unknown): undefined | TreeNodeSchema {\n\tconst kernel = treeNodeToKernel.get(value as TreeNode);\n\treturn kernel?.schema;\n}\n\n/** The {@link HydrationState} of a {@link TreeNodeKernel} before the kernel is hydrated */\ninterface UnhydratedState {\n\treadonly innerNode: UnhydratedFlexTreeNode;\n}\n\n/** The {@link HydrationState} of a {@link TreeNodeKernel} after the kernel is hydrated */\ninterface HydratedState {\n\t/** The flex node for this kernel (lazy - undefined if it has not yet been demanded) */\n\tinnerNode?: FlexTreeNode;\n\t/** The {@link AnchorNode} that this node is associated with. */\n\treadonly anchorNode: AnchorNode;\n\t/** All {@link Off | event deregistration functions} that should be run when the kernel is disposed. */\n\treadonly offAnchorNode: Set<Off>;\n}\n\n/** State within a {@link TreeNodeKernel} that is related to the hydration process */\ntype HydrationState = UnhydratedState | HydratedState;\n\n/** True if and only if the given {@link HydrationState} is post-hydration */\nfunction isHydrated(state: HydrationState): state is HydratedState {\n\treturn (state as Partial<HydratedState>).anchorNode !== undefined;\n}\n\n/**\n * Contains state and an internal API for managing {@link TreeNode}s.\n * @remarks All {@link TreeNode}s have an associated kernel object.\n * The kernel has the same lifetime as the node and spans both its unhydrated and hydrated states.\n */\nexport class TreeNodeKernel {\n\tprivate disposed = false;\n\n\t/**\n\t * Generation number which is incremented any time we have an edit on the node.\n\t * Used during iteration to make sure there has been no edits that were concurrently made.\n\t * @remarks\n\t * This is updated monotonically by this class when edits are applied.\n\t * TODO: update this when applying edits to unhydrated trees.\n\t *\n\t * If TypeScript supported making this immutable from outside the class without making it readonly from inside, that would be used here,\n\t * but they only way to do that is add a separate public accessor and make it private, which was deemed not worth the boilerplate, runtime overhead and bundle size.\n\t */\n\tpublic generationNumber: number = 0;\n\n\t#hydrationState: HydrationState;\n\n\t/**\n\t * Events registered before hydration.\n\t * @remarks\n\t * Since these are usually not used, they are allocated lazily as an optimization.\n\t * The laziness also avoids extra forwarding overhead for events from this kernel's anchor node and also avoids registering for events that are unneeded.\n\t * This means optimizations like skipping processing data in subtrees where no subtreeChanged events are subscribed to would be able to work,\n\t * since the kernel does not unconditionally subscribe to those events (like a design which simply forwards all events would).\n\t */\n\treadonly #eventBuffer: KernelEventBuffer;\n\n\t/**\n\t * Create a TreeNodeKernel which can be looked up with {@link getKernel}.\n\t *\n\t * @param initialContext - context from when this node was originally created. Only used when unhydrated.\n\t * @param innerNode - When unhydrated/raw or marinated the MapTreeNode. FlexTreeNode when cooked.\n\t * @remarks\n\t * Exactly one kernel per TreeNode should be created.\n\t */\n\tpublic constructor(\n\t\tpublic readonly node: TreeNode,\n\t\tpublic readonly schema: TreeNodeSchema,\n\t\tinnerNode: InnerNode,\n\t\tprivate readonly initialContext: Context,\n\t) {\n\t\tsplitInnerNodeType(innerNode);\n\n\t\tassert(!treeNodeToKernel.has(node), 0xa1a /* only one kernel per node can be made */);\n\t\ttreeNodeToKernel.set(node, this);\n\n\t\tif (innerNode instanceof UnhydratedFlexTreeNode) {\n\t\t\t// Unhydrated case\n\n\t\t\tdebugAssert(() => innerNode.treeNode === undefined);\n\t\t\tinnerNode.treeNode = node;\n\n\t\t\tthis.#hydrationState = {\n\t\t\t\tinnerNode,\n\t\t\t};\n\n\t\t\tthis.#eventBuffer = new KernelEventBuffer(innerNode.events);\n\t\t} else {\n\t\t\t// Hydrated case\n\t\t\tthis.#hydrationState = this.createHydratedState(innerNode.anchorNode);\n\t\t\tthis.#hydrationState.innerNode = innerNode;\n\n\t\t\tthis.#eventBuffer = new KernelEventBuffer(innerNode.anchorNode.events);\n\t\t}\n\t}\n\n\tpublic get context(): Context {\n\t\tif (isHydrated(this.#hydrationState)) {\n\t\t\t// This can't be cached on this.#hydrated during hydration since initial tree is hydrated before the context is cached on the anchorSet.\n\t\t\treturn (\n\t\t\t\tthis.#hydrationState?.anchorNode.anchorSet.slots.get(SimpleContextSlot) ??\n\t\t\t\tfail(0xb40 /* missing simple-tree context */)\n\t\t\t);\n\t\t}\n\t\treturn this.initialContext;\n\t}\n\n\t/**\n\t * Transition from {@link Unhydrated} to hydrated.\n\t * Bi-directionally associates the given hydrated TreeNode to the anchor node at the provided path.\n\t * @remarks\n\t * Happens at most once for any given node.\n\t * Cleans up mappings to {@link UnhydratedFlexTreeNode} - it is assumed that they are no longer needed once this node has an anchor node.\n\t */\n\tpublic hydrate(anchors: AnchorSet, path: UpPath): void {\n\t\tassert(!this.disposed, 0xa2a /* cannot hydrate a disposed node */);\n\t\tassert(!isHydrated(this.#hydrationState), 0xa2b /* hydration should only happen once */);\n\n\t\tconst anchor = anchors.track(path);\n\t\tconst anchorNode =\n\t\t\tanchors.locate(anchor) ?? fail(0xb42 /* Expected anchor node to be present */);\n\n\t\tthis.#hydrationState = this.createHydratedState(anchorNode);\n\t\tthis.#hydrationState.offAnchorNode.add(() => anchors.forget(anchor));\n\n\t\t// Lazily migrate existing event listeners to the anchor node\n\t\tthis.#eventBuffer.migrateEventSource(anchorNode.events);\n\t}\n\n\tprivate createHydratedState(anchorNode: AnchorNode): HydratedState {\n\t\tassert(\n\t\t\t!anchorNode.slots.has(simpleTreeNodeSlot),\n\t\t\t0x7f5 /* Cannot associate an flex node with multiple simple-tree nodes */,\n\t\t);\n\t\tanchorNode.slots.set(simpleTreeNodeSlot, this.node);\n\t\treturn {\n\t\t\tanchorNode,\n\t\t\toffAnchorNode: new Set([\n\t\t\t\tanchorNode.events.on(\"afterDestroy\", () => this.dispose()),\n\t\t\t\t// TODO: this should be triggered on change even for unhydrated nodes.\n\t\t\t\tanchorNode.events.on(\"childrenChanging\", () => {\n\t\t\t\t\tthis.generationNumber += 1;\n\t\t\t\t}),\n\t\t\t]),\n\t\t};\n\t}\n\n\tpublic getStatus(): TreeStatus {\n\t\tif (this.disposed) {\n\t\t\treturn TreeStatus.Deleted;\n\t\t}\n\t\tif (!isHydrated(this.#hydrationState)) {\n\t\t\treturn TreeStatus.New;\n\t\t}\n\n\t\t// TODO: Replace this check with the proper check against the cursor state when the cursor becomes part of the kernel\n\t\tconst flex = this.#hydrationState.anchorNode.slots.get(flexTreeSlot);\n\t\tif (flex !== undefined) {\n\t\t\tassert(flex instanceof LazyEntity, 0x9b4 /* Unexpected flex node implementation */);\n\t\t\tif (flex.isFreed()) {\n\t\t\t\treturn TreeStatus.Deleted;\n\t\t\t}\n\t\t}\n\n\t\treturn treeStatusFromAnchorCache(this.#hydrationState.anchorNode);\n\t}\n\n\tpublic get events(): Listenable<KernelEvents> {\n\t\treturn this.#eventBuffer;\n\t}\n\n\tpublic dispose(): void {\n\t\tdebugAssert(() => !this.disposed || \"Cannot dispose a disposed node\");\n\t\tthis.disposed = true;\n\t\tif (isHydrated(this.#hydrationState)) {\n\t\t\tfor (const off of this.#hydrationState.offAnchorNode) {\n\t\t\t\toff();\n\t\t\t}\n\t\t}\n\t\tthis.#eventBuffer.dispose();\n\t\t// TODO: go to the context and remove myself from withAnchors\n\t}\n\n\tpublic isHydrated(): this is { anchorNode: AnchorNode; context: HydratedContext } {\n\t\treturn isHydrated(this.#hydrationState);\n\t}\n\n\tpublic get anchorNode(): AnchorNode | undefined {\n\t\treturn isHydrated(this.#hydrationState) ? this.#hydrationState.anchorNode : undefined;\n\t}\n\n\t/**\n\t * Retrieves the flex node associated with the given target.\n\t * @remarks\n\t * For {@link Unhydrated} nodes, this returns the MapTreeNode.\n\t *\n\t * For hydrated nodes it returns a FlexTreeNode backed by the forest.\n\t * Note that for \"marinated\" nodes, this FlexTreeNode exists and returns it: it does not return the MapTreeNode which is the current InnerNode.\n\t *\n\t * @throws A {@link @fluidframework/telemetry-utils#UsageError} if the node has been deleted.\n\t */\n\tpublic getOrCreateInnerNode(): InnerNode {\n\t\tif (!isHydrated(this.#hydrationState)) {\n\t\t\tdebugAssert(\n\t\t\t\t() =>\n\t\t\t\t\tthis.#hydrationState.innerNode?.context.isDisposed() === false ||\n\t\t\t\t\t\"Unhydrated node should never be disposed\",\n\t\t\t);\n\t\t\treturn this.#hydrationState.innerNode; // Unhydrated case\n\t\t}\n\n\t\tif (this.disposed) {\n\t\t\tthrow new UsageError(\"Cannot access a deleted node.\");\n\t\t}\n\n\t\tif (this.#hydrationState.innerNode === undefined) {\n\t\t\t// Marinated case -> cooked\n\t\t\tconst anchorNode = this.#hydrationState.anchorNode;\n\t\t\t// This TreeNode is bound to an anchor node, but it may or may not have an actual flex node yet\n\t\t\tconst flexNode = anchorNode.slots.get(flexTreeSlot);\n\t\t\tif (flexNode !== undefined) {\n\t\t\t\t// If the flex node already exists, use it...\n\t\t\t\tthis.#hydrationState.innerNode = flexNode;\n\t\t\t} else {\n\t\t\t\t// ...otherwise, the flex node must be created\n\t\t\t\tconst context =\n\t\t\t\t\tanchorNode.anchorSet.slots.get(ContextSlot) ?? fail(0xb41 /* missing context */);\n\t\t\t\tconst cursor = context.checkout.forest.allocateCursor(\"getFlexNode\");\n\t\t\t\tcontext.checkout.forest.moveCursorToPath(anchorNode, cursor);\n\t\t\t\tthis.#hydrationState.innerNode = getOrCreateHydratedFlexTreeNode(context, cursor);\n\t\t\t\tcursor.free();\n\t\t\t\tassertFlexTreeEntityNotFreed(this.#hydrationState.innerNode);\n\t\t\t}\n\t\t}\n\n\t\treturn this.#hydrationState.innerNode;\n\t}\n\n\t/**\n\t * Retrieves the {@link UnhydratedFlexTreeNode} if unhydrated. otherwise undefined.\n\t */\n\tpublic getInnerNodeIfUnhydrated(): UnhydratedFlexTreeNode | undefined {\n\t\tif (isHydrated(this.#hydrationState)) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn this.#hydrationState.innerNode;\n\t}\n}\n\nconst kernelEvents = [\"childrenChangedAfterBatch\", \"subtreeChangedAfterBatch\"] as const;\n\ntype KernelEvents = Pick<AnchorEvents, (typeof kernelEvents)[number]>;\n\n// #region TreeNodeEventBuffer\n\n/**\n * Whether or not events from {@link TreeNodeKernel} should be buffered instead of emitted immediately.\n */\nlet bufferTreeEvents: boolean = false;\n\n/**\n * Call the provided callback with {@link TreeNode}s' events paused until after the callback's completion.\n *\n * Events that would otherwise have been emitted immediately are merged and buffered until after the\n * provided callback has been completed.\n *\n * @remarks\n * Note: this should be used with caution. User application behaviors are implicitly coupled to event timing.\n * Disrupting this timing can lead to unexpected behavior.\n */\nexport function withBufferedTreeEvents(callback: () => void): void {\n\tif (bufferTreeEvents) {\n\t\t// Already buffering - just run the callback\n\t\tcallback();\n\t} else {\n\t\tbufferTreeEvents = true;\n\t\ttry {\n\t\t\tcallback();\n\t\t} finally {\n\t\t\tbufferTreeEvents = false;\n\t\t\tflushEventsEmitter.emit(\"flush\");\n\t\t}\n\t}\n}\n\n/**\n * Event emitter to notify subscribers when tree events buffered due to {@link withBufferedTreeEvents} should be flushed.\n */\nconst flushEventsEmitter = createEmitter<{\n\tflush: () => void;\n}>();\n\n/**\n * Event emitter for {@link TreeNodeKernel}, which optionally buffers events based on {@link bufferTreeEvents}.\n * @remarks Listens to {@link flushEventsEmitter} to know when to flush any buffered events.\n */\nclass KernelEventBuffer implements Listenable<KernelEvents> {\n\t#disposed: boolean = false;\n\n\t/**\n\t * Listen to {@link flushEventsEmitter} to know when to flush buffered events.\n\t */\n\treadonly #disposeOnFlushListener = flushEventsEmitter.on(\"flush\", () => {\n\t\tthis.flush();\n\t});\n\n\treadonly #events = createEmitter<KernelEvents>();\n\n\t#eventSource: Listenable<KernelEvents> & HasListeners<KernelEvents>;\n\t#disposeSourceListeners: Map<keyof KernelEvents, Off> = new Map();\n\n\t/**\n\t * Buffer of fields that have changed since events were paused.\n\t * When events are flushed, a single {@link AnchorEvents.childrenChangedAfterBatch} event will be emitted\n\t * containing the accumulated set of changed fields.\n\t */\n\treadonly #childrenChangedBuffer: Set<FieldKey> = new Set();\n\n\t/**\n\t * Whether or not the subtree has changed since events were paused.\n\t * When events are flushed, a single {@link AnchorEvents.subTreeChanged} event will be emitted if and only\n\t * if the subtree has changed.\n\t */\n\t#subTreeChangedBuffer: boolean = false;\n\n\tpublic constructor(\n\t\t/**\n\t\t * Source of the kernel events.\n\t\t * Subscriptions will be created on-demand when listeners are added to this.events,\n\t\t * and those subscriptions will be cleaned up when all corresponding listeners have been removed.\n\t\t */\n\t\teventSource: Listenable<KernelEvents> & HasListeners<KernelEvents>,\n\t) {\n\t\tthis.#eventSource = eventSource;\n\t}\n\n\t/**\n\t * Migrate this event buffer to a new event source.\n\t *\n\t * @remarks\n\t * Cleans up any existing event subscriptions from the old source.\n\t * Binds events to the new source for each event with active listeners.\n\t */\n\tpublic migrateEventSource(\n\t\tnewSource: Listenable<KernelEvents> & HasListeners<KernelEvents>,\n\t): void {\n\t\t// Unsubscribe from the old source\n\t\tthis.#disposeSourceListeners.forEach((off) => off());\n\t\tthis.#disposeSourceListeners.clear();\n\n\t\tthis.#eventSource = newSource;\n\n\t\tif (this.#events.hasListeners(\"childrenChangedAfterBatch\")) {\n\t\t\tconst off = this.#eventSource.on(\"childrenChangedAfterBatch\", ({ changedFields }) =>\n\t\t\t\tthis.#emit(\"childrenChangedAfterBatch\", { changedFields }),\n\t\t\t);\n\t\t\tthis.#disposeSourceListeners.set(\"childrenChangedAfterBatch\", off);\n\t\t}\n\t\tif (this.#events.hasListeners(\"subtreeChangedAfterBatch\")) {\n\t\t\tconst off = this.#eventSource.on(\"subtreeChangedAfterBatch\", () =>\n\t\t\t\tthis.#emit(\"subtreeChangedAfterBatch\"),\n\t\t\t);\n\t\t\tthis.#disposeSourceListeners.set(\"subtreeChangedAfterBatch\", off);\n\t\t}\n\t}\n\n\tpublic on(eventName: keyof KernelEvents, listener: KernelEvents[typeof eventName]): Off {\n\t\t// Lazily bind event listeners to the source.\n\t\t// If we do not have any existing listeners for this event, then we need to bind to the source.\n\t\tif (!this.#events.hasListeners(eventName)) {\n\t\t\tassert(\n\t\t\t\t!this.#disposeSourceListeners.has(eventName),\n\t\t\t\t0xc4f /* Should not have a dispose function without listeners */,\n\t\t\t);\n\n\t\t\tconst off = this.#eventSource.on(eventName, (args) => this.#emit(eventName, args));\n\t\t\tthis.#disposeSourceListeners.set(eventName, off);\n\t\t}\n\n\t\tthis.#events.on(eventName, listener);\n\t\treturn () => this.off(eventName, listener);\n\t}\n\n\tpublic off(eventName: keyof KernelEvents, listener: KernelEvents[typeof eventName]): void {\n\t\tthis.#events.off(eventName, listener);\n\n\t\t// If there are no remaining listeners for the event, unbind from the source\n\t\tif (!this.#events.hasListeners(eventName)) {\n\t\t\tconst off = this.#disposeSourceListeners.get(eventName);\n\t\t\toff?.();\n\t\t\tthis.#disposeSourceListeners.delete(eventName);\n\t\t}\n\t}\n\n\t#emit(\n\t\teventName: keyof KernelEvents,\n\t\targ?: {\n\t\t\tchangedFields: ReadonlySet<FieldKey>;\n\t\t},\n\t): void {\n\t\tthis.#assertNotDisposed();\n\t\tswitch (eventName) {\n\t\t\tcase \"childrenChangedAfterBatch\":\n\t\t\t\tassert(arg !== undefined, 0xc50 /* childrenChangedAfterBatch should have arg */);\n\t\t\t\treturn this.#handleChildrenChangedAfterBatch(arg.changedFields);\n\t\t\tcase \"subtreeChangedAfterBatch\":\n\t\t\t\treturn this.#handleSubtreeChangedAfterBatch();\n\t\t\tdefault:\n\t\t\t\tunreachableCase(eventName);\n\t\t}\n\t}\n\n\t#handleChildrenChangedAfterBatch(changedFields: ReadonlySet<FieldKey>): void {\n\t\tif (bufferTreeEvents) {\n\t\t\tfor (const fieldKey of changedFields) {\n\t\t\t\tthis.#childrenChangedBuffer.add(fieldKey);\n\t\t\t}\n\t\t} else {\n\t\t\tthis.#events.emit(\"childrenChangedAfterBatch\", { changedFields });\n\t\t}\n\t}\n\n\t#handleSubtreeChangedAfterBatch(): void {\n\t\tif (bufferTreeEvents) {\n\t\t\tthis.#subTreeChangedBuffer = true;\n\t\t} else {\n\t\t\tthis.#events.emit(\"subtreeChangedAfterBatch\");\n\t\t}\n\t}\n\n\t/**\n\t * Flushes any events buffered due to {@link withBufferedTreeEvents}.\n\t */\n\tpublic flush(): void {\n\t\tthis.#assertNotDisposed();\n\n\t\tif (this.#childrenChangedBuffer.size > 0) {\n\t\t\tthis.#events.emit(\"childrenChangedAfterBatch\", {\n\t\t\t\tchangedFields: this.#childrenChangedBuffer,\n\t\t\t});\n\t\t\tthis.#childrenChangedBuffer.clear();\n\t\t}\n\n\t\tif (this.#subTreeChangedBuffer) {\n\t\t\tthis.#events.emit(\"subtreeChangedAfterBatch\");\n\t\t\tthis.#subTreeChangedBuffer = false;\n\t\t}\n\t}\n\n\t#assertNotDisposed(): void {\n\t\tassert(!this.#disposed, 0xc51 /* Event handler disposed. */);\n\t}\n\n\tpublic dispose(): void {\n\t\tif (this.#disposed) {\n\t\t\treturn;\n\t\t}\n\n\t\tassert(\n\t\t\tthis.#childrenChangedBuffer.size === 0 && !this.#subTreeChangedBuffer,\n\t\t\t0xc52 /* Buffered kernel events should have been flushed before disposing. */,\n\t\t);\n\n\t\tthis.#disposeOnFlushListener();\n\t\tthis.#disposeSourceListeners.forEach((off) => off());\n\t\tthis.#disposeSourceListeners.clear();\n\n\t\tthis.#childrenChangedBuffer.clear();\n\t\tthis.#subTreeChangedBuffer = false;\n\n\t\tthis.#disposed = true;\n\t}\n}\n\n// #endregion\n\n/**\n * For \"cooked\" nodes this is a HydratedFlexTreeNode thats a projection of forest content.\n * For {@link Unhydrated} nodes this is a UnhydratedFlexTreeNode.\n *\n * For \"marinated\" nodes, some code (ex: getOrCreateInnerNode) returns the FlexTreeNode thats a projection of forest content, and some code (ex: tryGetInnerNode) returns undefined.\n */\nexport type InnerNode = FlexTreeNode;\n\n/**\n * Narrows innerNode to either {@link UnhydratedFlexTreeNode} or {@link HydratedFlexTreeNode}.\n */\nexport function splitInnerNodeType(\n\tinnerNode: InnerNode,\n): asserts innerNode is UnhydratedFlexTreeNode | HydratedFlexTreeNode {\n\tassert(\n\t\tinnerNode instanceof UnhydratedFlexTreeNode || innerNode.isHydrated(),\n\t\t0xbc8 /* Invalid inner node type */,\n\t);\n}\n\n/**\n * An anchor slot which associates an anchor with its corresponding {@link TreeNode}, if there is one.\n * @remarks\n * For this to work, we have to require that there is at most a single view using a given AnchorSet.\n * FlexTree already has this assumption, and we also assume there is a single simple-tree per FlexTree, so this is valid.\n */\nexport const simpleTreeNodeSlot = anchorSlot<TreeNode>();\n\n/**\n * Dispose a TreeNode (if any) for an existing anchor without disposing the anchor.\n */\nexport function tryDisposeTreeNode(anchorNode: AnchorNode): void {\n\tconst treeNode = anchorNode.slots.get(simpleTreeNodeSlot);\n\tif (treeNode !== undefined) {\n\t\tconst kernel = getKernel(treeNode);\n\t\tkernel.dispose();\n\t\tanchorNode.slots.delete(simpleTreeNodeSlot);\n\t}\n}\n\n/**\n * Gets the {@link TreeNodeSchema} for the {@link InnerNode}.\n */\nexport function getSimpleNodeSchemaFromInnerNode(innerNode: InnerNode): TreeNodeSchema {\n\tconst context: Context = getSimpleContextFromInnerNode(innerNode);\n\treturn context.schema.get(innerNode.type) ?? fail(0xb3f /* missing schema from context */);\n}\n\n/**\n * Gets the {@link Context} for the {@link InnerNode}.\n */\nexport function getSimpleContextFromInnerNode(innerNode: InnerNode): Context {\n\tsplitInnerNodeType(innerNode);\n\tif (innerNode instanceof UnhydratedFlexTreeNode) {\n\t\treturn innerNode.simpleContext;\n\t}\n\n\tconst context = innerNode.anchorNode.anchorSet.slots.get(SimpleContextSlot);\n\tassert(context !== undefined, 0xa55 /* missing simple tree context */);\n\n\treturn context;\n}\n\n/**\n * Retrieves the flex node associated with the given target.\n * @remarks\n * For {@link Unhydrated} nodes, this returns the MapTreeNode.\n *\n * For hydrated nodes it returns a FlexTreeNode backed by the forest.\n * Note that for \"marinated\" nodes, this FlexTreeNode exists and returns it: it does not return the MapTreeNode which is the current InnerNode.\n *\n * @throws A {@link @fluidframework/telemetry-utils#UsageError} if the node has been deleted.\n */\nexport function getOrCreateInnerNode(treeNode: TreeNode): InnerNode {\n\tconst kernel = getKernel(treeNode);\n\treturn kernel.getOrCreateInnerNode();\n}\n\n/**\n * Gets a flex node from an anchor node\n */\nfunction flexNodeFromAnchor(anchorNode: AnchorNode): HydratedFlexTreeNode {\n\tconst flexNode = anchorNode.slots.get(flexTreeSlot);\n\tif (flexNode !== undefined) {\n\t\treturn flexNode; // If it does have a flex node, return it...\n\t} // ...otherwise, the flex node must be created\n\tconst context =\n\t\tanchorNode.anchorSet.slots.get(ContextSlot) ?? fail(0xb45 /* missing context */);\n\tconst cursor = context.checkout.forest.allocateCursor(\"getFlexNode\");\n\tcontext.checkout.forest.moveCursorToPath(anchorNode, cursor);\n\tconst newFlexNode = getOrCreateHydratedFlexTreeNode(context, cursor);\n\tcursor.free();\n\treturn newFlexNode;\n}\n\n/**\n * Gets a tree node from an anchor node\n */\nexport function treeNodeFromAnchor(anchorNode: AnchorNode): TreeNode | TreeValue {\n\tconst cached = anchorNode.slots.get(simpleTreeNodeSlot);\n\tif (cached !== undefined) {\n\t\treturn cached;\n\t}\n\n\tconst flexNode = flexNodeFromAnchor(anchorNode);\n\treturn createTreeNodeFromInner(flexNode);\n}\n\n/**\n * Constructs a TreeNode from an InnerNode.\n * @remarks\n * This does not do caching or validation: caller must ensure duplicate nodes for a given inner node are not created, and that the inner node is valid.\n */\nexport function createTreeNodeFromInner(innerNode: InnerNode): TreeNode | TreeValue {\n\tconst classSchema = getSimpleNodeSchemaFromInnerNode(innerNode);\n\tconst internal = innerNode as unknown as InternalTreeNode;\n\treturn typeof classSchema === \"function\"\n\t\t? new classSchema(internal)\n\t\t: (classSchema as { create(data: InternalTreeNode): TreeNode | TreeValue }).create(\n\t\t\t\tinternal,\n\t\t\t);\n}\n\n/**\n * Creating multiple simple tree contexts for the same branch, and thus with the same underlying AnchorSet does not work due to how TreeNode caching works.\n * This slot is used to detect if one already exists and error if creating a second.\n * @remarks\n * See also {@link ContextSlot} in which the flex-tree context is stored.\n */\nexport const SimpleContextSlot = anchorSlot<HydratedContext>();\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/tree",
|
|
3
|
-
"version": "2.61.0
|
|
3
|
+
"version": "2.61.0",
|
|
4
4
|
"description": "Distributed tree",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -101,17 +101,17 @@
|
|
|
101
101
|
"temp-directory": "nyc/.nyc_output"
|
|
102
102
|
},
|
|
103
103
|
"dependencies": {
|
|
104
|
-
"@fluid-internal/client-utils": "2.61.0
|
|
105
|
-
"@fluidframework/container-runtime": "2.61.0
|
|
106
|
-
"@fluidframework/core-interfaces": "2.61.0
|
|
107
|
-
"@fluidframework/core-utils": "2.61.0
|
|
108
|
-
"@fluidframework/datastore-definitions": "2.61.0
|
|
109
|
-
"@fluidframework/driver-definitions": "2.61.0
|
|
110
|
-
"@fluidframework/id-compressor": "2.61.0
|
|
111
|
-
"@fluidframework/runtime-definitions": "2.61.0
|
|
112
|
-
"@fluidframework/runtime-utils": "2.61.0
|
|
113
|
-
"@fluidframework/shared-object-base": "2.61.0
|
|
114
|
-
"@fluidframework/telemetry-utils": "2.61.0
|
|
104
|
+
"@fluid-internal/client-utils": "~2.61.0",
|
|
105
|
+
"@fluidframework/container-runtime": "~2.61.0",
|
|
106
|
+
"@fluidframework/core-interfaces": "~2.61.0",
|
|
107
|
+
"@fluidframework/core-utils": "~2.61.0",
|
|
108
|
+
"@fluidframework/datastore-definitions": "~2.61.0",
|
|
109
|
+
"@fluidframework/driver-definitions": "~2.61.0",
|
|
110
|
+
"@fluidframework/id-compressor": "~2.61.0",
|
|
111
|
+
"@fluidframework/runtime-definitions": "~2.61.0",
|
|
112
|
+
"@fluidframework/runtime-utils": "~2.61.0",
|
|
113
|
+
"@fluidframework/shared-object-base": "~2.61.0",
|
|
114
|
+
"@fluidframework/telemetry-utils": "~2.61.0",
|
|
115
115
|
"@sinclair/typebox": "^0.34.13",
|
|
116
116
|
"@tylerbu/sorted-btree-es6": "^1.8.0",
|
|
117
117
|
"@types/ungap__structured-clone": "^1.2.0",
|
|
@@ -121,19 +121,19 @@
|
|
|
121
121
|
"devDependencies": {
|
|
122
122
|
"@arethetypeswrong/cli": "^0.17.1",
|
|
123
123
|
"@biomejs/biome": "~1.9.3",
|
|
124
|
-
"@fluid-internal/mocha-test-setup": "2.61.0
|
|
125
|
-
"@fluid-private/stochastic-test-utils": "2.61.0
|
|
126
|
-
"@fluid-private/test-dds-utils": "2.61.0
|
|
127
|
-
"@fluid-private/test-drivers": "2.61.0
|
|
124
|
+
"@fluid-internal/mocha-test-setup": "~2.61.0",
|
|
125
|
+
"@fluid-private/stochastic-test-utils": "~2.61.0",
|
|
126
|
+
"@fluid-private/test-dds-utils": "~2.61.0",
|
|
127
|
+
"@fluid-private/test-drivers": "~2.61.0",
|
|
128
128
|
"@fluid-tools/benchmark": "^0.51.0",
|
|
129
129
|
"@fluid-tools/build-cli": "^0.58.3",
|
|
130
130
|
"@fluidframework/build-common": "^2.0.3",
|
|
131
131
|
"@fluidframework/build-tools": "^0.58.3",
|
|
132
|
-
"@fluidframework/container-definitions": "2.61.0
|
|
133
|
-
"@fluidframework/container-loader": "2.61.0
|
|
132
|
+
"@fluidframework/container-definitions": "~2.61.0",
|
|
133
|
+
"@fluidframework/container-loader": "~2.61.0",
|
|
134
134
|
"@fluidframework/eslint-config-fluid": "^6.0.0",
|
|
135
|
-
"@fluidframework/test-runtime-utils": "2.61.0
|
|
136
|
-
"@fluidframework/test-utils": "2.61.0
|
|
135
|
+
"@fluidframework/test-runtime-utils": "~2.61.0",
|
|
136
|
+
"@fluidframework/test-utils": "~2.61.0",
|
|
137
137
|
"@fluidframework/tree-previous": "npm:@fluidframework/tree@2.60.0",
|
|
138
138
|
"@microsoft/api-extractor": "7.52.11",
|
|
139
139
|
"@types/diff": "^3.5.1",
|
package/src/packageVersion.ts
CHANGED
|
@@ -73,8 +73,8 @@ function createDirtyVisitor(forest: IEditableForest, dirty: DirtyTreeMap): Annou
|
|
|
73
73
|
|
|
74
74
|
return createAnnouncedVisitor({
|
|
75
75
|
beforeDetach: (src) => {
|
|
76
|
-
assert(parent !== undefined,
|
|
77
|
-
assert(parentField !== undefined,
|
|
76
|
+
assert(parent !== undefined, 0xc48 /* Expected node */);
|
|
77
|
+
assert(parentField !== undefined, 0xc49 /* Expected field */);
|
|
78
78
|
for (let parentIndex = src.start; parentIndex < src.end; parentIndex++) {
|
|
79
79
|
const path: UpPath = {
|
|
80
80
|
parent,
|
|
@@ -95,8 +95,8 @@ function createDirtyVisitor(forest: IEditableForest, dirty: DirtyTreeMap): Annou
|
|
|
95
95
|
}
|
|
96
96
|
},
|
|
97
97
|
afterAttach: (_, dst) => {
|
|
98
|
-
assert(parent !== undefined,
|
|
99
|
-
assert(parentField !== undefined,
|
|
98
|
+
assert(parent !== undefined, 0xc4a /* Expected node */);
|
|
99
|
+
assert(parentField !== undefined, 0xc4b /* Expected field */);
|
|
100
100
|
for (let parentIndex = dst.start; parentIndex < dst.end; parentIndex++) {
|
|
101
101
|
const path: UpPath = {
|
|
102
102
|
parent,
|
|
@@ -116,7 +116,7 @@ function createDirtyVisitor(forest: IEditableForest, dirty: DirtyTreeMap): Annou
|
|
|
116
116
|
}
|
|
117
117
|
},
|
|
118
118
|
enterNode(index: number): void {
|
|
119
|
-
assert(parentField !== undefined,
|
|
119
|
+
assert(parentField !== undefined, 0xc4c /* Expected field */);
|
|
120
120
|
parent = {
|
|
121
121
|
parent,
|
|
122
122
|
parentField,
|
|
@@ -125,7 +125,7 @@ function createDirtyVisitor(forest: IEditableForest, dirty: DirtyTreeMap): Annou
|
|
|
125
125
|
parentField = undefined;
|
|
126
126
|
},
|
|
127
127
|
exitNode(): void {
|
|
128
|
-
assert(parent !== undefined,
|
|
128
|
+
assert(parent !== undefined, 0xc4d /* Expected node */);
|
|
129
129
|
parentField = parent.parentField;
|
|
130
130
|
parent = parent.parent;
|
|
131
131
|
},
|
|
@@ -141,7 +141,7 @@ function createDirtyVisitor(forest: IEditableForest, dirty: DirtyTreeMap): Annou
|
|
|
141
141
|
function getNodeAtPath(forest: IEditableForest, path: UpPath): TreeNode | undefined {
|
|
142
142
|
const cursor = forest.allocateCursor();
|
|
143
143
|
forest.moveCursorToPath(path, cursor);
|
|
144
|
-
assert(cursor.mode === CursorLocationType.Nodes,
|
|
144
|
+
assert(cursor.mode === CursorLocationType.Nodes, 0xc4e /* attach should happen in a node */);
|
|
145
145
|
const anchor = cursor.buildAnchor();
|
|
146
146
|
const anchorNode = forest.anchors.locate(anchor);
|
|
147
147
|
cursor.free();
|
|
@@ -448,7 +448,7 @@ class KernelEventBuffer implements Listenable<KernelEvents> {
|
|
|
448
448
|
if (!this.#events.hasListeners(eventName)) {
|
|
449
449
|
assert(
|
|
450
450
|
!this.#disposeSourceListeners.has(eventName),
|
|
451
|
-
|
|
451
|
+
0xc4f /* Should not have a dispose function without listeners */,
|
|
452
452
|
);
|
|
453
453
|
|
|
454
454
|
const off = this.#eventSource.on(eventName, (args) => this.#emit(eventName, args));
|
|
@@ -479,7 +479,7 @@ class KernelEventBuffer implements Listenable<KernelEvents> {
|
|
|
479
479
|
this.#assertNotDisposed();
|
|
480
480
|
switch (eventName) {
|
|
481
481
|
case "childrenChangedAfterBatch":
|
|
482
|
-
assert(arg !== undefined,
|
|
482
|
+
assert(arg !== undefined, 0xc50 /* childrenChangedAfterBatch should have arg */);
|
|
483
483
|
return this.#handleChildrenChangedAfterBatch(arg.changedFields);
|
|
484
484
|
case "subtreeChangedAfterBatch":
|
|
485
485
|
return this.#handleSubtreeChangedAfterBatch();
|
|
@@ -526,7 +526,7 @@ class KernelEventBuffer implements Listenable<KernelEvents> {
|
|
|
526
526
|
}
|
|
527
527
|
|
|
528
528
|
#assertNotDisposed(): void {
|
|
529
|
-
assert(!this.#disposed,
|
|
529
|
+
assert(!this.#disposed, 0xc51 /* Event handler disposed. */);
|
|
530
530
|
}
|
|
531
531
|
|
|
532
532
|
public dispose(): void {
|
|
@@ -536,7 +536,7 @@ class KernelEventBuffer implements Listenable<KernelEvents> {
|
|
|
536
536
|
|
|
537
537
|
assert(
|
|
538
538
|
this.#childrenChangedBuffer.size === 0 && !this.#subTreeChangedBuffer,
|
|
539
|
-
|
|
539
|
+
0xc52 /* Buffered kernel events should have been flushed before disposing. */,
|
|
540
540
|
);
|
|
541
541
|
|
|
542
542
|
this.#disposeOnFlushListener();
|