github statelyai/xstate @xstate/store@3.8.0

2 months ago

Minor Changes

  • #5305 725530f Thanks @davidkpiano! - Added undo/redo functionality to XState Store via the undoRedo higher-order store logic:

    • Adds undo and redo events to stores
    • Supports grouping related events into transactions using transactionId
    • Maintains event history for precise state reconstruction
    • Automatically clears redo stack when new events occur
    import { createStore } from '@xstate/store';
    import { undoRedo } from '@xstate/store/undo';
    
    const store = createStore(
      undoRedo({
        context: { count: 0 },
        on: {
          inc: (ctx) => ({ count: ctx.count + 1 }),
          dec: (ctx) => ({ count: ctx.count - 1 })
        }
      })
    );
    
    store.trigger.inc();
    // count: 1
    store.trigger.inc();
    // count: 2
    store.trigger.undo();
    // count: 1
    store.trigger.undo();
    // count: 0
    store.trigger.redo();
    // count: 1
    store.trigger.redo();
    // count: 2

Don't miss a new xstate release

NewReleases is sending notifications on new releases.