Repository navigation
v1.64: split js/app.js by area into app-*.js - #62
Merged
Merged
Conversation
Still one file. init() in js/app.js added every listener itself; each area now has its own setup function (setupPlanForm, setupImports, setupFreeTab, setupAccount, setupResultTools, setupSettingsMenu, and the Start tab's bill upload joins setupBillCheck), and init() calls them in order. tryLoadSites and resetSitesIfKeyChanged move out of init(). The statements are the same; this makes the split that follows a move of whole functions. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016net8VqMzbBJe1deXahjg6
The 3,000-line page controller becomes eight classic scripts, each an
IIFE on window.Amber as before, with no build step:
app-core.js state, Amber.app, the selected site and state,
Amber's fixed charges, saved JSON, messages
app-plan-form.js the plan form, saved settings, custom plans
app-results.js the answer, every plan, month by month, Usage
app-imports.js the site picker, Amber CSV and NEM12 imports
app-bill.js reading a bill and the Bill? tab
app-free.js the Free? tab
app-settings.js the settings menu
app.js tabs, Start, the dates bar, fetchAndCompare, init
Shared state is exposed deliberately: app-core.js creates Amber.app with
`state` and the shared helpers, each file lists what others may call in
Object.assign(app, { ... }), and calls across files are app.name(),
looked up at call time. Amber._appState and Amber.appApi are unchanged.
The code was moved by script, statement for statement; the only edits
are the app. prefixes on calls that now cross a file.
tests/unit-syntax.js also checks that every app.<name> used is put on
Amber.app by one file and used by another, and that app-core.js loads
first. Docs: module map, load order and review notes updated.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016net8VqMzbBJe1deXahjg6
RickUsingGitHub
marked this pull request as ready for review
November 10, 2026 20:43
RickUsingGitHub
added a commit
that referenced
this pull request
Nov 15, 2026
…s8o-split-app v1.64: split js/app.js by area into app-*.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Step 2 of 2 of the structural clean-up from the v1.62 code review. No change in behaviour.
Stacked on #61 (ESLint, v1.63): this pull request's base is that branch, so the diff here is only the split. Merge #61 first, then point this one at
main.The files
js/app.jswas one 3,000-line IIFE. It is now eight classic scripts, each an IIFE onwindow.Amberas before, with no build step:app-core.jsstate,Amber.app,$,storedJson, the selected site and state, Amber's fixed charges (readAmberRates),fmtDate, messagesapp-plan-form.jscreatePlanObjectFromForm,applyPlanTemplate, saved settings, custom plansapp-results.jsdisplayResults,renderAllPlansTable,updatePlanSavings,renderMonthly, the Usage tab's daily graph and More Statsapp-imports.jsapp-bill.jsensureBillLoaded,renderBillCheckapp-free.jsrenderBatteryShift,drawBatteryShiftapp-settings.jsapp.jsfetchAndCompare,init()(still last)How they share state
app-core.jsloads first and createsAmber.app = { state, $, … }.const app = Amber.app; const state = app.state; const $ = app.$;.app.name(…), looked up when the call runs. The files call each other in both directions (results call the plan form; the plan form asks for a recalculation), so this is what lets the load order between them not matter.Object.assign(app, { … })listing only what another file uses: 52 names in all, out of about 130 functions. Anything not listed is private to its file.Amber._appStateandAmber.appApiare unchanged, so the tests andplanner-ui.jsneeded no edits.Amber.appis internal to the app files.How it was done, and how to review it
Two commits:
init()'s event wiring into one setup function per area (still one file).init()added every listener itself; nowsetupPlanForm,setupImports,setupFreeTab,setupAccount,setupResultToolsandsetupSettingsMenudo, andinit()calls them in order. This is the only commit with hand-moved code, and it is a small diff. The full browser suite passed on this commit on its own.app.in front of each reference that now crosses a file (199 of them, found by scope analysis, not by text search). Nothing was retyped. I checked afterwards that every code line of the old file is in the new files and nothing else is, apart from theapp.prefixes and the wrappers.git diff --color-movedshows it as moves.One deliberate ordering change: in
app.js, theObject.assign(app, …)andAmber.appApilines now come before theDOMContentLoadedhook instead of after it, so everything is in place beforeinit()could run.Guards against a broken cross-file call
no-undefreports a call to another file's function written withoutapp..tests/unit-syntax.jsnow also checks that everyapp.<name>used is put onAmber.appby exactly one file, that everything on it is used by another file, that no other module touchesAmber.app, and thatapp-core.jsis the first app script andapp.jsthe last.Checks
npm run lint: clean.npm run test:unit: passes (388oklines).unit-syntax.js(the new checks) and the version assert inunit-time.js.npm run build:cssleavescss/app.cssunchanged.index.html,js/constants.jsandtests/unit-time.js.docs/ARCHITECTURE.md(load order, module map, a new section on the page controller),docs/REVIEW.md,docs/FRONTEND.mdandCLAUDE.mdupdated.What this doesn't do
The files still read and write one shared
stateobject, so they are separate files more than separate modules.docs/REVIEW.mdnow says so and names narrowing each file's slice ofstateas the next step.planner-ui.jsis untouched.Generated by Claude Code