Skip to content

Commit 7b12a88

Browse files
fix(overmind): fix production of proxy state tree
1 parent 2fcb820 commit 7b12a88

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

packages/node_modules/overmind-components/src/Component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export class Component {
9898
name: this.name,
9999
paths: Array.from(paths),
100100
})
101+
101102
this.vtree.mount(this, this.context)
102103
for (const listener of this.mountListeners) {
103104
listener()

packages/node_modules/overmind-components/src/hooks.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,21 @@ export function useOvermind<Config extends IConfig>(): {
66
actions: TApp<Config>['actions']
77
} {
88
const component = Component.current
9+
const existingHook = component.getHook()
10+
11+
if (existingHook) {
12+
component.nextHookIndex++
13+
return existingHook
14+
}
915

10-
return {
16+
const hook = {
1117
state: component.context.app.state,
1218
actions: component.context.app.actions,
1319
}
20+
21+
component.addHook(hook)
22+
23+
return hook
1424
}
1525

1626
export function useState<T>(initialState: T): [T, (update: T) => void] {

packages/node_modules/overmind/src/index.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export class Overmind<Config extends Configuration> implements Configuration {
8989
the eventHub
9090
*/
9191
const proxyStateTree = new ProxyStateTree(this.getState(configuration), {
92+
devmode: !IS_PRODUCTION,
9293
dynamicWrapper: (proxyStateTree, path, func) =>
9394
func(eventHub, proxyStateTree, path),
9495
})
@@ -218,15 +219,19 @@ export class Overmind<Config extends Configuration> implements Configuration {
218219
const execution = this.createExecution(name, action)
219220
this.eventHub.emit(EventType.ACTION_START, execution)
220221

221-
action(
222-
null,
223-
this.createContext(value, execution, this.proxyStateTree.get()),
224-
(err, val) => {
225-
this.eventHub.emit(EventType.ACTION_END, execution)
226-
if (err) reject(err)
227-
else resolve(val)
228-
}
229-
)
222+
action[IS_PIPE]
223+
? action(
224+
null,
225+
this.createContext(value, execution, this.proxyStateTree.get()),
226+
(err, val) => {
227+
this.eventHub.emit(EventType.ACTION_END, execution)
228+
if (err) reject(err)
229+
else resolve(val)
230+
}
231+
)
232+
: action(
233+
this.createContext(value, execution, this.proxyStateTree.get())
234+
)
230235
})
231236
} else {
232237
const execution = {

0 commit comments

Comments
 (0)