Skip to content

refactor(studio): extract undo/redo + mix-save to src/undo.js (step 8)#23

Merged
byrongamatos merged 2 commits into
mainfrom
feat/es-module-split-undo
Jul 8, 2026
Merged

refactor(studio): extract undo/redo + mix-save to src/undo.js (step 8)#23
byrongamatos merged 2 commits into
mainfrom
feat/es-module-split-undo

Conversation

@byrongamatos

@byrongamatos byrongamatos commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

What

Step 8. Moves undo/redo + debounced mix-save out of main.js into src/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

_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 (Codex preflight caught that leaving it behind = ReferenceError after the debounce). window.studioUndo/studioRedo stay in main and call the imported helpers. main.js 2076 → 2028.

Move-only, no behaviour change.

Tests

node --test 15/15, pytest 25/25. Codex preflight: 0 (after the _saveMixSettings fix).

Behavioral — on-device: change a mix control (persists after ~1s), undo/redo restores audio + UI, mix survives a reload.

Summary by CodeRabbit

  • New Features
    • Added improved undo/redo support for mix changes, including smoother handling of continuous adjustments.
    • Mix settings are now saved more reliably after edits, with automatic delayed updates.
  • Bug Fixes
    • Restored mix changes now reapply correctly and keep the on-screen controls in sync.
    • Undo/redo controls update properly after changes and restores.

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>
Copilot AI review requested due to automatic review settings July 8, 2026 20:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.js containing undo/redo snapshot helpers, restored-state application, and debounced mix persistence.
  • Updated src/main.js to 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.

Comment thread src/undo.js
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>
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f31a73b5-5fa5-44c1-95d8-ee091a0909b1

📥 Commits

Reviewing files that changed from the base of the PR and between f63c01a and 54bac45.

📒 Files selected for processing (3)
  • CHANGELOG.md
  • src/main.js
  • src/undo.js

📝 Walkthrough

Walkthrough

Undo/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.

Changes

Undo/Redo Module Extraction

Layer / File(s) Summary
Snapshot capture and stack management
src/undo.js
Adds _pushUndo (debounced) and _captureUndoNow (immediate) functions that serialize mix state, deduplicate against last snapshot, enforce MAX_UNDO depth, clear redo stack, and update undo/redo button UI.
Snapshot restoration and mix persistence
src/undo.js
Adds _applyRestoredMixState to restore a snapshot (re-render tracks, apply to live audio, trigger save, redraw cursors) and _debounceSaveMix/_saveMixSettings to POST mix settings to the server with a 1-second debounce.
main.js wiring
src/main.js
Imports _pushUndo, _captureUndoNow, _applyRestoredMixState, _debounceSaveMix from ./undo.js and removes the corresponding previously in-file implementations, including MAX_UNDO and the old _saveMixSettings flow.
Changelog documentation
CHANGELOG.md
Documents ES-module migration step 8 as a move-only extraction of undo/redo and mix-save logic to src/undo.js.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/es-module-split-undo

Comment @coderabbitai help to get the list of available commands.

@byrongamatos
byrongamatos merged commit 4040a06 into main Jul 8, 2026
2 of 3 checks passed
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.

2 participants