Skip to main content

TreeChangeEvents Interface

A collection of events that can be emitted by a TreeNode.

Signature

/** @sealed */
export interface TreeChangeEvents

Methods

Method Return Type Description
nodeChanged(unstable) void

Emitted by a node after a batch of changes has been applied to the tree, if any of the changes affected the node.

- Object nodes define a change as being when the value of one of its properties changes (i.e., the property's value is set, including when set to undefined).

- Array nodes define a change as when an element is added, removed, moved or replaced.

- Map nodes define a change as when an entry is added, updated, or removed.

treeChanged() void Emitted by a node after a batch of changes has been applied to the tree, when something changed anywhere in the subtree rooted at it.

Method Details

nodeChanged

Emitted by a node after a batch of changes has been applied to the tree, if any of the changes affected the node.

  • Object nodes define a change as being when the value of one of its properties changes (i.e., the property's value is set, including when set to undefined).

  • Array nodes define a change as when an element is added, removed, moved or replaced.

  • Map nodes define a change as when an entry is added, updated, or removed.

Signature

nodeChanged(unstable?: unknown): void;

Remarks

This event is not emitted when:

  • Properties of a child node change. Notably, updates to an array node or a map node (like adding or removing elements/entries) will emit this event on the array/map node itself, but not on the node that contains the array/map node as one of its properties.

  • The node is moved to a different location in the tree or removed from the tree. In this case the event is emitted on the _parent_ node, not the node itself.

For remote edits, this event is not guaranteed to occur in the same order or quantity that it did in the client that made the original edit.

When the event is emitted, the tree is guaranteed to be in-schema.

Parameters

Parameter Modifiers Type Description
unstable optional unknown Future versions of this API (such as the one in beta on TreeBeta) may use this argument to provide additional data to the event. users of this event should ensure that they do not provide a listener callback which has an optional parameter in this position, since unexpected data might get provided to it. This parameter exists to capture this fact in the type system. Using an inline lambda expression as the listener callback is a good pattern to avoid cases like this were arguments are added from breaking due to optional arguments.

treeChanged

Emitted by a node after a batch of changes has been applied to the tree, when something changed anywhere in the subtree rooted at it.

Signature

treeChanged(): void;

Remarks

This event is not emitted when the node itself is moved to a different location in the tree or removed from the tree. In that case it is emitted on the _parent_ node, not the node itself.

The node itself is part of the subtree, so this event will be emitted even if the only changes are to the properties of the node itself.

For remote edits, this event is not guaranteed to occur in the same order or quantity that it did in the client that made the original edit.

When it is emitted, the tree is guaranteed to be in-schema.