Skip to content

Commit 4e53493

Browse files
fix(proxy-state-tree): call listeners in order of nestedness
1 parent a31127d commit 4e53493

File tree

1 file changed

+9
-4
lines changed
  • packages/node_modules/proxy-state-tree/src

1 file changed

+9
-4
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,25 @@ class ProxyStateTree {
5454
}
5555
}
5656
flush() {
57+
const paths = new Set()
5758
const pathCallbacksToCall = new Set()
5859
const mutations = this.mutations.slice()
5960
const flushId = this.currentFlushId++
6061

6162
for (let objectChange of this.objectChanges) {
6263
if (this.pathDependencies[objectChange]) {
63-
for (let callback of this.pathDependencies[objectChange]) {
64-
pathCallbacksToCall.add(callback)
65-
}
64+
paths.add(objectChange)
6665
}
6766
}
6867

6968
for (let mutation in this.mutations) {
70-
const path = this.mutations[mutation].path
69+
paths.add(this.mutations[mutation].path)
70+
}
71+
72+
// Sort so that parent paths are called first
73+
const sortedPaths = Array.from(paths).sort()
7174

75+
for (let path of sortedPaths) {
7276
if (this.pathDependencies[path]) {
7377
for (let callback of this.pathDependencies[path]) {
7478
pathCallbacksToCall.add(callback)
@@ -80,6 +84,7 @@ class ProxyStateTree {
8084
callback(flushId)
8185
}
8286

87+
paths.clear()
8388
pathCallbacksToCall.clear()
8489
this.mutations.length = 0
8590
this.objectChanges.clear()

0 commit comments

Comments
 (0)