mirror of
https://github.com/got-feedBack/feedBack.git
synced 2026-08-11 03:09:57 +00:00
refactor(app): make app.js's window contract explicit — 66 names (R3a) (#874)
app.js is a classic script, so each of its 385 top-level `function foo()` decls
is implicitly a property of `window`. As an ES module it will not be — module
scope is not global scope — and every name reached from outside this file would
silently vanish. This adds the explicit `window.*` assignments BEFORE the flip.
Provably a NO-OP: all 66 are top-level function declarations, so while app.js is
still a classic script `Object.assign(window, {...})` only re-assigns what
`window` already has. That is what makes it safe to land on its own, ahead of
the flip that needs it.
The consumers are wider than the inline handlers in index.html:
- inline on*= handlers in static/v3/index.html
- on*= handlers app.js BUILDS inside template literals (goFavPage,
updatePlugin, hideScanBanner, ...) — they resolve against window at CLICK
time, but live in a JS string, so scanning the HTML alone never finds them
- static/v3/*.js (showScreen alone has 17 consumers), capabilities
- feedback-desktop and the external plugin repos — easy to miss, they live in
other repos and no core test covers them
- capabilities/visualization.js reads window.setViz behind a `typeof` guard,
so losing it DEGRADES IN SILENCE rather than throwing
Constitution II names window.playSong / window.showScreen / window.feedBack as
the public extension contract, so this is an obligation, not a convenience.
FOUR names are invisible to every static tool. app.js:2156-2157 picks the
handler NAME at runtime —
const letterFn = favoritesOnly ? 'filterFavTreeLetter' : 'filterTreeLetter';
— and interpolates it into `onclick="${letterFn}('A')"`. The names exist only
inside string literals, so ESLint, no-undef, and any grep for `onclick="fn` all
miss them. They are the library A-Z rail and its pagination: drop one and those
buttons throw at click time and nowhere else.
New tests/js/window_contract.test.js scrapes the HTML's handlers AND app.js's
template-literal handlers, and pins the 4 runtime-composed names by hand.
Verified to BITE: dropping showScreen, goTreePage, or setViz each fails it with
the right message.
On-device: 28 A-Z rail buttons render with their real onclick sources
(filterTreeLetter('A'), ...) and 8/8 execute with no ReferenceError; all 66
names resolve on window in the browser.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
4b4c156fce
commit
ff7e855e35
@@ -12165,3 +12165,52 @@ async function bootstrapPluginsAndUi() {
|
||||
})
|
||||
.catch(() => {});
|
||||
})();
|
||||
|
||||
|
||||
// ─── The window contract ────────────────────────────────────────────────────
|
||||
// app.js is a classic script today, so every top-level `function foo()` here is
|
||||
// implicitly a property of `window`. The R3a migration turns this file into an
|
||||
// ES module, where that stops being true — module scope is not global scope, and
|
||||
// each of these names would silently vanish from `window`.
|
||||
//
|
||||
// Everything below is reached by NAME from outside this file, so each one is
|
||||
// made explicit BEFORE the flip. While app.js is still classic this whole block
|
||||
// is a no-op (it just re-assigns what is already there), which is exactly what
|
||||
// makes it safe to land on its own.
|
||||
//
|
||||
// The consumers are: inline on*= handlers in static/v3/index.html; on*= handlers
|
||||
// this file builds inside template literals; static/v3/*.js; the capabilities;
|
||||
// bundled plugins; and — easy to forget, since they live in other repos —
|
||||
// feedback-desktop and the external plugins. Constitution II names
|
||||
// `window.playSong` / `window.showScreen` / `window.feedBack` as the public
|
||||
// extension contract.
|
||||
//
|
||||
// Guarded by tests/js/window_contract.test.js. Add a name here the moment
|
||||
// anything outside app.js calls it.
|
||||
Object.assign(window, {
|
||||
_confirmDialog, _getArrangementNamingMode, _libraryLocalFilename, _librarySongArtUrl,
|
||||
_librarySongId, _onHeaderClick, _onNamingModeChange, _trapFocusInModal,
|
||||
changeArrangement, checkPluginUpdates, clearLibFilters, clearLoop,
|
||||
deleteSelectedLoop, exportDiagnostics, exportSettings, filterFavorites,
|
||||
filterLibrary, fullRescanLibrary, goFavPage, handleSliderInput,
|
||||
hideScanBanner, importSettings, loadPlugins, loadSavedLoop,
|
||||
loadSettings, onSectionPracticeModeChange, openEditModal, persistSetting,
|
||||
pickDlcFolder, pinCurrentArrangementDefault, playSong, previewDiagnostics,
|
||||
previewEditArt, renderGridCards, renderTreeInto, rescanLibrary,
|
||||
retuneSong, saveCurrentLoop, saveSettings, seekBy,
|
||||
setAvOffsetMs, setFavView, setInstrumentPathway, setLibView,
|
||||
setLibraryProvider, setLoopEnd, setLoopStart, setMastery,
|
||||
setSpeed, setViz, showScreen, sortFavorites,
|
||||
sortLibrary, syncLibrarySong, toggleAllArtists, toggleAllFavoriteArtists,
|
||||
toggleLibFilters, togglePlay, toggleSectionPracticePopover, uiPrompt,
|
||||
updatePlugin, uploadSongs,
|
||||
|
||||
// These four are invisible to every static scan. app.js:2156-2157 picks the
|
||||
// handler NAME at runtime —
|
||||
// const letterFn = favoritesOnly ? 'filterFavTreeLetter' : 'filterTreeLetter';
|
||||
// — and interpolates it: `onclick="${letterFn}('A')"`. So the names never
|
||||
// appear as identifiers anywhere, and ESLint / no-undef / a grep for
|
||||
// `onclick="fn` all miss them. They are the library A-Z rail and its
|
||||
// pagination; drop one and those buttons throw at click time, nowhere else.
|
||||
filterFavTreeLetter, filterTreeLetter, goFavTreePage, goTreePage,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user