Skip to content

Commit f7b9f3f

Browse files
fix(overmind-react): improve passing updates to devtools using hooks
1 parent 96963d2 commit f7b9f3f

File tree

1 file changed

+22
-33
lines changed
  • packages/node_modules/overmind-react/src

1 file changed

+22
-33
lines changed

packages/node_modules/overmind-react/src/index.ts

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -95,48 +95,37 @@ export const createHook = <Config extends Configuration>(
9595
[]
9696
)
9797
} else {
98-
const [debugging] = useState<any>(() => ({
99-
isFirstRender: true,
100-
currentFlushId: 0,
101-
componentInstanceId: currentComponentInstanceId++,
102-
}))
98+
const [componentInstanceId] = useState<any>(
99+
() => currentComponentInstanceId++
100+
)
103101

104-
tree.track((mutations, paths, flushId) => {
105-
debugging.currentFlushId = flushId
102+
tree.track((_, paths, flushId) => {
106103
updateComponent((state) => state)
104+
overmind.eventHub.emitAsync(EventType.COMPONENT_UPDATE, {
105+
componentId: component.__componentId,
106+
componentInstanceId,
107+
name,
108+
flushId,
109+
paths,
110+
})
107111
})
108112

109-
useLayoutEffect(() => {
110-
if (debugging.isFirstRender) {
111-
overmind.eventHub.emitAsync(EventType.COMPONENT_ADD, {
112-
componentId: component.__componentId,
113-
componentInstanceId: debugging.componentInstanceId,
114-
name,
115-
paths: Array.from(tree.pathDependencies) as any,
116-
})
117-
debugging.isFirstRender = false
118-
} else {
119-
overmind.eventHub.emitAsync(EventType.COMPONENT_UPDATE, {
120-
componentId: component.__componentId,
121-
componentInstanceId: debugging.componentInstanceId,
122-
name,
123-
flushId: debugging.currentFlushId,
124-
paths: Array.from(tree.pathDependencies as Set<string>),
125-
})
126-
}
127-
})
128-
129-
useEffect(
130-
() => () => {
113+
useEffect(() => {
114+
overmind.eventHub.emitAsync(EventType.COMPONENT_ADD, {
115+
componentId: component.__componentId,
116+
componentInstanceId,
117+
name,
118+
paths: Array.from(tree.pathDependencies) as any,
119+
})
120+
return () => {
131121
;(overmind as any).proxyStateTree.disposeTree(tree)
132122
overmind.eventHub.emitAsync(EventType.COMPONENT_REMOVE, {
133123
componentId: component.__componentId,
134-
componentInstanceId: debugging.componentInstanceId,
124+
componentInstanceId,
135125
name,
136126
})
137-
},
138-
[]
139-
)
127+
}
128+
}, [])
140129
}
141130

142131
return {

0 commit comments

Comments
 (0)