Skip to content

Commit

Permalink
refactor: emit load event on reload
Browse files Browse the repository at this point in the history
  • Loading branch information
cpvalente committed Jul 11, 2024
1 parent 84792bc commit 00d34ee
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 7 additions & 1 deletion apps/server/src/services/runtime-service/RuntimeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,13 @@ class RuntimeService {
reload() {
const state = runtimeState.getState();
if (state.eventNow) {
runtimeState.reload();
const eventId = runtimeState.reload();
if (eventId) {
logger.info(LogOrigin.Playback, `Loaded event with ID ${eventId}`);
process.nextTick(() => {
integrationService.dispatch(TimerLifeCycle.onLoad);
});
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion apps/server/src/stores/runtimeState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,15 @@ export function resume(restorePoint: RestorePoint, event: OntimeEvent, rundown:
* @param {OntimeEvent} event only passed if we are changing the data if a playing timer
*/
export function reload(event?: OntimeEvent) {
// we only pass an event for hot reloading, ie: the event has changed
if (event) {
runtimeState.eventNow = event;

// update data which is duplicate between eventNow and timer objects
runtimeState.timer.duration = calculateDuration(runtimeState.eventNow.timeStart, runtimeState.eventNow.timeEnd);
runtimeState.timer.current = getCurrent(runtimeState);
runtimeState.timer.expectedFinish = getExpectedFinish(runtimeState);
return;
return runtimeState.eventNow.id;
}
runtimeState.timer.playback = Playback.Armed;

Expand All @@ -257,6 +258,7 @@ export function reload(event?: OntimeEvent) {
runtimeState.timer.addedTime = 0;

runtimeState.timer.expectedFinish = getExpectedFinish(runtimeState);
return runtimeState.eventNow.id;
}

/**
Expand Down

0 comments on commit 00d34ee

Please sign in to comment.