End pause (#832)

* refactor: trigger ahead

* refactor: refresh often

* fix: handle empty rundown updates

* fix: handle falsy values

* style: avoid overlap of components

* refactor: freeze end option
This commit is contained in:
Carlos Valente
2024-03-19 18:04:05 +01:00
committed by GitHub
parent 8156da03d5
commit 4bb836b6f2
18 changed files with 89 additions and 39 deletions
+24 -3
View File
@@ -48,7 +48,7 @@ export class TimerService {
this.onUpdateCallback = timerConfig.onUpdateCallback;
this._interval = setInterval(() => {
this.update();
}, TimerService._updateInterval);
}, TimerService._refreshInterval);
}
@broadcastResult
@@ -58,7 +58,8 @@ export class TimerService {
}
const state = runtimeState.getState();
this.endCallback = setTimeout(() => this.update(), state.timer.expectedFinish);
const endTime = state.timer.current - 10;
this.endCallback = setTimeout(() => this.update(), endTime);
return true;
}
@@ -107,7 +108,6 @@ export class TimerService {
@broadcastResult
update() {
const updateResult = runtimeState.update();
// pass the result to the parent
this.onUpdateCallback(updateResult);
}
@@ -143,6 +143,7 @@ function broadcastResult(_target: any, _propertyKey: string, descriptor: Propert
// some changes need an immediate update
const hasNewLoaded = state.eventNow?.id !== TimerService.previousState?.eventNow?.id;
const hasSkippedBack = state.clock < TimerService.previousUpdate;
const justStarted = !TimerService.previousState?.timer;
const hasChangedPlayback = TimerService.previousState.timer?.playback !== state.timer.playback;
@@ -175,7 +176,27 @@ function broadcastResult(_target: any, _propertyKey: string, descriptor: Propert
// Helper function to update an event if it has changed
function updateEventIfChanged(eventKey: keyof RuntimeStore, state: RuntimeState) {
const previous = TimerService.previousState?.[eventKey];
const now = state[eventKey];
// if there was nothing, and there is nothing, noop
if (!previous?.id && !now?.id) {
return;
}
// if load status changed, save new
if (previous?.id !== now?.id) {
storeKey(eventKey);
return;
}
// maybe the event itself has changed
if (!deepEqual(TimerService.previousState?.[eventKey], state[eventKey])) {
storeKey(eventKey);
return;
}
function storeKey(eventKey: keyof RuntimeStore) {
eventStore.set(eventKey, state[eventKey]);
TimerService.previousState[eventKey] = { ...state[eventKey] };
}