Skip to main content

TreeContextAlpha Interface

Provides additional APIs that may be used to interact with a tree node or a tree node's SharedTree.

This API is provided as an alpha preview and may change without notice.

To use, import via @fluidframework/tree/alpha.

For more information about our API support guarantees, see here.

Signature​

export interface TreeContextAlpha

Methods​

MethodAlertsReturn TypeDescription
isBranch()Deprecated, Alphathis is UntypedTreeViewAlphaTrue if this context is associated with an untyped view and false if it is associated with an unhydrated node.
isView()Alphathis is UntypedTreeViewAlphaTrue if this context is associated with an untyped view and false if it is associated with an unhydrated node.
runTransaction(transaction, params)AlphaTransactionValueResult<TValue, TValue>Run a synchronous transaction which groups sequential edits to the tree into a single atomic edit if possible.
runTransaction(transaction, params)AlphaTransactionVoidResultAn overload of runTransaction which does not return a value.
runTransactionAsync(transaction, params)AlphaPromise<TransactionValueResult<TValue, TValue>>An asynchronous version of runTransaction.
runTransactionAsync(transaction, params)AlphaPromise<TransactionVoidResult>An overload of runTransactionAsync which does not return a value.

Method Details​

isBranch​

True if this context is associated with an untyped view and false if it is associated with an unhydrated node.

This API is deprecated and will be removed in a future release.

Use isView() instead.

This API is provided as an alpha preview and may change without notice.

For more information about our API support guarantees, see here.

Signature​

isBranch(): this is UntypedTreeViewAlpha;

Remarks​

If this returns true, the context can be safely inferred or cast to UntypedTreeViewAlpha to access additional view-specific APIs.

Returns​

Whether this context is associated with an untyped view.

Return type: this is UntypedTreeViewAlpha

isView​

True if this context is associated with an untyped view and false if it is associated with an unhydrated node.

This API is provided as an alpha preview and may change without notice.

For more information about our API support guarantees, see here.

Signature​

isView(): this is UntypedTreeViewAlpha;

Remarks​

If this returns true, the context can be safely inferred or cast to UntypedTreeViewAlpha to access additional view-specific APIs.

Example​

const context = tree.context(someNode);
if (context.isView()) {
assert(context.hasRootSchema(MySchema)) // `hasRootSchema` is a method on UntypedTreeViewAlpha, so this is only accessible if `context` is a view context.
context.root.foo = "bar"; // Edit the root of the SharedTree that `someNode` belongs to.
}

Returns​

Whether this context is associated with an untyped view.

Return type: this is UntypedTreeViewAlpha

runTransaction​

Run a synchronous transaction which groups sequential edits to the tree into a single atomic edit if possible.

This API is provided as an alpha preview and may change without notice.

For more information about our API support guarantees, see here.

Signature​

runTransaction<TValue>(transaction: () => WithValue<TValue>, params?: RunTransactionParamsAlpha): TransactionValueResult<TValue, TValue>;
Type Parameters​
ParameterDescription
TValue

Remarks​

All of the changes in the transaction are applied synchronously and therefore no other changes from a remote client can be interleaved with those changes. Note that this is guaranteed by Fluid for any sequence of changes that are submitted synchronously, whether in a transaction or not.

Change events will be emitted for changed nodes on this client _as each edit happens_, just as they would be if the changes were made outside of a transaction. Any other/future clients or contexts will process the transaction "squashed", i.e. they will apply its changes all at once, emitting only a single event per node (even if that node was edited multiple times in the transaction). Edits to the tree are not permitted within these event callbacks, therefore no other local changes from this client will be interleaved with the changes in this transaction.

Using a transaction has the following additional consequences:

  • If reverted (e.g. via an "undo" operation), all the changes in the transaction are reverted together. Only the "outermost" transaction commits a change to the synchronized tree state and therefore only the outermost transaction can be reverted. If a transaction is started and completed while another transaction is already in progress, then the inner transaction will be reverted together with the outer transaction. - The internal data representation of a transaction with many changes is generally smaller and more efficient than that of the changes when separate.

runTransaction may be invoked on the context of a hydrated or unhydrated node. Use isView() to check whether this context is associated with a view and gain access to more transaction capabilities if so.

Parameters​

ParameterModifiersTypeDescription
transaction() => WithValue<TValue>A callback run during the transaction to perform user-supplied operations. It may optionally return a value, which will be returned by the runTransaction call.
paramsoptionalRunTransactionParamsAlphaOptional parameters for the transaction.

Returns​

A value indicating whether or not the transaction succeeded, and containing the value returned by transaction.

Return type: TransactionValueResult<TValue, TValue>

runTransaction​

An overload of runTransaction which does not return a value.

This API is provided as an alpha preview and may change without notice.

For more information about our API support guarantees, see here.

Signature​

runTransaction(transaction: () => void, params?: RunTransactionParamsAlpha): TransactionVoidResult;

Parameters​

ParameterModifiersTypeDescription
transaction() => void
paramsoptionalRunTransactionParamsAlpha

Returns​

Return type: TransactionVoidResult

runTransactionAsync​

An asynchronous version of runTransaction.

This API is provided as an alpha preview and may change without notice.

For more information about our API support guarantees, see here.

Signature​

runTransactionAsync<TValue>(transaction: () => Promise<WithValue<TValue>>, params?: RunTransactionParamsAlpha): Promise<TransactionValueResult<TValue, TValue>>;
Type Parameters​
ParameterDescription
TValue

Remarks​

As with synchronous transactions, all of the changes in an asynchronous transaction are treated as a unit. Therefore, no other changes (either from this client or from a remote client) can be interleaved with the transaction changes.

Unlike with synchronous transactions, it is possible that other changes (e.g. from a remote client) may be applied to the branch while this transaction is in progress. Those other changes will be not be reflected on the branch until after this transaction completes, at which point the transaction changes will be applied after those other changes.

An asynchronous transaction may not be started while any other transaction is in progress in this context.

Parameters​

ParameterModifiersTypeDescription
transaction() => Promise<WithValue<TValue>>
paramsoptionalRunTransactionParamsAlpha

Returns​

Return type: Promise<TransactionValueResult<TValue, TValue>>

runTransactionAsync​

An overload of runTransactionAsync which does not return a value.

This API is provided as an alpha preview and may change without notice.

For more information about our API support guarantees, see here.

Signature​

runTransactionAsync(transaction: () => Promise<void>, params?: RunTransactionParamsAlpha): Promise<TransactionVoidResult>;

Parameters​

ParameterModifiersTypeDescription
transaction() => Promise<void>
paramsoptionalRunTransactionParamsAlpha

Returns​

Return type: Promise<TransactionVoidResult>