refactor(editor): move file operations to src/file-ops.js (R2, step 31) - #183
Conversation
Extract the load and save flows out of the src/main.js monolith into a new native ES module: loadCDLC + the load-browser modal (browse/song-list/search), and _buildSaveBody + saveCDLC + the save-format modal. - src/file-ops.js: exports the 7 symbols main.js still calls (loadCDLC, saveCDLC, showLoadModal, filterSongs, _activeArrangementExceedsArchiveLimit, _resetOffsetUI, and the _editorLoadsInFlight live binding) plus the 2 save-format window handlers. The interleaved display helpers (updateTimeDisplay, updateArrangementSelector) stay in main.js — this was a function-level cut, not a banner range — and are reached, like every other retained dep, through host. - host.js: one new hook applyEditorPendingView (loadCDLC's tail consumes a stashed view). Default no-op. - Removed 16 now-dead main.js imports (they served only the moved save/load code) and dropped the dead renderSongPrompt function. - tests/feedpak_song_list.test.js retargeted to slice _normalizeSongList from src/file-ops.js. main.js drops ~610 lines. 32 modules. Verified: 90/90 JS suites pass, ESLint gate clean (0 errors), strict no-undef clean on file-ops.js, Codex preflight 0 issues. New headless harness drives a REAL load (editorLoadFile → loadCDLC, with a stashed pending view asserted consumed to prove the applyEditorPendingView hook — negative-checked) and a REAL save (saveCDLC + _buildSaveBody, POST intercepted so nothing persists), with zero page errors across both, which exercises every host qualification. 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 (1)
📝 WalkthroughWalkthroughChangesEditor file operations
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant EditorUI
participant file_ops
participant EditorAPI
participant EditorState
EditorUI->>file_ops: loadCDLC(filename)
file_ops->>EditorAPI: POST /api/plugins/editor/load
EditorAPI-->>file_ops: session data
file_ops->>EditorState: restore session and reset selections
EditorState-->>EditorUI: refresh and draw
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Pull request overview
This PR continues the R2 module-extraction refactor by moving the editor’s load/save flows out of src/main.js into a new ES module, src/file-ops.js, while keeping UI/toolbar composition in main.js and accessing it via host hooks.
Changes:
- Extracted load pipeline (
loadCDLC, load-browser modal + search/filter) intosrc/file-ops.jsand re-wiredmain.jsto import/re-export the required window handlers and symbols. - Extracted save pipeline (
_buildSaveBody,saveCDLC, archive-limit check, save-format modal handlers) intosrc/file-ops.jsand re-attached save-format handlers onwindowfrommain.js. - Added a new host hook
applyEditorPendingViewand retargeted the_normalizeSongListunit test to read fromsrc/file-ops.js.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
tests/feedpak_song_list.test.js |
Updates the source-slicing test to extract _normalizeSongList from src/file-ops.js instead of src/main.js. |
src/main.js |
Removes now-dead imports and moved function bodies; imports file-ops symbols, re-attaches window handlers, and wires the new host hook. |
src/host.js |
Adds the applyEditorPendingView host hook with a default no-op implementation. |
src/file-ops.js |
New module containing the extracted load/save flows, calling back into main.js-owned UI refreshers via host. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@src/file-ops.js`:
- Around line 413-421: Guard both save loops over S.arrangements against falsy
or missing entries before processing each arrangement. In the loop containing
flattenChords/reconstructChords and the loop invoking _normalizeTuningToLanes,
skip the iteration when S.arrangements[i] is falsy while preserving index
handling and savedArr behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 4e787526-fc59-4b61-9fe3-19da1a373a48
📒 Files selected for processing (4)
src/file-ops.jssrc/host.jssrc/main.jstests/feedpak_song_list.test.js
Defense-in-depth for a data-loss path (a null entry would throw mid-save and abort the write). Addresses CodeRabbit on #183. Not currently reachable — no code path inserts a hole into S.arrangements (whole-array assign, push, splice only) — but the guard is trivial and the failure mode is a lost save. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
What
Step 31 of the R2 module-extraction refactor: move the load and save flows out of
src/main.jsinto a new native ES modulesrc/file-ops.js.Covers:
loadCDLC(open a pack into the editor) + the load-browser modal (showLoadModal, directory browse, song list, search/filterSongs)._buildSaveBody+saveCDLC+_activeArrangementExceedsArchiveLimit+ the save-format modal (editorSaveAsSloppakConfirm/editorHideSaveFormatModal).How the seam is drawn
updateTimeDisplayandupdateArrangementSelectorare interleaved between the load and save functions and stay in main.js (they're the composition root's toolbar/display layer). file-ops.js reaches them — and every other retained dep — throughhost.loadCDLC,saveCDLC,showLoadModal,filterSongs,_activeArrangementExceedsArchiveLimit,_resetOffsetUI, and the_editorLoadsInFlightlive binding read by the start-landing guard) and re-attaches the 2 save-format window handlers.applyEditorPendingView(loadCDLC's tail consumes a stashed view from the highway's "Edit region" handoff). Default no-op.renderSongPromptfunction.tests/feedpak_song_list.test.jsretargeted to slice_normalizeSongListfromsrc/file-ops.js.main.js drops ~610 lines. 32 modules.
Verification
no-undefclean onfile-ops.js(which pinpointed every host qualification, including one I'd have missed).verify_file_ops.py) drives a real load (editorLoadFile → loadCDLC, with a stashed pending view asserted consumed to prove the newapplyEditorPendingViewhook — negative-checked by unwiring it → stash survives → FAIL) and a real save (saveCDLC+_buildSaveBody, POST intercepted so nothing persists — the built body carriesarrangements/notes), with zero page errors across both, which exercises every one of the 8 host qualifications.🤖 Generated with Claude Code
Summary by CodeRabbit