Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: emit load event on reload #1128

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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