GenericTransactionPolicy Interface
An object that encapsulates the rules and state pertaining to a specific subclass of GenericTransaction. The characteristics that define such a subclass (and an implementation of this interface) are: - The type of change that can be applied - How those changes impact the state of the tree - How those changes are resolved in the face of concurrent changes - What makes a transaction valid - The kind of situations that might lead to a transaction failure
Instances of this type are passed to the GenericTransaction constructor.
Signature
export interface GenericTransactionPolicy
Methods
Method | Return Type | Description |
---|---|---|
dispatchChange(state, change) | ChangeResult | Provides a new state given the current state and a change to apply. |
tryResolveChange(state, change, path) | Result<ChangeInternal, TransactionFailure> | Given a change, attempts to derive an equivalent change which can be applied to the current state even if the given change was issued over a different state. This can be used to apply a sequence of changes that were issued concurrently, i.e., without knowledge of each other. |
validateOnClose(state) | ChangeResult | Additional transaction validation when the transaction is closed. |
Method Details
dispatchChange
Provides a new state given the current state and a change to apply.
Signature
dispatchChange(state: SucceedingTransactionState, change: ChangeInternal): ChangeResult;
Parameters
Parameter | Type | Description |
---|---|---|
state | SucceedingTransactionState | The current state on which the change is applied. |
change | ChangeInternal | The change to apply to the current state. |
Returns
The new state reflecting the applied change, or a failure.
Return type: ChangeResult
tryResolveChange
Given a change, attempts to derive an equivalent change which can be applied to the current state even if the given change was issued over a different state. This can be used to apply a sequence of changes that were issued concurrently, i.e., without knowledge of each other.
Signature
tryResolveChange(state: SucceedingTransactionState, change: ChangeInternal, path: ReconciliationPath): Result<ChangeInternal, TransactionFailure>;
Parameters
Parameter | Type | Description |
---|---|---|
state | SucceedingTransactionState | The current state on which the returned change will be applied. |
change | ChangeInternal | The original change issued. |
path | ReconciliationPath | The reconciliation path for the change. |
Returns
The change to be applied to the current state, or a failure if the change cannot be resolved.
Return type: Result<ChangeInternal, TransactionFailure>
validateOnClose
Additional transaction validation when the transaction is closed.
Signature
validateOnClose(state: SucceedingTransactionState): ChangeResult;
Parameters
Parameter | Type | Description |
---|---|---|
state | SucceedingTransactionState | The current state of the transaction. |
Returns
The new state reflecting the closed transaction, or a failure if the transaction cannot be closed.
Return type: ChangeResult