fix: state stale in integrations

This commit is contained in:
Carlos Valente
2024-04-27 20:17:37 +02:00
committed by Carlos Valente
parent 9e04a1dcfa
commit 189cee0104
2 changed files with 11 additions and 2 deletions
@@ -1,7 +1,7 @@
import { LogOrigin } from 'ontime-types';
import IIntegration, { TimerLifeCycleKey } from './IIntegration.js';
import { eventStore } from '../../stores/EventStore.js';
import { getState } from '../../stores/runtimeState.js';
import { logger } from '../../classes/Logger.js';
class IntegrationService {
@@ -20,7 +20,14 @@ class IntegrationService {
}
dispatch(action: TimerLifeCycleKey) {
const state = eventStore.poll();
/**
* We currently get the state from the runtimeState store
* This solves an issue where the state is not updated until after the integrations have ran
* The workaround solves the issue with the tradeoff of
* - we do not have access to data outside runtimeState (eg: messages or auxtimers)
* - we couple the integrationService to runtimeState
*/
const state = getState();
this.integrations.forEach((integration) => {
integration.dispatch(action, state);
});
@@ -196,6 +196,8 @@ class RuntimeService {
const success = runtimeState.load(event, timedEvents);
if (success) {
// TODO: dispatch should happen after store update
// currently store update is handled in TimerService only
integrationService.dispatch(TimerLifeCycle.onLoad);
logger.info(LogOrigin.Playback, `Loaded event with ID ${event.id}`);
}