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

    Class TransactionStore

    Events are never fired on sub transactions. Only when making changes to the root either directly or through a final commit. Any models that want to fire non transactional events should do this directly.

    Implements

    Index
    • Parameters

      • event: "onCommitStart" | "onCommitEnd" | "onAmendEnd" | "onCommitChange"
      • commit: ICommit
      • async: boolean = false

      Returns void | Promise<any>

    • Parameters

      • event: keyof IStateListener<any>
      • container: CommitContainer
      • states: Map<any, any>
      • isRevert: boolean = false
      • isRestore: boolean = false
      • async: boolean = false
      • source: CommitContainer = container

      Returns void

    • Fold a set of writes into an existing commit, by id, without a log entry.

      Type Parameters

      • R

      Parameters

      • commitId: string

        The commit the writes belong to.

      • callback: (commit: ICommit) => R

        Performs the writes, handed the commit they fold into (its intents are what an amend reads). Runs synchronously; whatever it commits joins the target rather than becoming a commit of its own.

      Returns R

      An amend is how derived data lands: what a calculation produced for a commit, or a listener registration that must never read as an edit. It is not a step in the history:

      • it adds no commit and fires no IListeners.onCommitChange / IListeners.onCommitEnd, so the undo manager never sees it;
      • it leaves the tip where it is and prunes no redo branch, so it may target a commit the store has been restored to;
      • its intent writes are replayed onto the target, so an undo of that commit replays them and an accumulating ITransaction.setIntent writer unions with what the target already held;
      • state listeners are told what the amend recorded, not what the target holds.

      The writes read from and land in the named commit's own snapshot, whichever commit the store is at, and later snapshots are not touched: a later commit answers for its own writes. That is the fold for a result computed against a snapshot, a calculation's answer to a request made at that commit. A target that is not the current commit notifies no state listener; the current state did not change. A target the store no longer has folds into the current commit. Called while a transaction is open, the callback runs inside it and its writes land wherever that operation's commit does: an amend cannot re-target an operation in progress.

    • Create a record, minting its stable state id. The opposite of remove.

      Type Parameters

      • STATE = any

      Parameters

      • Optionalinitial: Readonly<STATE>

        The initial state to seed, if any.

      Returns string

      The store-issued state id — the model's identity (ITransactional.getId) and the key for every other store operation.

      When initial is provided, creation is a write: it joins an open transaction (or commits one), so undo/restore naturally un-creates — the prior snapshot simply has no record. With no initial this only mints the id; the record exists once first written.

    • Returns the total number of commits.

      Returns number

    • Returns the current commit.

      Parameters

      • includePending: boolean = true

        If false, always the last completed commit — a stable log id even while a transaction is open. default true.

      Returns ICommit

      Returns either the last completed commit or the current pending.

    • Returns the last commits of commits.

      Parameters

      • commitId: string

        The commit id to start from.

      • max: number = 100

        The maximum number of commits to return. default 100.

      Returns ICommit[]

    • The root transaction of the operation that is open.

      Returns ITransaction | null

      null if none is. What it is for is reaching the operation from outside the call that began it - a model asked to record an intent on whatever is open rather than being handed the transaction. Writes made through it join that operation.

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

      Type Parameters

      • STATE = any

      Parameters

      • stateId: string

        The store-issued record id (create).

      Returns Readonly<STATE>

    • Returns the state a record held as of a commit.

      Type Parameters

      • STATE = any

      Parameters

      • commitId: string

        The commit whose snapshot to read.

      • stateId: string

        The store-issued record id (create).

      Returns Readonly<STATE> | undefined

      The commit's snapshot, not the current state: what a derived write that lands late - a calculation's compile landing in the commit that entered a formula (amend) - reads so that it sees the inputs as they were when the operation was made, whatever has changed since. undefined when the store no longer holds the commit, or the record did not exist at it.

    • Returns the newest committed point of the history — the tip.

      Returns ICommit

      Unlike getCurrentCommit the tip does not move on restore/revert; the segment from the current commit forward to the tip is the redo history. Together with getLog this is the pull primitive for "what happened since commit X": walk the log from the tip back to the last id you saw. Listener events are dispatched on a deferred tick, so a consumer whose next action depends on being current should pull, not wait.

    • Returns the version id of a record at the current commit.

      Parameters

      • stateId: string

        The store-issued record id (create).

      Returns number

      The version id, or 0 if the record has never been committed.

      Ids come from a single store-wide sequence bumped once per commit: a record's id increases on every committed write (but is not sequential per record), and records written in the same commit share an id. Because records are immutable, a restore/revert repoints the store and this reports the id of the snapshot the store is currently at; ids themselves are never reused. Reads during an open transaction report the last committed id — pending (uncommitted) writes have no id yet.

    • Returns true while the open operation is an amend of a commit other than the one the store is at.

      Returns boolean

      Its writes land in that commit's snapshot alone, and the current state does not change. So anything made inside it that is not versioned by this store - a resource held outside it, once for every snapshot - would exist where the current snapshot has no record of it. Code that makes such a thing asks this first.

    • Returns true if there is an open transaction.

      Returns boolean

    • Returns true while a restore or revert is being delivered to its listeners.

      Returns boolean

      No transaction is open then, but the store is mid-change: a listener that acts on what it hears (a transactional emitter listener, a model re-deriving from the restored snapshot) needs to know that the change it is hearing about is a restore, not an operation.

    • Physically remove a record from the store. Not undoable. The opposite of create.

      Parameters

      • stateId: string

        The store-issued record id (create).

      Returns boolean

      A flag indicating if anything was removed.

      Fires IStateListener.onClose and detaches the record's state listeners, then purges the record from every snapshot (history included) and any open transactions. For the logical, undoable flavor use the model's delete (a state flag).

    • Set the state to a previous history point.

      Parameters

      Returns ICommit

      Can be any previous restore point available in before the current commit or after the current commit.

    • Revert is similar to restore in that it moves the state, but it replays the commit's intents in reverse - an undo lands where the operation began rather than where it ended.

      Parameters

      Returns ICommit

      Can be any previous restore point available in before the current commit or after the current commit.

    • Sets the transaction store to be synchronous or asynchronous.

      Parameters

      • sync: boolean

      Returns void

      This is used for unit tests only.