Skip to content

Add undo and redo lifecycle callbacks#40

Merged
TrystonPerry merged 1 commit into
masterfrom
tdawg/luxembourg-v2
Jul 14, 2026
Merged

Add undo and redo lifecycle callbacks#40
TrystonPerry merged 1 commit into
masterfrom
tdawg/luxembourg-v2

Conversation

@TrystonPerry

@TrystonPerry TrystonPerry commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Adds successful undo/redo callbacks across the standalone manager, store, and React provider while routing action failures through the existing error channel. Grouped actions now retain their members, run in the correct order, and compensate already-applied members when a later member fails; provider callbacks can also be replaced without recreating the store. Updates public types, README examples, package version, and focused store/undo/provider coverage. Verified with pnpm typecheck, pnpm test (252 passed, 3 skipped), and pnpm build.

Note

Add onUndo and onRedo lifecycle callbacks to the undo manager and store

  • Adds onUndo and onRedo optional callbacks to UndoManagerConfig, FirestateConfig, and FirestateProviderProps, invoked after successful undo/redo operations.
  • Adds setOnUndo and setOnRedo methods to FirestateStore for replacing handlers at runtime without recreating the store.
  • Routes undo/redo failures through the store's existing onError channel with ErrorContext { type: 'undo', operation: 'undo' | 'redo' } instead of only logging to console.
  • Adds grouped action support in createUndoManager: consecutive actions sharing a groupId are merged into a single atomic entry that undoes newest-first and redoes oldest-first, with compensation on partial failure.
📊 Macroscope summarized 1585d0f. 5 files reviewed, 0 issues evaluated, 0 issues filtered, 0 comments posted

🗂️ Filtered Issues

No issues evaluated.

Comment thread src/react/provider.tsx
onUndo,
onRedo,
children,
}) => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium react/provider.tsx:86

onUndo and onRedo are applied to the store in useEffect, which runs after descendant effects during the same commit. A descendant that calls undoManager.undo() or redo() in its effect observes the previous callback (or undefined) instead of the prop from the current render. Update these handlers synchronously during render (e.g. via refs) rather than deferring replacement to effects.

🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file @src/react/provider.tsx around line 86:

`onUndo` and `onRedo` are applied to the store in `useEffect`, which runs after descendant effects during the same commit. A descendant that calls `undoManager.undo()` or `redo()` in its effect observes the previous callback (or `undefined`) instead of the prop from the current render. Update these handlers synchronously during render (e.g. via refs) rather than deferring replacement to effects.

@TrystonPerry
TrystonPerry merged commit b1d9e02 into master Jul 14, 2026
2 checks passed
@TrystonPerry
TrystonPerry deleted the tdawg/luxembourg-v2 branch July 14, 2026 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant