Skip to content

Commit

Permalink
Fixed an issue with choose and pure not being able to use actions…
Browse files Browse the repository at this point in the history
… defined in options
  • Loading branch information
Andarist committed Apr 22, 2020
1 parent 73f5802 commit e16e48e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/tall-cars-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'xstate': patch
---

Fixed an issue with `choose` and `pure` not being able to use actions defined in options.
4 changes: 2 additions & 2 deletions packages/core/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ export function resolveActions<TContext, TEvent extends EventObject>(
currentState,
updatedContext,
_event,
toActionObjects(toArray(matchedActions))
toActionObjects(toArray(matchedActions), machine.options.actions)
);
updatedContext = resolved[1];
return resolved[0];
Expand All @@ -619,7 +619,7 @@ export function resolveActions<TContext, TEvent extends EventObject>(
currentState,
updatedContext,
_event,
toActionObjects(toArray(matchedActions))
toActionObjects(toArray(matchedActions), machine.options.actions)
);
updatedContext = resolved[1];
return resolved[0];
Expand Down
27 changes: 27 additions & 0 deletions packages/core/test/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1292,4 +1292,31 @@ describe('choose', () => {

expect(service.state.context).toEqual({ counter: 101, answer: 42 });
});

it('should be able to use actions defined in options', () => {
interface Ctx {
answer?: number;
}

const machine = createMachine<Ctx>(
{
context: {},
initial: 'foo',
states: {
foo: {
entry: choose([{ cond: () => true, actions: 'revealAnswer' }])
}
}
},
{
actions: {
revealAnswer: assign<Ctx>({ answer: 42 })
}
}
);

const service = interpret(machine).start();

expect(service.state.context).toEqual({ answer: 42 });
});
});

0 comments on commit e16e48e

Please sign in to comment.