Skip to content

refactor(worker-javascript): extract Phase 2 helpers from Core.js#1038

Open
dqnykamp wants to merge 5 commits intoDoenet:mainfrom
dqnykamp:core-refactor-2
Open

refactor(worker-javascript): extract Phase 2 helpers from Core.js#1038
dqnykamp wants to merge 5 commits intoDoenet:mainfrom
dqnykamp:core-refactor-2

Conversation

@dqnykamp
Copy link
Copy Markdown
Member

@dqnykamp dqnykamp commented May 1, 2026

Note

Stacked on #1036. This PR includes Phase 1's commits in its diff until #1036 merges; review Phase 2 by reading just the final commit, or use the commits tab to see Phase 2 changes in isolation. Once #1036 merges, this PR will auto-rebase and the diff will show only Phase 2.

Summary

Phase 2 of breaking up packages/doenetml-worker-javascript/src/Core.js. Same pattern as Phase 1 (composed sibling holding a core back-reference, thin delegating wrapper on Core for every public method/property). No behavior change.

Net effect over both phases: Core.js drops from 13,837 → 11,253 lines (-18.7%).

Modules extracted in Phase 2

Module Lines Owns
RendererInstructionBuilder.ts 512 componentsToRender, componentsWithChangedChildrenToRender, rendererState; the dast/instruction stream sent to the renderer
ProcessQueue.ts 220 processQueue, processing, stopProcessingRequests; the async request queue and entry-point scheduling (executeProcesses, requestAction, requestUpdate, requestRecordEvent)
ComponentLifecycle.ts 264 Stateless: registerComponent, deregisterComponent, setAncestors, processNewDefiningChildren, spliceChildren, addChildrenAndRecurseToShadows
ChildMatcher.ts 483 Recursion guard only: child-group matching, adapter substitution, rendered-child filtering
DeletionEngine.ts 397 Stateless: two-phase component deletion
ActionTriggerScheduler.ts 303 stateVariableChangeTriggers, actionsChangedToActions, originsOfActionsChangedToActions; trigger polling and chained-action graph

Sequencing rationale

Per the multi-phase plan: `RendererInstructionBuilder` and `ProcessQueue` first (highest readability per line, unblock downstream); `ChildMatcher` and `DeletionEngine` are larger but algorithmically isolated; `ActionTriggerScheduler` last because it shares `updateInfo` fields with the perform bodies still in Core.

Test plan

  • `npm run build -w @doenet/doenetml-worker-javascript` passes after every extraction
  • All 238 tests pass across diagnostics, copying, baseComponent, and answerValidation
    • Diagnostic paths exercise `RendererInstructionBuilder` (renderer state delivery includes diagnostics)
    • Copying tests heavily exercise `ChildMatcher` (alias/composite paths) and the new manager↔core back-refs
    • answerValidation exercises `ActionTriggerScheduler` (chained actions on submitAnswer)
  • CI: full Vitest suite + Cypress groups 1–5

🤖 Generated with Claude Code

dqnykamp and others added 5 commits May 1, 2026 14:14
Begin breaking up the 13,837-line Core class by lifting seven self-
contained, low-coupling helpers into TypeScript modules. The pattern
matches the existing composed siblings (Dependencies.js, ParameterStack):
each module is constructed with a `core` back-reference, and Core retains
a thin delegating wrapper for every method/property that was previously
on the class so external callers (CoreWorker, tests, components, and
`coreFunctions`-bound references) continue to work unchanged.

Modules extracted:
- DiagnosticsManager.ts       — diagnostics queue + source-location walk
- StateVariableNameResolver.ts — pure-function name resolution utilities
- VisibilityTracker.ts        — visibility state and save/suspend timers
- StatePersistence.ts         — save to localStorage / database
- AutoSubmitManager.ts        — debounced answer-submit queue
- NavigationHandler.ts        — handleNavigatingToComponent, navigateToTarget
- ResolverAdapter.ts          — adapter to the external Rust name resolver

No behavior change. Core.js drops from 13,837 to 12,909 lines.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Continues the Core.js breakup with six moderate-effort modules. Same
pattern as Phase 1 (composed sibling holding a `core` back-reference,
thin delegating wrapper on Core for every public method/property).
No behavior change.

Modules extracted:
- RendererInstructionBuilder.ts — owns componentsToRender,
  componentsWithChangedChildrenToRender, rendererState; the dast
  instruction stream sent to the renderer
- ProcessQueue.ts — owns processQueue, processing,
  stopProcessingRequests; async request queue and entry-point
  scheduling (executeProcesses, requestAction, requestUpdate,
  requestRecordEvent)
- ComponentLifecycle.ts — stateless: registration, ancestors,
  defining-child splicing, propagation to shadows
- ChildMatcher.ts — child-group matching, adapter substitution,
  rendered-child filtering (recursion guard only)
- DeletionEngine.ts — stateless two-phase component deletion
- ActionTriggerScheduler.ts — owns stateVariableChangeTriggers,
  actionsChangedToActions, originsOfActionsChangedToActions; trigger
  polling and chained-action graph

Core.js drops from 12,909 to 11,253 lines (this PR), 13,837 → 11,253
since the refactor began (~18.7%).

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 1, 2026

⚠️ No Changeset found

Latest commit: 865e963

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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