From e16e48e05e6243a3eacca58a13d3e663cd641f55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Wed, 22 Apr 2020 11:45:26 +0200 Subject: [PATCH] Fixed an issue with `choose` and `pure` not being able to use actions defined in options --- .changeset/tall-cars-provide.md | 5 +++++ packages/core/src/actions.ts | 4 ++-- packages/core/test/actions.test.ts | 27 +++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 .changeset/tall-cars-provide.md diff --git a/.changeset/tall-cars-provide.md b/.changeset/tall-cars-provide.md new file mode 100644 index 0000000000..be3926a2a7 --- /dev/null +++ b/.changeset/tall-cars-provide.md @@ -0,0 +1,5 @@ +--- +'xstate': patch +--- + +Fixed an issue with `choose` and `pure` not being able to use actions defined in options. diff --git a/packages/core/src/actions.ts b/packages/core/src/actions.ts index 1e51eb7afa..09b7083112 100644 --- a/packages/core/src/actions.ts +++ b/packages/core/src/actions.ts @@ -601,7 +601,7 @@ export function resolveActions( currentState, updatedContext, _event, - toActionObjects(toArray(matchedActions)) + toActionObjects(toArray(matchedActions), machine.options.actions) ); updatedContext = resolved[1]; return resolved[0]; @@ -619,7 +619,7 @@ export function resolveActions( currentState, updatedContext, _event, - toActionObjects(toArray(matchedActions)) + toActionObjects(toArray(matchedActions), machine.options.actions) ); updatedContext = resolved[1]; return resolved[0]; diff --git a/packages/core/test/actions.test.ts b/packages/core/test/actions.test.ts index 5c1603b142..89763b3751 100644 --- a/packages/core/test/actions.test.ts +++ b/packages/core/test/actions.test.ts @@ -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( + { + context: {}, + initial: 'foo', + states: { + foo: { + entry: choose([{ cond: () => true, actions: 'revealAnswer' }]) + } + } + }, + { + actions: { + revealAnswer: assign({ answer: 42 }) + } + } + ); + + const service = interpret(machine).start(); + + expect(service.state.context).toEqual({ answer: 42 }); + }); });