refactor(studio): extract undo/redo + mix-save to src/undo.js (step 8)#23
Conversation
Move _pushUndo/_captureUndoNow (debounced snapshots, §VI), _updateUndoButtons, _applyRestoredMixState (re-applies a snapshot to the live graph + re-renders), _debounceSaveMix + _saveMixSettings (debounced server persist), and MAX_UNDO out of main.js. _applyRestoredMixState imports the lower layers it drives (audio-graph _applyAllMixToLive/_getAudioCtx, viz _drawAllCursors, render _renderTracks) — one-way, no cycle. _saveMixSettings moved alongside its only caller _debounceSaveMix (Codex caught the ReferenceError otherwise). window.studioUndo/ studioRedo stay in main (command surface) and call the imported helpers. main.js 2076 -> 2028. node 15/15, python 25/25. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR is part of the ongoing ES-module migration and refactors the Studio code by extracting undo/redo handling and the debounced server mix-save logic from src/main.js into a dedicated module src/undo.js, with the goal of keeping main.js smaller while preserving existing behavior.
Changes:
- Added
src/undo.jscontaining undo/redo snapshot helpers, restored-state application, and debounced mix persistence. - Updated
src/main.jsto import the extracted helpers and removed the inline implementations. - Documented the refactor as “step 8” in
CHANGELOG.md.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/undo.js | New module that owns undo/redo snapshot capture, restored-state application, and debounced mix-save persistence. |
| src/main.js | Switches to importing undo/mix-save helpers and removes the inlined implementations. |
| CHANGELOG.md | Adds an entry describing the step-8 extraction/refactor. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Address Copilot on #23 — _applyRestoredMixState now clears S.undoDebounceTimer first. Otherwise a snapshot timer armed by a slider drag just before undo/redo fires afterward, captures the post-restore state, and clears redoStack (breaking redo). Pre-existing; hardened here in the undo module. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughUndo/redo snapshotting, restoration, undo-button UI updates, and debounced mix-settings persistence logic are extracted from src/main.js into a new src/undo.js module. main.js now imports these helpers instead of defining them. CHANGELOG.md documents this as a move-only change. ChangesUndo/Redo Module Extraction
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
What
Step 8. Moves undo/redo + debounced mix-save out of
main.jsintosrc/undo.js:_pushUndo/_captureUndoNow(debounced vs immediate snapshots, §VI),_updateUndoButtons_applyRestoredMixState(re-applies a snapshot to the live audio graph + re-renders)_debounceSaveMix+_saveMixSettings(debounced server persist) +MAX_UNDO_applyRestoredMixStateimports the lower layers it drives (audio-graph_applyAllMixToLive/_getAudioCtx, viz_drawAllCursors, render_renderTracks) — one-way, no cycle._saveMixSettingsmoved alongside its only caller (Codex preflight caught that leaving it behind =ReferenceErrorafter the debounce).window.studioUndo/studioRedostay in main and call the imported helpers.main.js2076 → 2028.Move-only, no behaviour change.
Tests
node --test15/15,pytest25/25. Codex preflight: 0 (after the_saveMixSettingsfix).Summary by CodeRabbit