You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is a new .preserveActionOrder (default: false) setting in the machine configuration that preserves the order of actions when set to true. Normally, actions are executed in order except for assign(...) actions, which are prioritized and executed first. When .preserveActionOrder is set to true, assign(...) actions will not be prioritized, and will instead run in order. As a result, actions will capture the intermediate context values instead of the resulting context value from all assign(...) actions.
Hence I am creating this issue to show the problem.
// Based on example from docs (https://xstate.js.org/docs/guides/context.html#action-order)constcounterMachine=createMachine<ToggleContext,ToggleEvent>({preserveActionOrder: true,// Ensures that assign actions are called in orderinitial: "active",// ...context: {count: 0},states: {active: {on: {INC_TWICE: {actions: [(context)=>console.log(`Before: ${context.count}`),// "Before: 0"assign((context)=>{console.log(`First assign`);return{ ...context,count: context.count+1};}),// count === 1assign((context)=>{console.log(`Second assign`);return{ ...context,count: context.count+1};}),// count === 2(context)=>console.log(`After: ${context.count}`)// "After: 2"]}}}}});interpret(counterMachine).start().send({type: "INC_TWICE"});
Description
I've initially created #3382 to show how
preserveActionOrder=true
is confusing because it only preserve the order of context and not the order of execution of actions.However, I am not sure anymore what is the intention of
preserveActionOrder
because it mentions the order of execution as described in (https://github.com/statelyai/xstate/blob/1d1c90c4be57e606975564114b7f23d951ad5ccb/packages/core/CHANGELOG.md#minor-changes-9):Hence I am creating this issue to show the problem.
Expected result
Actual result
Reproduction
https://codesandbox.io/s/stupefied-torvalds-mjjhi0
Additional context
xstate@4.31.0
The text was updated successfully, but these errors were encountered: