Files
Psychotoxical-psysonic/src/store/undoRedoActions.ts
T
Frank Stellmacher 76fc3bb9c9 refactor(player): E.34 — extract transport-light + undo/redo factories (#598)
Two small action-factory extractions in one PR, both following the
pattern from E.31–E.33.

- `createTransportLightActions` — `stop`, `pause`, `resetAudioPause`,
  `togglePlay`. Everything in the pause/togglePlay cluster except
  `resume` (~165 LOC, deferred to its own PR).
- `createUndoRedoActions` — `undoLastQueueEdit`, `redoLastQueueEdit`.
  Trivial wrappers around `applyQueueHistorySnapshot` + the queue-undo
  stack helpers.

Pure code-move. playerStore.ts: 1247 → 1167 LOC (−80).
2026-05-12 20:52:22 +02:00

44 lines
1.4 KiB
TypeScript

import { applyQueueHistorySnapshot } from './applyQueueHistorySnapshot';
import type { PlayerState } from './playerStoreTypes';
import {
popQueueRedoSnapshot,
popQueueUndoSnapshot,
pushQueueRedoSnapshot,
pushQueueUndoSnapshot,
queueUndoSnapshotFromState,
} from './queueUndo';
type SetState = (
partial: Partial<PlayerState> | ((state: PlayerState) => Partial<PlayerState>),
) => void;
type GetState = () => PlayerState;
/**
* Undo / redo wrappers for queue edits. Both pop the matching history
* snapshot, push the *prior* state onto the opposite stack so the next
* call reverses direction, and delegate the actual state reconciliation
* to `applyQueueHistorySnapshot`.
*/
export function createUndoRedoActions(set: SetState, get: GetState): Pick<
PlayerState,
'undoLastQueueEdit' | 'redoLastQueueEdit'
> {
return {
undoLastQueueEdit: () => {
const prior = get();
const snap = popQueueUndoSnapshot();
if (!snap) return false;
pushQueueRedoSnapshot(queueUndoSnapshotFromState(prior));
return applyQueueHistorySnapshot(snap, prior, set, get);
},
redoLastQueueEdit: () => {
const prior = get();
const snap = popQueueRedoSnapshot();
if (!snap) return false;
pushQueueUndoSnapshot(queueUndoSnapshotFromState(prior));
return applyQueueHistorySnapshot(snap, prior, set, get);
},
};
}