Skip to content

Commit d157047

Browse files
fix(overmind): ensure flush callbacks are run even though disposing
1 parent 22d6dd3 commit d157047

File tree

1 file changed

+10
-2
lines changed
  • packages/node_modules/proxy-state-tree/src

1 file changed

+10
-2
lines changed

packages/node_modules/proxy-state-tree/src/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,16 @@ export class ProxyStateTree<T extends object> implements IProxyStateTree<T> {
192192
callback(changes.mutations, sortedPaths, flushId, isAsync)
193193
}
194194

195-
for (let callback of this.flushCallbacks) {
196-
callback(changes.mutations, sortedPaths, flushId, isAsync)
195+
// We have to ensure that we iterate all callbacks. One flush might
196+
// lead to a change of the array (disposing), which means something
197+
// might be skipped. But we still want to allow removal of callbacks,
198+
// we just do not want to skip any, which is why we still check if it
199+
// exists in the original array
200+
const flushCallbacks = this.flushCallbacks.slice()
201+
for (let callback of flushCallbacks) {
202+
if (this.flushCallbacks.includes(callback)) {
203+
callback(changes.mutations, sortedPaths, flushId, isAsync)
204+
}
197205
}
198206

199207
paths.clear()

0 commit comments

Comments
 (0)