diff options
| author | (quasar) nebula <qznebula@protonmail.com> | 2026-03-03 17:14:15 -0400 |
|---|---|---|
| committer | (quasar) nebula <qznebula@protonmail.com> | 2026-03-03 17:14:49 -0400 |
| commit | 488d0a1542e16b2552fbf7d477ad7d6eb753f8a6 (patch) | |
| tree | eaee2a37d71a0b2375d620694e5629adb7990765 /src/static/js | |
| parent | bb296e0b91cb3037d27a742d8939dd2bde6f1833 (diff) | |
client: slightly more versatile step evaluation interface
Alas, it goes completely unused.
Diffstat (limited to 'src/static/js')
| -rw-r--r-- | src/static/js/client/index.js | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/src/static/js/client/index.js b/src/static/js/client/index.js index 3357837e..53432a91 100644 --- a/src/static/js/client/index.js +++ b/src/static/js/client/index.js @@ -56,7 +56,10 @@ export const modules = [ const clientInfo = window.hsmusicClientInfo = Object.create(null); -const clientSteps = { +// These steps are always run in the listed order, on page load. +// So for example, all modules' getPageReferences steps are evaluated, then +// all modules' addInternalListeners steps are evaluated, and so on. +const setupSteps = { getPageReferences: [], addInternalListeners: [], mutatePageContent: [], @@ -64,6 +67,14 @@ const clientSteps = { addPageListeners: [], }; +// These steps are run only on certain triggers. Those are global events, +// so all modules (which specify that step) respond in sequence. +const situationalSteps = { + /* There's none yet... sorry... */ +}; + +const stepInfoSymbol = Symbol(); + for (const module of modules) { const {info} = module; @@ -216,28 +227,34 @@ for (const module of modules) { Object.preventExtensions(info.session); } - for (const key of Object.keys(clientSteps)) { - if (Object.hasOwn(module, key)) { - const fn = module[key]; + for (const stepsObject of [setupSteps, situationalSteps]) { + for (const key of Object.keys(stepsObject)) { + if (Object.hasOwn(module, key)) { + const fn = module[key]; - Object.defineProperty(fn, 'name', { - value: `${infoKey}/${fn.name}`, - }); + fn[stepInfoSymbol] = info; - clientSteps[key].push(fn); + Object.defineProperty(fn, 'name', { + value: `${infoKey}/${fn.name}`, + }); + + stepsObject[key].push(fn); + } } } } -for (const [key, steps] of Object.entries(clientSteps)) { - for (const step of steps) { +function evaluateStep(stepsObject, key) { + for (const step of stepsObject[key]) { try { step(); } catch (error) { - // TODO: Be smarter about not running later steps for the same module! - // Or maybe not, since an error is liable to cause explosions anyway. console.error(`During ${key}, failed to run ${step.name}`); console.error(error); } } } + +for (const key of Object.keys(setupSteps)) { + evaluateStep(setupSteps, key); +} |