[v5] enqueueActions() (replaces pure() and choose())#4429
Conversation
🦋 Changeset detectedLatest commit: 25fdbf9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 25fdbf9:
|
packages/core/test/actions.test.ts
Outdated
| if (guard({ type: 'worstGuard' })) { | ||
| exec.action({ type: 'revealAnswer' }); | ||
| } |
There was a problem hiding this comment.
I love this. A little more verbose but feels more natural than choose
|
I love this, is there any conversation or references anywhere about where it came from? |
Some conversation here: https://discord.com/channels/795785288994652170/1169717611416789083 It builds up from previous discussions about a |
|
How will it behave with async logic? I imagine new users will attempt something like this: actions: createAction(async ({ context, event, exec }) => {
exec.assign({ isFetching: true });
const res = await fetchTodos(1000);
exec.assign({ todos: res.data, isFetching: false });
}) |
|
Async logic would not be permitted here |
Sounds perfect to me 👌 Also, I'm curious, what is the reason behind using Are they just shortcuts for better DX? While I do like it, I wonder about the case of using a custom assign, like @xstate/immer. Without the shortcuts, it's one less thing to think about. import { assign } from '@xstate/immer';
//...
actions: [
// a custom assign imported from "@xstate/immer"
assign(({ context }) => {
context.value = 'foo';
}),
createAction(({ context, event, exec }) => {
// The assign we're using for the rest of the machine
exec(assign({
count: context.count + 1
}));
})
]What do you think? |
Makes typing stronger; no need to infer types, which isn't perfect. We can strongly type |
createAction() (replaces pure() and choose())enqueueActions() (replaces pure() and choose())
Note that this should still "just work" - so you can very much do this. |
Uh oh!
There was an error while loading. Please reload this page.