mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-23 16:09:11 +00:00
refactor: offset cannot be null
This commit is contained in:
committed by
Carlos Valente
parent
e90e94828d
commit
938c5fbb4c
@@ -1558,7 +1558,7 @@ describe('getRuntimeOffset()', () => {
|
|||||||
} as RuntimeState;
|
} as RuntimeState;
|
||||||
|
|
||||||
const offset = getRuntimeOffset(state);
|
const offset = getRuntimeOffset(state);
|
||||||
expect(offset).toBe(null);
|
expect(offset).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles loaded event', () => {
|
it('handles loaded event', () => {
|
||||||
|
|||||||
@@ -299,10 +299,10 @@ export const updateRoll = (state: RuntimeState) => {
|
|||||||
* Positive offset is time ahead
|
* Positive offset is time ahead
|
||||||
* Negative offset is time delayed
|
* Negative offset is time delayed
|
||||||
*/
|
*/
|
||||||
export function getRuntimeOffset(state: RuntimeState): MaybeNumber {
|
export function getRuntimeOffset(state: RuntimeState): number {
|
||||||
// nothing to calculate if there are no loaded events or if we havent started
|
// nothing to calculate if there are no loaded events or if we havent started
|
||||||
if (state.eventNow === null || state.runtime.actualStart === null) {
|
if (state.eventNow === null || state.runtime.actualStart === null) {
|
||||||
return null;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { clock } = state;
|
const { clock } = state;
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ describe('mutation on runtimeState', () => {
|
|||||||
stop();
|
stop();
|
||||||
newState = getState();
|
newState = getState();
|
||||||
expect(newState.runtime.actualStart).toBeNull();
|
expect(newState.runtime.actualStart).toBeNull();
|
||||||
expect(newState.runtime.offset).toBeNull();
|
expect(newState.runtime.offset).toBe(0);
|
||||||
expect(newState.runtime.expectedEnd).toBeNull();
|
expect(newState.runtime.expectedEnd).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import { timerConfig } from '../config/config.js';
|
|||||||
const initialRuntime: Runtime = {
|
const initialRuntime: Runtime = {
|
||||||
selectedEventIndex: null,
|
selectedEventIndex: null,
|
||||||
numEvents: 0,
|
numEvents: 0,
|
||||||
offset: null,
|
offset: 0,
|
||||||
plannedStart: 0,
|
plannedStart: 0,
|
||||||
plannedEnd: 0,
|
plannedEnd: 0,
|
||||||
actualStart: null,
|
actualStart: null,
|
||||||
@@ -82,7 +82,7 @@ export function clear() {
|
|||||||
runtimeState.eventNext = null;
|
runtimeState.eventNext = null;
|
||||||
runtimeState.publicEventNext = null;
|
runtimeState.publicEventNext = null;
|
||||||
|
|
||||||
runtimeState.runtime.offset = null;
|
runtimeState.runtime.offset = 0;
|
||||||
runtimeState.runtime.actualStart = null;
|
runtimeState.runtime.actualStart = null;
|
||||||
runtimeState.runtime.expectedEnd = null;
|
runtimeState.runtime.expectedEnd = null;
|
||||||
runtimeState.runtime.selectedEventIndex = null;
|
runtimeState.runtime.selectedEventIndex = null;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import type { MaybeNumber } from '../../utils/utils.type.js';
|
|||||||
export type Runtime = {
|
export type Runtime = {
|
||||||
numEvents: number;
|
numEvents: number;
|
||||||
selectedEventIndex: MaybeNumber;
|
selectedEventIndex: MaybeNumber;
|
||||||
offset: MaybeNumber;
|
offset: number;
|
||||||
plannedStart: MaybeNumber;
|
plannedStart: MaybeNumber;
|
||||||
actualStart: MaybeNumber;
|
actualStart: MaybeNumber;
|
||||||
plannedEnd: MaybeNumber;
|
plannedEnd: MaybeNumber;
|
||||||
|
|||||||
Reference in New Issue
Block a user