Skip to content

Commit

Permalink
Add changeset
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkpiano committed Jul 12, 2021
1 parent 07d416e commit 7dc7ceb
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .changeset/chatty-spiders-suffer.md
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
});
```

0 comments on commit 7dc7ceb

Please sign in to comment.