mwg API
    Preparing search index...

    Class ActionJournal<Action, Event>

    A serializable, append-only action log for replay, undo checkpoints, synchronization and debugging. It does not interpret actions or events: the game decides how to reapply an action, while the journal preserves the exact order and resulting event batch.

    Actions and events are copied with structuredClone on the way in, so both must be plain data. An action that carries a live object holding callbacks (an actor with a ReactionTable, say) is refused by append with the path of the first value that cannot be copied; carry that object's id instead.

    import { ActionJournal } from '@datamoc/mwg/core';

    const journal = new ActionJournal<string, { type: string }>();
    journal.append('open-door', [{ type: 'door-opened' }]);
    const checkpoint = journal.mark();
    // An undo system can restore its state and replay journal.since(checkpoint).

    Type Parameters

    • Action
    • Event
    Index
    • Returns a sequence number that can be used as an undo or sync checkpoint.

      Returns number

    • Drops entries at and after a checkpoint, as an undo operation would.

      Parameters

      • sequence: number

      Returns void