Skip to content

Commit

Permalink
Refactor magickEvent.ts to improve state synchronization and event ha…
Browse files Browse the repository at this point in the history
…ndling
  • Loading branch information
michaelsharpe committed Jan 28, 2024
1 parent 8360ddf commit d0d6530
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions packages/server/grimoire/src/lib/nodes/magickEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,13 @@ export function makeMagickEventNodeDefinition<
completedListener: CommitArgs[1]
) => {
const stateService = getDependency<IStateService>('IStateService')

if (!stateService) {
commit(outflowName, completedListener)
return
}
const eventStore = getDependency<IEventStore>('IEventStore')

commit(outflowName, async resolveSockets => {
// When the event is done, we sync the state and clear it
// This sets the state for the next run of this event on this or another engine
await stateService.syncAndClearState()
if (stateService) await stateService.syncAndClearState()
if (eventStore) eventStore.done()

completedListener?.(resolveSockets)
})
Expand Down Expand Up @@ -206,7 +203,8 @@ export function makeMagickEventNodeDefinition<
await stateService.rehydrateState(engine!.nodes, stateKey)
}

eventConfig.handleEvent(event, newArgs) // Pass all init args and the event to the callback
// Pass all init args and the event to the callback
eventConfig.handleEvent(event, newArgs)
if (!node || !engine) return

// This allows us to send up the signal that the event node has been triggered by the listener
Expand Down

0 comments on commit d0d6530

Please sign in to comment.