From f4076aa0db33472522c9ec54c60812c779a89724 Mon Sep 17 00:00:00 2001 From: delucis Date: Sat, 22 Jan 2022 16:54:52 +0100 Subject: [PATCH] feat(emitter): flush remaining effects queue on state update Previously, if a state update arrived while an effects queue was in the middle of being processed, the active effects queue was simply discarded and the new one processed. This was potentially buggy in that `onEnd` callbacks might not be called even if the `onStart` was (and similar clean-up bugs if relying on a separate effect or `effects:end` to run clean-up, stop animations etc.). Now, any outstanding effects are flushed when a new state update arrives, ensuring those callbacks will all immediately be called before the new queue is started. BREAKING CHANGE: This may be a breaking change if you were relying on the previous queue being discarded. Given that would be highly timing dependent between when moves where executed, that seems unlikely to be the case, but flagging this as potentially breaking nonetheless. Closes #57 --- src/emitter/emitter.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/emitter/emitter.ts b/src/emitter/emitter.ts index 34f33e5..499d65a 100644 --- a/src/emitter/emitter.ts +++ b/src/emitter/emitter.ts @@ -150,6 +150,7 @@ class EffectsEmitterImpl implements EffectsEmitter { * Update the queue state when a new state update is received from boardgame.io. */ public onUpdate(state: null | S): void { + this.flush(); const prevState = this.latestState; this.latestState = state; if (