Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/microsoft/FluidFramework in…
Browse files Browse the repository at this point in the history
…to vermadhr/keylessAccessWork
  • Loading branch information
dhr-verma committed Dec 30, 2024
2 parents b73ae27 + 0630c39 commit fb06ce9
Show file tree
Hide file tree
Showing 99 changed files with 1,032 additions and 860 deletions.
2 changes: 1 addition & 1 deletion azure/packages/test/scenario-runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"@fluidframework/build-tools": "^0.51.0",
"@fluidframework/eslint-config-fluid": "^5.6.0",
"@types/js-yaml": "^4.0.5",
"@types/mocha": "^9.1.1",
"@types/mocha": "^10.0.10",
"@types/nock": "^9.3.0",
"@types/node": "^18.19.0",
"@types/sinon": "^17.0.3",
Expand Down
2 changes: 1 addition & 1 deletion common/lib/common-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"@types/benchmark": "^2.1.0",
"@types/jest": "29.5.3",
"@types/jest-environment-puppeteer": "2.2.0",
"@types/mocha": "^9.1.1",
"@types/mocha": "^10.0.10",
"@types/node": "^18.19.39",
"@types/sinon": "^17.0.3",
"benchmark": "^2.1.4",
Expand Down
8 changes: 4 additions & 4 deletions common/lib/common-utils/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions docs/docs/data-structures/tree/events.mdx
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();

```
Loading

0 comments on commit fb06ce9

Please sign in to comment.