-
Notifications
You must be signed in to change notification settings - Fork 535
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/microsoft/FluidFramework in…
…to vermadhr/keylessAccessWork
- Loading branch information
Showing
99 changed files
with
1,032 additions
and
860 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,44 @@ | ||
--- | ||
title: Events | ||
sidebar_position: 5 | ||
--- | ||
|
||
`SharedTree` supports two node level events: `nodeChanged` and `treeChanged`. | ||
|
||
Additionally, the `TreeView` object includes 2 events that operate over the whole tree. | ||
These are `rootChanged` and `commitApplied`. | ||
|
||
`rootChanged` fires when the root field (the field that contains the root node) changes. | ||
That is, if a new root node is assigned or the schema changes. | ||
This will not fire when the node itself changes. | ||
|
||
`changed` fires whenever a change is applied outside of a transaction or when a transaction is committed. | ||
This is used to get `Revertible` objects to put on the undo or redo stacks. | ||
See [undo redo support](./undo-redo.mdx) and [Transactions](./transactions.mdx). | ||
|
||
## Event Handling | ||
|
||
```typescript | ||
on<K extends keyof TreeChangeEvents>( | ||
node: TreeNode, | ||
eventName: K, | ||
listener: TreeChangeEvents[K], | ||
): () => void; | ||
``` | ||
|
||
`Tree.on` assigns the specified `listener` function to the specified `eventName` for the specified `node`. | ||
The `node` can be any node of the tree. | ||
The `eventName` can be either "treeChanged" or "nodeChanged". | ||
`nodeChanged` fires whenever one or more properties of the specified node change. | ||
`treeChanged` fires whenever one or more properties of the specified node or any node in its subtree, change. | ||
We recommend looking at the documentation of each of the events for more details. | ||
|
||
The `Tree.on()` method returns a function that unsubscribes the handler from the event. This method is typically called in clean up code when the node is being removed. For example: | ||
|
||
```typescript | ||
const unsubscribe = Tree.on(myTreeNode, "nodeChanged", () => {...}); | ||
|
||
// Later at some point when the event subscription is not needed anymore | ||
unsubscribe(); | ||
|
||
``` |
Oops, something went wrong.