Skip to content

Commit 5bcda51

Browse files
Merge pull request cerebral#92 from etienne-dldc/next
fix(overmind): use operators in compose
2 parents e82a8b3 + 3424414 commit 5bcda51

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

packages/node_modules/overmind/src/Action.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,7 @@ export default class ActionClass<
274274
) => [InitialValue] extends [void]
275275
? INoValueAction<State, Effects, InitialValue, T>
276276
: IValueAction<State, Effects, InitialValue, T> = (action) => {
277-
const composedAction = (action as any)(
278-
() => new ActionClass(this.proxyStateTree, this.getActionChain())
279-
)
277+
const composedAction = (action as any)(this.operators)
280278
const operator = (effects, value) => {
281279
return composedAction(value, effects)
282280
}

packages/node_modules/overmind/src/index.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,4 +336,24 @@ describe('OPERATORS', () => {
336336
expect(end - start).toBeGreaterThanOrEqual(100)
337337
})
338338
})
339+
test('compose', () => {
340+
const mockCallback = jest.fn()
341+
const runMock: Action = ({ run }) =>
342+
run(() => {
343+
mockCallback()
344+
})
345+
const doThis: Action = ({ compose }) => compose(runMock)
346+
const config = {
347+
actions: {
348+
doThis,
349+
},
350+
}
351+
type Config = TConfig<{
352+
actions: typeof config.actions
353+
}>
354+
type Action<Input = void, Output = any> = TAction<Input, Output, Config>
355+
const app = new App(config)
356+
app.actions.doThis()
357+
expect(mockCallback.mock.calls.length).toBe(1)
358+
})
339359
})

0 commit comments

Comments
 (0)