mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-13 11:23:50 +00:00
refactor: parameterize runtimeState mutators on an explicit state
Every mutator in runtimeState.ts now has a *Core function that receives the state it operates on and touches nothing else. The module keeps the singleton and exports thin wrappers with the existing names and signatures, so all call sites (EventTimer, runtime service, rundown service) are unchanged and the hot path gains no allocations. This also removes the partial-injection hazards of the previous seams: start(state) wrote timer.phase, offset and expected times to the module singleton rather than the received state, and stop(state) cleared the singleton. Production behaviour is identical since production always operated on the singleton; the characterisation harness and snapshots are untouched and prove it. The cores can now be unit tested against a plain state object without the singleton, module resets or the rundown cache. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PVTnCfesGNGwPQJwJ9FwoD
This commit is contained in:
@@ -11,11 +11,12 @@ import {
|
||||
clearState,
|
||||
getState,
|
||||
load,
|
||||
loadGroupFlagAndEnd,
|
||||
loadGroupFlagAndEndCore,
|
||||
pause,
|
||||
resume,
|
||||
roll,
|
||||
start,
|
||||
startCore,
|
||||
stop,
|
||||
update,
|
||||
} from '../runtimeState.js';
|
||||
@@ -82,7 +83,7 @@ describe('mutation on runtimeState', () => {
|
||||
await initRundown(makeRundown({}), {});
|
||||
vi.runAllTimers();
|
||||
|
||||
let success = start(mockState);
|
||||
let success = startCore(mockState);
|
||||
expect(success).toBe(false);
|
||||
|
||||
success = pause();
|
||||
@@ -868,7 +869,7 @@ describe('loadGroupFlagAndEnd()', () => {
|
||||
|
||||
const metadata = { playableEventOrder: ['0', '11', '3'], flags: ['1'] } as RundownMetadata;
|
||||
|
||||
loadGroupFlagAndEnd(rundown, metadata, 2, state);
|
||||
loadGroupFlagAndEndCore(state, rundown, metadata, 2);
|
||||
|
||||
expect(state).toMatchObject({
|
||||
groupNow: rundown.entries[1],
|
||||
@@ -896,7 +897,7 @@ describe('loadGroupFlagAndEnd()', () => {
|
||||
|
||||
const metadata = { playableEventOrder: ['0', '11', '22'], flags: ['1'] } as RundownMetadata;
|
||||
|
||||
loadGroupFlagAndEnd(rundown, metadata, 1, state);
|
||||
loadGroupFlagAndEndCore(state, rundown, metadata, 1);
|
||||
|
||||
expect(state).toMatchObject({
|
||||
groupNow: rundown.entries[2],
|
||||
@@ -924,7 +925,7 @@ describe('loadGroupFlagAndEnd()', () => {
|
||||
|
||||
const metadata = { playableEventOrder: ['0', '11', '22'], flags: ['1'] } as RundownMetadata;
|
||||
|
||||
loadGroupFlagAndEnd(rundown, metadata, 1, state);
|
||||
loadGroupFlagAndEndCore(state, rundown, metadata, 1);
|
||||
|
||||
expect(state).toMatchObject({
|
||||
groupNow: null,
|
||||
@@ -949,7 +950,7 @@ describe('loadGroupFlagAndEnd()', () => {
|
||||
|
||||
const metadata = { playableEventOrder: ['0', '1'], flags: ['1'] } as RundownMetadata;
|
||||
|
||||
loadGroupFlagAndEnd(rundown, metadata, 0, state);
|
||||
loadGroupFlagAndEndCore(state, rundown, metadata, 0);
|
||||
|
||||
expect(state).toMatchObject({
|
||||
groupNow: null,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user