gameplate - v2.2.0
    Preparing search index...

    Function createRecorder

    • Create a Recorder. Pass recorder.tap to createGame({ tap }) so the recorder sees every dispatched action; drive with start / stop.

      Type Parameters

      • S

      Parameters

      Returns Recorder<S>

      import { createGame, createRecorder, defineActions, replay } from 'gameplate';

      type State = { score: number };
      const actions = defineActions<State>()({
      add: (s, n: number) => ({ score: s.score + n }),
      });

      const recorder = createRecorder<State>();
      const game = createGame({ state: { score: 0 }, actions, tap: recorder.tap });

      recorder.start(game.state());
      game.actions.add(10);
      game.actions.add(20);
      const recording = recorder.stop();

      // Deterministic re-derivation — perfect for tests.
      replay(recording, actions); // → { score: 30 }

      // Persist anywhere — recordings are plain JSON.
      const blob = JSON.stringify(recording);
      const restored: Recording<State> = JSON.parse(blob);
      replay(restored, actions); // → { score: 30 }