Transaction Class
Buffers changes to be applied to an isolated view of a SharedTree
over time before applying them directly to the tree itself as a single edit
Signature
export declare class Transaction extends TypedEventEmitter<TransactionEvents>
Extends: TypedEventEmitter<TransactionEvents
Constructors
Constructor | Description |
---|---|
(constructor)(tree) | Create a new transaction over the given tree. The tree's currentView at this time will become the startingView for this transaction. |
Properties
Property | Type | Description |
---|---|---|
currentView | TreeView | The state of the tree following the most change that was successfully applied. If no changes have been applied, this is the same as startingView . |
isOpen | boolean | True if this transaction is open, false if it is closed. A transaction may be closed manually via closeAndApplyEdit() , or may be automatically closed by a change in this transaction failing to apply (see applyChange() ). |
startingView | TreeView | The view of the tree when this transaction was created |
status | EditStatus | The status of the most recently applied change in this transaction |
tree | SharedTree |
Methods
Method | Return Type | Description |
---|---|---|
apply(changes) | EditStatus | Attempt to apply a sequence of changes in this transaction. The currentView will be updated to reflect the new tree state after all applied changes. If any change fails to apply, the remaining changes will be ignored and this transaction will be automatically closed (see isOpen ). If this transaction is already closed, this method has no effect. This method will emit a TransactionEvent.ViewChange event at most once per call. |
apply(changes) | EditStatus | |
closeAndCommit() | void | Close this transaction and apply its changes to the SharedTree . If this transaction is already closed, this method has no effect. |
Constructor Details
(constructor)
Create a new transaction over the given tree. The tree's currentView
at this time will become the startingView
for this transaction.
Signature
constructor(tree: SharedTree);
Parameters
Parameter | Type | Description |
---|---|---|
tree | SharedTree | the SharedTree that this transaction applies changes to |
Property Details
currentView
The state of the tree following the most change that was successfully applied. If no changes have been applied, this is the same as startingView
.
Signature
get currentView(): TreeView;
Type: TreeView
isOpen
True if this transaction is open, false if it is closed. A transaction may be closed manually via closeAndApplyEdit()
, or may be automatically closed by a change in this transaction failing to apply (see applyChange()
).
Signature
get isOpen(): boolean;
Type: boolean
startingView
The view of the tree when this transaction was created
Signature
readonly startingView: TreeView;
Type: TreeView
status
The status of the most recently applied change in this transaction
Signature
get status(): EditStatus;
Type: EditStatus
tree
Signature
readonly tree: SharedTree;
Type: SharedTree
Method Details
apply
Attempt to apply a sequence of changes in this transaction. The currentView
will be updated to reflect the new tree state after all applied changes. If any change fails to apply, the remaining changes will be ignored and this transaction will be automatically closed (see isOpen
). If this transaction is already closed, this method has no effect. This method will emit a TransactionEvent.ViewChange
event at most once per call.
Signature
apply(...changes: Change[]): EditStatus;
Parameters
Parameter | Type | Description |
---|---|---|
changes | Change[] | the changes to apply |
Returns
either the EditStatus
of the given changes or the EditStatus
of the last change before the transaction was closed
Return type: EditStatus
apply
Signature
apply(changes: Change[]): EditStatus;
Parameters
Parameter | Type | Description |
---|---|---|
changes | Change[] |
Returns
Return type: EditStatus
closeAndCommit
Close this transaction and apply its changes to the SharedTree
. If this transaction is already closed, this method has no effect.
Signature
closeAndCommit(): void;