Skip to content

Schedule slice 2: atomic cutover in timer.js #12

Description

@benabraham

Parent

#10

What to build

Atomic cutover: replace flat position-and-clock fields in timerState with the Schedule module from #11. End-user behavior must remain identical — this is a pure refactor, but a risky one because every read and write site in src/lib/timer.js shifts at once.

Changes:

  • Drop phase, currentPeriodIndex, timestampStarted, timestampPaused from initialState. After this slice timerState shrinks to { periods, types }.
  • Switch every read of those four fields to the corresponding Schedule computed.
  • Switch every write (across all ~28 mutation sites) to the corresponding Schedule verb.
  • Wrap mixed verbs that touch both Schedule and Periods (moveToNextPeriod, moveToPreviousPeriod, addPeriod, etc.) in batch() so reactive subscribers don't see torn state.
  • Migrate persistence: the storage effect() reads a computed() snapshot of Schedule.snapshot + periods; loadState parses persisted shape into Schedule + periods at boot.
  • Update src/lib/timer-simple.test.js to read phase/index via Schedule computeds.

updateTimerState's timerProperties branch becomes dead code after this slice but is not deleted yet — that's slice 3 (#TBD).

Acceptance criteria

  • phase, currentPeriodIndex, timestampStarted, timestampPaused are no longer in initialState; timerState is { periods, types }
  • All reads of those four fields go through Schedule computeds
  • All writes go through Schedule verbs
  • Mixed Schedule+Period verbs are wrapped in batch()
  • Storage round-trips correctly: a persisted state from before this slice loads into the new shape (or, if backward compatibility is out of scope per project memory, fresh persistence works)
  • src/lib/timer-simple.test.js and src/lib/schedule.test.js both pass
  • pnpm test and pnpm run build both pass
  • Manual QA passes for: start, pause, resume, complete (last period), navigate forward, navigate backward, edit Current Period duration, edit Past Period duration, edit Future Period duration, reset, browser reload mid-run, browser reload while paused
  • No UI flicker or torn states during transitions
  • No end-user behavior change vs. main

Blocked by

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions