Replies: 2 comments
-
@ldadams I've got a similar use case, did ever find a good solution for this? |
Beta Was this translation helpful? Give feedback.
0 replies
-
You can use a pattern where you defer those actions: // global actions array
const actionFns = [];
function deferActionFn(actionFn) {
return () => actionFns.push(actionFn)
}
function executeActions() {
actionFns.forEach(actionFn => actionFn())
const machine = setup({
actions: {
doSomething: deferActionFn(() => {
// do something
}),
doSomethingElse: deferActionFn(() => {
// ...
})
}
});
const actor = createActor(machine);
actor.subscribe(snapshot => {
persistState(snapshot).then(executeActions);
});
actor.start(); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello xstate community! I have two kinda related questions.
Inbound Event -> Get Machine -> Hydrate Machine -> Send event to Machine -> Actions emit events -> Persist State
The problem I am encountering is around side effects of actions. Basically, services are responding to events before the previous state is persisted. This causes a race condition where a machine is hydrated with previous state.
I am looking for a way to capture / queue all the actions of a transition so that I can persist the state before executing them.
Thank you!!
Beta Was this translation helpful? Give feedback.
All reactions