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 }
Create a Recorder. Pass
recorder.taptocreateGame({ tap })so the recorder sees every dispatched action; drive withstart/stop.