SheetXL - v0.8.0-beta.9+sites.210.e2d420901
    Preparing search index...

    Interface ITransaction

    Objects that implement this interface have ACID properties.

    interface ITransaction {
        isITransaction: true;
        amend<P = any>(options?: StoreOperationOptions<P>): ITransaction;
        beginTransaction(
            options?: StoreOperationOptions<any>,
            onClose?: CloseCallback,
        ): ITransaction;
        commit<P = any>(options?: StoreOperationOptions<P>): ITransaction;
        getDepth(): number;
        getDescription(): string;
        getId(): string;
        getIntent<T = any>(key: string): T | undefined;
        getOperation(): Readonly<Operation<any>> | null;
        getParent(): ITransaction;
        getSavepointId(): string;
        getState<STATE = any>(stateId: string): Readonly<STATE>;
        getStates(): Map<string, any>;
        rollback(): ITransaction;
        setIntent<T = any>(
            key: string,
            value: T | ((prev: T | undefined) => T),
        ): void;
        updateState<STATE = any>(
            stateId: string,
            state:
                | Readonly<Partial<STATE>>
                | ((prev: Readonly<STATE>) => Readonly<STATE>),
        ): STATE;
    }
    Index
    isITransaction: true

    For runtime type checking.

    • Close the transaction by folding its writes into the commit it opened on, rather than adding a step to the history.

      Type Parameters

      • P = any

      Parameters

      Returns ITransaction

      The same fold as IStore.amend, which names the commit it lands in; this one always lands in the commit this transaction began from. Reach for IStore.amend when the writes belong to a commit you can name - what a calculation produced, where a listener registered - and this when they belong to wherever you started: a model folding its own initialization into the load it is happening during.

      Either way the writes add no undo entry and no audit of their own; they are undone with the commit they land in. On a nested transaction there is nothing to fold into and this is commit: the writes join the operation that is open, which is already not a step of their own.

    • Begin a transaction with self contained, non-eventing updates.

      Parameters

      • Optionaloptions: StoreOperationOptions<any>

        The description of the transaction or options.

      • OptionalonClose: CloseCallback

        A callback for when the transaction is closed (due to either a commit or rollback).

      Returns ITransaction

      description is useful for debugging and logging.

      Transactions are treated as a stack so with fifo remove. When the final commit is applied to global only the final transaction will be maintained.

    • 0-Based depth of the current transaction. If 0 then it's globally available.

      Returns number

    • Describes the current transaction.

      Returns string

    • A unique id for this transaction. This will be the same id for all sub transactions.

      Returns string

    • Reads an intent recorded on the root of this transaction.

      Type Parameters

      • T = any

      Parameters

      • key: string

        Names the intent. Owned by whoever records it.

      Returns T | undefined

    • The operation this transaction was begun for (ITransaction.StoreOperationOptions.operation), or null when it was begun without one.

      Returns Readonly<Operation<any>> | null

      Its own, not its root's: a transaction nested in an operation that did not name one of its own returns null. See ICommit.getOperation for the operation a commit records.

    • Identifies what a rollback of this transaction undoes on its own.

      Returns string

      A root's is its id. A nested transaction has one of its own, unless it was begun as a step of the one it is nested in (ITransaction.StoreOperationOptions.savepoint). It is the key for a copy-on-write structure that is changed in place: a copy taken under one savepoint is not reachable from a state that outlives that savepoint's rollback.

    • Returns the state associated to a record for the current transaction or globally if there are no open transactions.

      Type Parameters

      • STATE = any

      Parameters

      Returns Readonly<STATE>

    • All states in the current transaction, keyed by stateId.

      Returns Map<string, any>

    • Records an intent on the root of this transaction: something to do once the operation completes, rather than a change to the state.

      Type Parameters

      • T = any

      Parameters

      • key: string

        Names the intent. Owned by whoever records it.

      • value: T | ((prev: T | undefined) => T)

        The intent, or a function of the intent currently recorded under key.

      Returns void

      An intent is data - coords, ids and strings, never a model or a view. It is recorded on the root, so every nested transaction of an operation writes the same bag and a batch of N operations resolves one set of intents rather than N. It travels on the commit (ICommit.getIntents) and so is available again on undo and redo.

      The store gives a key no meaning and no merge rule beyond last-write-wins. An intent that accumulates - a union of ranges, say - passes a function and merges its own way. The write is kept, so an amend replays it onto the commit it folds into: the accumulating writer runs a second time, handed the TARGET's value, and the union spans both. What this transaction itself holds under the key stays its own contribution, which is what it announces. A writer must therefore produce a new value rather than mutate the one it is handed.

    • Update the state for a record.

      Type Parameters

      • STATE = any

      Parameters

      • stateId: string

        The store-issued record id (ITransaction.IStore.create).

      • state: Readonly<Partial<STATE>> | ((prev: Readonly<STATE>) => Readonly<STATE>)

        A partial to merge, or a function of the previous state. Returning the previous state unchanged records nothing (a batch of such calls elides).

      Returns STATE