-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
07d416e
commit 7dc7ceb
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--- | ||
'xstate': minor | ||
--- | ||
|
||
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. | ||
|
||
```ts | ||
// With `.preserveActionOrder: true` | ||
const machine = createMachine({ | ||
context: { count: 0 }, | ||
entry: [ | ||
(ctx) => console.log(ctx.count), // 0 | ||
assign({ count: (ctx) => ctx.count + 1 }), | ||
(ctx) => console.log(ctx.count), // 1 | ||
assign({ count: (ctx) => ctx.count + 1 }), | ||
(ctx) => console.log(ctx.count) // 2 | ||
], | ||
preserveActionOrder: true | ||
}); | ||
|
||
// With `.preserveActionOrder: false` (default) | ||
const machine = createMachine({ | ||
context: { count: 0 }, | ||
entry: [ | ||
(ctx) => console.log(ctx.count), // 2 | ||
assign({ count: (ctx) => ctx.count + 1 }), | ||
(ctx) => console.log(ctx.count), // 2 | ||
assign({ count: (ctx) => ctx.count + 1 }), | ||
(ctx) => console.log(ctx.count) // 2 | ||
] | ||
// preserveActionOrder: false | ||
}); | ||
``` |