Skip to content

refactor(studio): reassigned scalars → S container in src/state.js (step 3) - #18

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

refactor(studio): reassigned scalars → S container in src/state.js (step 3)#18
byrongamatos merged 2 commits into
mainfrom
feat/es-module-state-container

Conversation

@byrongamatos

@byrongamatos byrongamatos commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

What

Step 3 — the foundational state lift (like stems' S). All 66 module-scope _foo scalars move into a single exported S container in src/state.js; every _foo reference becomes S.foo (608 sites, underscore dropped). ES imports are read-only bindings, so export let x can't be reassigned from main.jsS.x = … can. main.js 2799 → 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.foo rewrite, then verified: 0 bare scalar refs, 0 double-prefix, parse-clean. Local objects (e.g. the parsed-JSON s.userName) correctly stayed put; only module scalars became S.*.

Move-only, no behaviour change. Keystone for extracting the functional modules (audio graph, waveform, recording, …) next.

Tests

node --test 7/7, pytest 25/25 (backend unaffected). Codex preflight: 0.

Big behavioral surface (all state access) — recommend an on-device pass (playback, mix, record) before/at merge.

Summary by CodeRabbit

  • Refactor
    • Consolidated shared session, playback, UI, recording, and undo/redo state into a single exported container for easier cross-module updates.
    • Updated references to use the new container-based state shape (dropping module-scope underscore variables) with no expected behavior change.
  • Documentation
    • Updated the changelog to reflect the ES-module migration step and the move-only, behavior-preserving rewrite.

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

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 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.js exporting a single mutable S object containing all reassigned studio state.
  • Refactors src/main.js to replace state locals (_foo) with S.foo across 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.

Comment thread src/state.js
Comment thread CHANGELOG.md
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 5512c547-8660-46d8-b6c8-de31ed22265e

📥 Commits

Reviewing files that changed from the base of the PR and between 28c181d and f0a3fef.

📒 Files selected for processing (2)
  • CHANGELOG.md
  • src/state.js
✅ Files skipped from review due to trivial changes (1)
  • CHANGELOG.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/state.js

📝 Walkthrough

Walkthrough

This PR introduces a new src/state.js module exporting a shared mutable object S for application state previously held in module-scope scalars. CHANGELOG.md adds an entry documenting the migration as move-only with no behavior change.

Changes

Shared State Module Migration

Layer / File(s) Summary
Shared state container and changelog entry
src/state.js, CHANGELOG.md
Adds an exported S object consolidating former module-scope state variables and documents the migration as move-only in the changelog.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: moving reassigned scalars into the exported S container in src/state.js.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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-state-container

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

…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>

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
src/state.js (1)

5-94: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Optional: consider a JSDoc @typedef for S.

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 at S.foo call sites across main.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

📥 Commits

Reviewing files that changed from the base of the PR and between fc76386 and 28c181d.

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

@byrongamatos

Copy link
Copy Markdown
Collaborator Author

On the CodeRabbit nitpick (JSDoc @typedef for S): declining. It's marked optional/low-value, and with no tsc type-checking in CI it'd be 66 lines of hand-maintained boilerplate for editor-only autocomplete — and a drift risk (the typedef and the object would need to stay in sync by hand). The grouped comments on the S object already document each field. Happy to revisit if the repo ever adopts checkJs/tsc.

@byrongamatos
byrongamatos merged commit 9e660b9 into main Jul 8, 2026
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