refactor(studio): reassigned scalars → S container in src/state.js (step 3) - #18
Conversation
…step 3)
Move all 66 module-scope _foo scalars (playback clock, audio graph, mix/undo,
recording, punch, highway-record, settings) into one exported S object in
src/state.js. ES imports are read-only bindings, so export let can't be
reassigned from main.js, but S.x = ... can. Every _foo -> S.foo (608 sites,
underscore dropped).
Rewrite audited safe: no name is an object key or inside a string/comment literal
(string-adjacent hits were all ${} template expressions or fn args); verified 0
bare refs + 0 double-prefix + parse-clean after. Local objects like the parsed-
JSON 's.userName' correctly untouched; only module scalars became S.*. Move-only,
no behaviour change. Keystone for extracting the functional modules next.
node 7/7, 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 continues the studio’s ES-module migration by consolidating previously private, reassigned state into a single exported container object (S) in src/state.js, and updating src/main.js to read/write all state via S.* instead of _foo locals. This is intended to enable safe cross-module reassignment (since ES module imports are read-only bindings) and sets up the codebase for further modular extraction.
Changes:
- Introduces
src/state.jsexporting a single mutableSobject containing all reassigned studio state. - Refactors
src/main.jsto replace state locals (_foo) withS.fooacross playback, mixing, undo, recording, punch-in, and highway recording paths. - Documents the migration step in
CHANGELOG.md.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/state.js | Adds exported S container holding the consolidated mutable studio state. |
| src/main.js | Switches all reassigned state access from _foo locals to S.foo and imports S. |
| CHANGELOG.md | Adds an entry describing ES-module migration step 3 (state lift to S). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis PR introduces a new ChangesShared State Module Migration
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
…lars Address Copilot on #18 — the scalars lived inside the IIFE (function scope), not module scope. Comment/CHANGELOG wording only. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/state.js (1)
5-94: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueOptional: consider a JSDoc
@typedefforS.With 66 flat properties on a single mutable object, an editor/tsc-checked JSDoc typedef (e.g.,
/**@type{{isPlaying: boolean, ...}} */) would give autocomplete and catch typos atS.foocall sites acrossmain.js, without requiring a TS migration.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/state.js` around lines 5 - 94, Add a JSDoc typedef for the exported S state object in state.js so editors and tsc can infer its shape and catch invalid S.foo usages. Define the full property structure alongside the S declaration, keeping the existing runtime object unchanged, and make sure the typedef covers the main mutable fields used throughout main.js such as playback, mixState, recording, and highway-related properties.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/state.js`:
- Around line 5-94: Add a JSDoc typedef for the exported S state object in
state.js so editors and tsc can infer its shape and catch invalid S.foo usages.
Define the full property structure alongside the S declaration, keeping the
existing runtime object unchanged, and make sure the typedef covers the main
mutable fields used throughout main.js such as playback, mixState, recording,
and highway-related properties.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: b717d19a-7b21-46bb-87a7-b6917dcffaef
📒 Files selected for processing (3)
CHANGELOG.mdsrc/main.jssrc/state.js
|
On the CodeRabbit nitpick (JSDoc @typedef for |
What
Step 3 — the foundational state lift (like stems'
S). All 66 module-scope_fooscalars move into a single exportedScontainer insrc/state.js; every_fooreference becomesS.foo(608 sites, underscore dropped). ES imports are read-only bindings, soexport let xcan't be reassigned frommain.js—S.x = …can.main.js2799 → 2731.Rewrite safety
Audited before touching: no name is an object key or appears inside a string/comment literal — the "string-adjacent" grep hits were all
${}template expressions or function args. Scripted\b_foo\b → S.foorewrite, then verified: 0 bare scalar refs, 0 double-prefix, parse-clean. Local objects (e.g. the parsed-JSONs.userName) correctly stayed put; only module scalars becameS.*.Move-only, no behaviour change. Keystone for extracting the functional modules (audio graph, waveform, recording, …) next.
Tests
node --test7/7,pytest25/25 (backend unaffected). Codex preflight: 0.Summary by CodeRabbit