Skip to content

Refactor (3/N): split js/app.js into per-feature files#24

Merged
dnkats merged 1 commit into
mainfrom
refactor/split-js-features
May 31, 2026
Merged

Refactor (3/N): split js/app.js into per-feature files#24
dnkats merged 1 commit into
mainfrom
refactor/split-js-features

Conversation

@dnkats

@dnkats dnkats commented May 31, 2026

Copy link
Copy Markdown
Member

Third step of splitting the large index.html. This carves the single js/app.js (4,121 lines) into 14 cohesive feature files.

Safety: provably behavior-preserving

The files are loaded as classic scripts in the same source order as the original code, so:

  • they share one global scope → the 49 inline onclick= handlers and all cross-file function/variable references keep working;
  • top-level statements (the var/let/const globals, the Info object, and the $(document).ready/addEventListener registrations) execute in the exact same order.

I verified mechanically that concatenating the 14 files in load order is byte-for-byte identical to the previous js/app.js — i.e. this is the same code, just partitioned. Each file also parses independently (node --check), confirming no split lands mid-statement.

The files (load order)

File Contents
jsmol-setup.js globals + Info object (JSmol applet config & callbacks)
image-export.js PNG/JPEG export
molecule-data.js atom-name preservation, XYZ loading, $(document).ready startup
viewer-controls.js spin / display mode / zoom
search.js file & sample load, PubChem/database search
orbitals.js MO list + navigation
xyz-editor.js XYZ editor panel
selection.js shared atom-selection state
ui.js draggable panels, wheel zoom, resize observer
jsme-2d.js 2D/3D (JSME) integration
elemco.js ElemCo.jl input generation + Julia runner
xtb.js xtb (g-xTB) energy/optimization
app-init.js panel + application initialization
preferences.js user preferences system

js/**/* is already in the build.files allowlist (from PR #23), so packaging is covered.

Notes

  • Indentation is left at the original 8 spaces so this remains a pure move (no whitespace noise). An optional whitespace-only re-indent PR can follow if desired.
  • A natural cleanup for a later PR: renderer.js still redefines a few functions (copyElemCoInput, showElemCoPanel, …) that the app overrides — worth consolidating.

Testing

  • Concatenation == original app.js (verified).
  • node --check passes for all 14 files.
  • Recommend an npm start smoke test across the panels (load molecule, XYZ editor, selection both ways, orbitals, ElemCo, xtb).

🤖 Generated with Claude Code

Third step of splitting index.html. js/app.js is divided into 14
cohesive feature files, loaded as classic scripts in the SAME source
order, so they share one global scope (the inline onclick handlers keep
working) and execute identically. Verified the concatenation of the 14
files in load order is byte-for-byte identical to the previous app.js,
so behavior is unchanged.

  jsmol-setup    Info object + JSmol applet config / callbacks
  image-export   PNG/JPEG export
  molecule-data  atom-name preservation, XYZ loading, app startup
  viewer-controls spin / display mode / zoom
  search         file/sample load + PubChem/database search
  orbitals       MO list + navigation
  xyz-editor     XYZ editor panel
  selection      shared atom-selection state
  ui             draggable panels, wheel zoom, resize observer
  jsme-2d        2D/3D (JSME) integration
  elemco         ElemCo.jl input generation + Julia runner
  xtb            xtb (g-xTB) energy/optimization
  app-init       panel + application initialization
  preferences    user preferences system

(js/**/* is already in the electron-builder files allowlist.)
Indentation is left as-is so this stays a pure move; an optional
whitespace-only re-indent can follow.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 31, 2026 15:43
@dnkats dnkats merged commit 6eae47f into main May 31, 2026
1 check passed
@dnkats dnkats deleted the refactor/split-js-features branch May 31, 2026 15:56
@dnkats dnkats review requested due to automatic review settings May 31, 2026 16:07
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.

1 participant