-
Notifications
You must be signed in to change notification settings - Fork 532
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Emit events from Unhydrated SharedTree Nodes (#22661)
## Description Currently, unhydrated nodes can be edited but they do not emit any change events. This PR fixes that by properly emitting events. Changes include: * Removing the `anchor` parameter from the relevant events on `AnchorEvents`. This allows those events to be implemented by things that don't have anchors (like `UnhydratedFlexTreeNode`) and things that only sometimes have anchors (like `TreeNodeKernel`). Nobody uses that parameter currently anyway because it is redundant (it's the same as the object that the event is being registered on). * Emitting a change event from `UnhydratedFlexTreeNode` when one of its fields is edited. This is listened to by the `TreeNodeKernel`, which can then emit its own corresponding event. * Adding distinct types for the "unhydrated" and "hydrated" versions of the state in `TreeNodeKernel`. This makes it more obvious what the state transition is, and makes the type checking and safety more explicit. * Adding a `lazy` function helper to better encapsulate the lazy-getting of the events in TreeNodeKernel.
- Loading branch information
Showing
7 changed files
with
202 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
"@fluidframework/tree": minor | ||
--- | ||
--- | ||
"section": tree | ||
--- | ||
|
||
Unhydrated SharedTree nodes emit change events when edited | ||
|
||
Newly-created SharedTree nodes which have not yet been inserted into the tree will now emit `nodeChanged` and `treeChanged` events when they are mutated via editing operations. | ||
|
||
```ts | ||
const node = new Foo({ foo: 3 }); | ||
Tree.on(node, "nodeChanged", () => { | ||
console.log("This will fire even before node is inserted!"); | ||
}); | ||
|
||
node.foo = 4; // log: "This will fire even before node is inserted!"; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.