xstate 5.1.0 → 5.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +330 -123
  2. package/actions/dist/xstate-actions.cjs.js +2 -2
  3. package/actions/dist/xstate-actions.development.cjs.js +2 -2
  4. package/actions/dist/xstate-actions.development.esm.js +2 -2
  5. package/actions/dist/xstate-actions.esm.js +2 -2
  6. package/actions/dist/xstate-actions.umd.min.js +1 -1
  7. package/actions/dist/xstate-actions.umd.min.js.map +1 -1
  8. package/actors/dist/xstate-actors.cjs.js +1 -1
  9. package/actors/dist/xstate-actors.development.cjs.js +1 -1
  10. package/actors/dist/xstate-actors.development.esm.js +1 -1
  11. package/actors/dist/xstate-actors.esm.js +1 -1
  12. package/actors/dist/xstate-actors.umd.min.js +1 -1
  13. package/actors/dist/xstate-actors.umd.min.js.map +1 -1
  14. package/dist/declarations/src/index.d.ts +6 -5
  15. package/dist/declarations/src/spawn.d.ts +3 -2
  16. package/dist/declarations/src/toPromise.d.ts +24 -0
  17. package/dist/declarations/src/types.d.ts +2 -0
  18. package/dist/{log-6e1b5540.esm.js → log-5409ee89.esm.js} +4 -1
  19. package/dist/{log-2cbae8e5.development.esm.js → log-557e5fa3.development.esm.js} +4 -1
  20. package/dist/{log-dca6710c.cjs.js → log-74467f02.cjs.js} +4 -1
  21. package/dist/{log-aa639ffe.development.cjs.js → log-a56e34a9.development.cjs.js} +4 -1
  22. package/dist/{raise-dd0e6cd2.development.esm.js → raise-0ff85b7b.development.esm.js} +23 -5
  23. package/dist/{raise-525f78b5.esm.js → raise-5d7ae4b7.esm.js} +23 -5
  24. package/dist/{raise-23324e7c.development.cjs.js → raise-6fb30f8b.development.cjs.js} +22 -4
  25. package/dist/{raise-9f420f96.cjs.js → raise-746abff7.cjs.js} +22 -4
  26. package/dist/xstate.cjs.js +36 -2
  27. package/dist/xstate.cjs.mjs +1 -0
  28. package/dist/xstate.development.cjs.js +36 -2
  29. package/dist/xstate.development.cjs.mjs +1 -0
  30. package/dist/xstate.development.esm.js +38 -5
  31. package/dist/xstate.esm.js +38 -5
  32. package/dist/xstate.umd.min.js +1 -1
  33. package/dist/xstate.umd.min.js.map +1 -1
  34. package/guards/dist/xstate-guards.cjs.js +1 -1
  35. package/guards/dist/xstate-guards.development.cjs.js +1 -1
  36. package/guards/dist/xstate-guards.development.esm.js +1 -1
  37. package/guards/dist/xstate-guards.esm.js +1 -1
  38. package/package.json +1 -1
package/README.md CHANGED
@@ -1,29 +1,93 @@
1
1
  <p align="center">
2
- <a href="https://xstate.js.org">
3
2
  <br />
4
- <img src="https://i.imgur.com/FshbFOv.png" alt="XState" width="100"/>
3
+
4
+ <picture>
5
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/statelyai/public-assets/main/logos/xstate-logo-white-nobg.svg">
6
+ <img alt="XState logotype" src="https://raw.githubusercontent.com/statelyai/public-assets/main/logos/xstate-logo-black-nobg.svg" width="200">
7
+ </picture>
5
8
  <br />
6
- <sub><strong>JavaScript state machines and statecharts</strong></sub>
9
+ <strong>Actor-based state management & orchestration for complex app logic.</strong> <a href="https://stately.ai/docs">→ Documentation</a>
7
10
  <br />
8
11
  <br />
9
- </a>
10
12
  </p>
11
13
 
12
- [![npm version](https://badge.fury.io/js/xstate.svg)](https://badge.fury.io/js/xstate)
13
- [![Statecharts gitter chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/statecharts/statecharts)
14
- <img src="https://opencollective.com/xstate/tiers/backer/badge.svg?label=sponsors&color=brightgreen" />
14
+ XState is a state management and orchestration solution for JavaScript and TypeScript apps. It has _zero_ dependencies, and is useful for frontend and backend application logic.
15
15
 
16
- JavaScript and TypeScript [finite state machines](https://en.wikipedia.org/wiki/Finite-state_machine) and [statecharts](https://www.sciencedirect.com/science/article/pii/0167642387900359/pdf) for the modern web.
16
+ It uses event-driven programming, state machines, statecharts, and the actor model to handle complex logic in predictable, robust, and visual ways. XState provides a powerful and flexible way to manage application and workflow state by allowing developers to model logic as actors and state machines.
17
17
 
18
- 📖 [Read the documentation](https://xstate.js.org/docs)
19
- 📑 Inspired by the [SCXML specification](https://www.w3.org/TR/scxml/).
18
+ ### Create state machines visually in Stately Studio → [state.new](https://state.new)
20
19
 
21
- ## Packages
20
+ ---
21
+
22
+ 📖 [Read the documentation](https://stately.ai/docs)
23
+
24
+ ➡️ [Create state machines with the Stately Editor](https://stately.ai/editor)
25
+
26
+ 🖥 [Download our VS Code extension](https://marketplace.visualstudio.com/items?itemName=statelyai.stately-vscode)
27
+
28
+ 📑 Inspired by the [SCXML specification](https://www.w3.org/TR/scxml/)
29
+
30
+ 💬 Chat on the [Stately Discord Community](https://discord.gg/xstate)
31
+
32
+ ## Templates
33
+
34
+ Get started by forking one of these templates on CodeSandbox:
35
+
36
+ <table>
37
+ <thead>
38
+ <tr><th>Template</th><th></th></tr>
39
+ </thead>
40
+ <tbody>
41
+ <tr>
42
+ <td>
43
+
44
+ [🤖 XState Template (CodeSandbox)](https://codesandbox.io/p/devbox/github/statelyai/xstate/tree/main/templates/vanilla-ts)
45
+
46
+ [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/statelyai/xstate/tree/main/templates/vanilla-ts?file=%2Fsrc%2FfeedbackMachine.ts)
47
+
48
+ </td>
49
+ <td>
50
+
51
+ - XState v5
52
+ - TypeScript
53
+ - _No framework_
54
+
55
+ </td>
56
+ </tr>
57
+ <tr>
58
+ <td>
59
+
60
+ [⚛️ XState + React Template (CodeSandbox)](https://codesandbox.io/p/devbox/github/statelyai/xstate/tree/main/templates/react-ts)
61
+
62
+ [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/statelyai/xstate/tree/main/templates/react-ts?file=%2Fsrc%2FfeedbackMachine.ts)
63
+
64
+ </td>
65
+ <td>
66
+
67
+ - [React](https://react.dev/)
68
+ - XState v5
69
+ - TypeScript
70
+
71
+ </td>
72
+ </tr>
73
+ <tr>
74
+ <td>
75
+
76
+ [💚 XState + Vue Template (CodeSandbox)](https://codesandbox.io/p/devbox/github/statelyai/xstate/tree/main/templates/vue-ts)
77
+
78
+ [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/statelyai/xstate/tree/main/templates/vue-ts?file=%2Fsrc%2FfeedbackMachine.ts)
79
+
80
+ </td>
81
+ <td>
82
+
83
+ - [Vue](https://vuejs.org/)
84
+ - XState v5
85
+ - TypeScript
22
86
 
23
- - 🤖 `xstate` - Core finite state machine and statecharts library + interpreter
24
- - [📉 `@xstate/graph`](https://github.com/statelyai/xstate/tree/main/packages/xstate-graph) - Graph traversal utilities for XState
25
- - [⚛️ `@xstate/react`](https://github.com/statelyai/xstate/tree/main/packages/xstate-react) - React hooks and utilities for using XState in React applications
26
- - [✅ `@xstate/test`](https://github.com/statelyai/xstate/tree/main/packages/xstate-test) - Model-based testing utilities for XState
87
+ </td>
88
+ </tr>
89
+ </tbody>
90
+ </table>
27
91
 
28
92
  ## Super quick start
29
93
 
@@ -31,46 +95,57 @@ JavaScript and TypeScript [finite state machines](https://en.wikipedia.org/wiki/
31
95
  npm install xstate
32
96
  ```
33
97
 
34
- ```js
35
- import { createMachine, interpret } from 'xstate';
98
+ ```ts
99
+ import { createMachine, createActor, assign } from 'xstate';
36
100
 
37
- // Stateless machine definition
38
- // machine.transition(...) is a pure function used by the interpreter.
101
+ // State machine
39
102
  const toggleMachine = createMachine({
40
103
  id: 'toggle',
41
104
  initial: 'inactive',
105
+ context: {
106
+ count: 0
107
+ },
42
108
  states: {
43
- inactive: { on: { TOGGLE: 'active' } },
44
- active: { on: { TOGGLE: 'inactive' } }
109
+ inactive: {
110
+ on: {
111
+ TOGGLE: { target: 'active' }
112
+ }
113
+ },
114
+ active: {
115
+ entry: assign({ count: ({ context }) => context.count + 1 }),
116
+ on: {
117
+ TOGGLE: { target: 'inactive' }
118
+ }
119
+ }
45
120
  }
46
121
  });
47
122
 
48
- // Machine instance with internal state
49
- const toggleService = interpret(toggleMachine)
50
- .onTransition((state) => console.log(state.value))
51
- .start();
52
- // => 'inactive'
123
+ // Actor (instance of the machine logic, like a store)
124
+ const toggleActor = createActor(toggleMachine);
125
+ toggleActor.subscribe((state) => console.log(state.value, state.context));
126
+ toggleActor.start();
127
+ // => logs 'inactive', { count: 0 }
53
128
 
54
- toggleService.send({ type: 'TOGGLE' });
55
- // => 'active'
129
+ toggleActor.send({ type: 'TOGGLE' });
130
+ // => logs 'active', { count: 1 }
56
131
 
57
- toggleService.send({ type: 'TOGGLE' });
58
- // => 'inactive'
132
+ toggleActor.send({ type: 'TOGGLE' });
133
+ // => logs 'inactive', { count: 1 }
59
134
  ```
60
135
 
61
- - [Visualizer](#visualizer)
62
- - [Why? (info about statecharts)](#why)
63
- - [Installation](https://xstate.js.org/docs/guides/installation.html)
64
- - [Finite State Machines](#finite-state-machines)
65
- - [Hierarchical (Nested) State Machines](#hierarchical--nested--state-machines)
66
- - [Parallel State Machines](#parallel-state-machines)
67
- - [History States](#history-states)
136
+ ## [Stately Studio](https://stately.ai)
68
137
 
69
- ## Visualizer
138
+ - Visually create, edit, and collaborate on state machines
139
+ - Export to many formats, including XState v5
140
+ - Test path & documentation autogeneration
141
+ - Deploy to Stately Sky
142
+ - Generate & modify machines with Stately AI
70
143
 
71
- **[Visualize, simulate, and share your statecharts in XState Viz!](https://stately.ai/viz)**
144
+ <a href="stately.ai/registry/new?ref=github" title="Stately Studio">
145
+ <img src="https://github.com/statelyai/xstate/assets/1093738/74ed9cbc-b824-4ed7-a16d-f104947af8a7" alt="XState Viz" width="800" />
146
+ </a>
72
147
 
73
- <a href="https://stately.ai/viz" title="xstate visualizer"><img src="https://i.imgur.com/3pEB0B3.png" alt="xstate visualizer" width="300" /></a>
148
+ **[state.new](https://stately.ai/registry/new?ref=github)**
74
149
 
75
150
  ## Why?
76
151
 
@@ -80,17 +155,30 @@ Read [📽 the slides](http://slides.com/davidkhourshid/finite-state-machines) (
80
155
 
81
156
  - [Statecharts - A Visual Formalism for Complex Systems](https://www.sciencedirect.com/science/article/pii/0167642387900359/pdf) by David Harel
82
157
  - [The World of Statecharts](https://statecharts.github.io/) by Erik Mogensen
83
- - [Pure UI](https://rauchg.com/2015/pure-ui) by Guillermo Rauch
84
- - [Pure UI Control](https://medium.com/@asolove/pure-ui-control-ac8d1be97a8d) by Adam Solove
85
- - [Stately Discord](https://discord.gg/xstate) chat about anything related to statecharts and XState
86
- - [GitHub Discussions](https://github.com/statelyai/xstate/discussions)
158
+
159
+ ## Packages
160
+
161
+ | Package | Description |
162
+ | --------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
163
+ | 🤖 `xstate` | Core finite state machine and statecharts library + interpreter |
164
+ | [📉 `@xstate/graph`](https://github.com/statelyai/xstate/tree/main/packages/xstate-graph) | Graph traversal utilities for XState |
165
+ | [⚛️ `@xstate/react`](https://github.com/statelyai/xstate/tree/main/packages/xstate-react) | React hooks and utilities for using XState in React applications |
166
+ | [💚 `@xstate/vue`](https://github.com/statelyai/xstate/tree/main/packages/xstate-vue) | Vue composition functions and utilities for using XState in Vue applications |
167
+ | [🎷 `@xstate/svelte`](https://github.com/statelyai/xstate/tree/main/packages/xstate-svelte) | Svelte utilities for using XState in Svelte applications |
168
+ | [🥏 `@xstate/solid`](https://github.com/statelyai/xstate/tree/main/packages/xstate-solid) | Solid hooks and utilities for using XState in Solid applications |
169
+ | [✅ `@xstate/test`](https://github.com/statelyai/xstate/tree/main/packages/xstate-test) | Model-Based-Testing utilities (using XState) for testing any software |
170
+ | [🔍 `@xstate/inspect`](https://github.com/statelyai/xstate/tree/main/packages/xstate-inspect) | Inspection utilities for XState |
87
171
 
88
172
  ## Finite State Machines
89
173
 
90
- <img src="https://imgur.com/rqqmkJh.png" alt="Light Machine" width="300" />
174
+ <table>
175
+ <thead><tr><th>Code</th><th>Statechart</th></tr></thead>
176
+ <tbody>
177
+ <tr>
178
+ <td>
91
179
 
92
180
  ```js
93
- import { createMachine } from 'xstate';
181
+ import { createMachine, createActor } from 'xstate';
94
182
 
95
183
  const lightMachine = createMachine({
96
184
  id: 'light',
@@ -114,21 +202,57 @@ const lightMachine = createMachine({
114
202
  }
115
203
  });
116
204
 
117
- const currentState = 'green';
205
+ const actor = createActor(lightMachine);
206
+
207
+ actor.subscribe((state) => {
208
+ console.log(state.value);
209
+ });
118
210
 
119
- const nextState = lightMachine.transition(currentState, {
120
- type: 'TIMER'
121
- }).value;
211
+ actor.start();
212
+ // logs 'green'
122
213
 
123
- // => 'yellow'
214
+ actor.send({ type: 'TIMER' });
215
+ // logs 'yellow'
124
216
  ```
125
217
 
218
+ <table>
219
+ <thead><tr><th>Code</th><th>Statechart</th></tr></thead>
220
+ <tbody>
221
+ <tr>
222
+ <td>
223
+
224
+ </td>
225
+ <td>
226
+
227
+ </td>
228
+ </tr>
229
+ </tbody>
230
+ </table>
231
+
232
+ </td>
233
+ <td>
234
+
235
+ <a href="https://stately.ai/registry/editor/fa443471-b416-4014-8e6f-12417863e4d4?mode=design&machineId=27e86036-f2f7-40f1-9d1e-66ce6e1accc0" title="Finite states">
236
+ <img src="https://github.com/statelyai/xstate/assets/1093738/36d4b6b5-e3d0-4c19-9f41-2e3425ceac88" alt="Finite states" width="400" />
237
+ <br />
238
+ Open in Stately Studio
239
+ </a>
240
+ <br />
241
+
242
+ </td>
243
+ </tbody>
244
+ </table>
245
+
126
246
  ## Hierarchical (Nested) State Machines
127
247
 
128
- <img src="https://imgur.com/GDZAeB9.png" alt="Hierarchical Light Machine" width="300" />
248
+ <table>
249
+ <thead><tr><th>Code</th><th>Statechart</th></tr></thead>
250
+ <tbody>
251
+ <tr>
252
+ <td>
129
253
 
130
254
  ```js
131
- import { createMachine } from 'xstate';
255
+ import { createMachine, createActor } from 'xstate';
132
256
 
133
257
  const pedestrianStates = {
134
258
  initial: 'walk',
@@ -170,46 +294,49 @@ const lightMachine = createMachine({
170
294
  }
171
295
  });
172
296
 
173
- const currentState = 'yellow';
174
-
175
- const nextState = lightMachine.transition(currentState, {
176
- type: 'TIMER'
177
- }).value;
178
- // => {
179
- // red: 'walk'
180
- // }
181
-
182
- lightMachine.transition('red.walk', { type: 'PED_TIMER' }).value;
183
- // => {
184
- // red: 'wait'
185
- // }
186
- ```
187
-
188
- **Object notation for hierarchical states:**
189
-
190
- ```js
191
- // ...
192
- const waitState = lightMachine.transition(
193
- { red: 'walk' },
194
- { type: 'PED_TIMER' }
195
- ).value;
297
+ const actor = createActor(lightMachine);
196
298
 
197
- // => { red: 'wait' }
299
+ actor.subscribe((state) => {
300
+ console.log(state.value);
301
+ });
198
302
 
199
- lightMachine.transition(waitState, { type: 'PED_TIMER' }).value;
303
+ actor.start();
304
+ // logs 'green'
200
305
 
201
- // => { red: 'stop' }
306
+ actor.send({ type: 'TIMER' });
307
+ // logs 'yellow'
202
308
 
203
- lightMachine.transition({ red: 'stop' }, { type: 'TIMER' }).value;
309
+ actor.send({ type: 'TIMER' });
310
+ // logs { red: 'walk' }
204
311
 
205
- // => 'green'
312
+ actor.send({ type: 'PED_TIMER' });
313
+ // logs { red: 'wait' }
206
314
  ```
207
315
 
316
+ </td>
317
+ <td>
318
+ <a href="https://stately.ai/registry/editor/fa443471-b416-4014-8e6f-12417863e4d4?mode=design&machineId=30dffcdd-16c2-49e2-bfc6-a674057cb271" title="Hierarchical states">
319
+ <img src="https://github.com/statelyai/xstate/assets/1093738/32b0692b-1c29-4469-b5e3-03146e3ef249" alt="Hierarchical states" width="400" />
320
+ <br />
321
+ Open in Stately Studio
322
+ </a>
323
+ <br />
324
+ </td>
325
+ </tr>
326
+ </tbody>
327
+ </table>
328
+
208
329
  ## Parallel State Machines
209
330
 
210
- <img src="https://imgur.com/GKd4HwR.png" width="300" alt="Parallel state machine" />
331
+ <table>
332
+ <thead><tr><th>Code</th><th>Statechart</th></tr></thead>
333
+ <tbody>
334
+ <tr>
335
+ <td>
336
+
337
+ ```ts
338
+ import { createMachine, createActor } from 'xstate';
211
339
 
212
- ```js
213
340
  const wordMachine = createMachine({
214
341
  id: 'word',
215
342
  type: 'parallel',
@@ -251,53 +378,82 @@ const wordMachine = createMachine({
251
378
  initial: 'none',
252
379
  states: {
253
380
  none: {
254
- on: { BULLETS: 'bullets', NUMBERS: 'numbers' }
381
+ on: {
382
+ BULLETS: 'bullets',
383
+ NUMBERS: 'numbers'
384
+ }
255
385
  },
256
386
  bullets: {
257
- on: { NONE: 'none', NUMBERS: 'numbers' }
387
+ on: {
388
+ NONE: 'none',
389
+ NUMBERS: 'numbers'
390
+ }
258
391
  },
259
392
  numbers: {
260
- on: { BULLETS: 'bullets', NONE: 'none' }
393
+ on: {
394
+ BULLETS: 'bullets',
395
+ NONE: 'none'
396
+ }
261
397
  }
262
398
  }
263
399
  }
264
400
  }
265
401
  });
266
402
 
267
- const boldState = wordMachine.transition('bold.off', {
268
- type: 'TOGGLE_BOLD'
269
- }).value;
403
+ const actor = createActor(wordMachine);
270
404
 
271
- // {
272
- // bold: 'on',
405
+ actor.subscribe((state) => {
406
+ console.log(state.value);
407
+ });
408
+
409
+ actor.start();
410
+ // logs {
411
+ // bold: 'off',
273
412
  // italics: 'off',
274
413
  // underline: 'off',
275
414
  // list: 'none'
276
415
  // }
277
416
 
278
- const nextState = wordMachine.transition(
279
- {
280
- bold: 'off',
281
- italics: 'off',
282
- underline: 'on',
283
- list: 'bullets'
284
- },
285
- { type: 'TOGGLE_ITALICS' }
286
- ).value;
417
+ actor.send({ type: 'TOGGLE_BOLD' });
418
+ // logs {
419
+ // bold: 'on',
420
+ // italics: 'off',
421
+ // underline: 'off',
422
+ // list: 'none'
423
+ // }
287
424
 
288
- // {
289
- // bold: 'off',
425
+ actor.send({ type: 'TOGGLE_ITALICS' });
426
+ // logs {
427
+ // bold: 'on',
290
428
  // italics: 'on',
291
- // underline: 'on',
292
- // list: 'bullets'
429
+ // underline: 'off',
430
+ // list: 'none'
293
431
  // }
294
432
  ```
295
433
 
434
+ </td>
435
+ <td>
436
+ <a href="https://stately.ai/registry/editor/fa443471-b416-4014-8e6f-12417863e4d4?mode=design&machineId=980f50d8-e1ff-4441-8c8b-afe41c1610f2" title="Parallel states">
437
+ <img src="https://github.com/statelyai/xstate/assets/1093738/3b1989c0-f4a9-4653-baf2-4df3a40e91a6" alt="Parallel states" width="400" />
438
+ <br />
439
+ Open in Stately Studio
440
+ </a>
441
+ </td>
442
+ </tr>
443
+ </tbody>
444
+ </table>
445
+
296
446
  ## History States
297
447
 
298
- <img src="https://imgur.com/I4QsQsz.png" width="300" alt="Machine with history state" />
448
+ <table>
449
+ <thead><tr><th>Code</th><th>Statechart</th></tr></thead>
450
+ <tbody>
451
+ <tr>
452
+ <td>
299
453
 
300
454
  ```js
455
+ import { createMachine, createActor } from 'xstate';
456
+
301
457
  const paymentMachine = createMachine({
302
458
  id: 'payment',
303
459
  initial: 'method',
@@ -305,8 +461,16 @@ const paymentMachine = createMachine({
305
461
  method: {
306
462
  initial: 'cash',
307
463
  states: {
308
- cash: { on: { SWITCH_CHECK: 'check' } },
309
- check: { on: { SWITCH_CASH: 'cash' } },
464
+ cash: {
465
+ on: {
466
+ SWITCH_CHECK: 'check'
467
+ }
468
+ },
469
+ check: {
470
+ on: {
471
+ SWITCH_CASH: 'cash'
472
+ }
473
+ },
310
474
  hist: { type: 'history' }
311
475
  },
312
476
  on: { NEXT: 'review' }
@@ -317,32 +481,75 @@ const paymentMachine = createMachine({
317
481
  }
318
482
  });
319
483
 
320
- const checkState = paymentMachine.transition('method.cash', {
321
- type: 'SWITCH_CHECK'
484
+ const actor = createActor(paymentMachine);
485
+
486
+ actor.subscribe((state) => {
487
+ console.log(state.value);
322
488
  });
323
489
 
324
- // => State {
325
- // value: { method: 'check' },
326
- // history: State { ... }
490
+ actor.start();
491
+ // logs {
492
+ // value: { method: 'cash' },
327
493
  // }
328
494
 
329
- const reviewState = paymentMachine.transition(checkState, { type: 'NEXT' });
495
+ actor.send({ type: 'SWITCH_CHECK' });
496
+ // logs {
497
+ // value: { method: 'check' },
498
+ // }
330
499
 
331
- // => State {
500
+ actor.send({ type: 'NEXT' });
501
+ // logs {
332
502
  // value: 'review',
333
- // history: State { ... }
334
503
  // }
335
504
 
336
- const previousState = paymentMachine.transition(reviewState, {
337
- type: 'PREVIOUS'
338
- }).value;
339
-
340
- // => { method: 'check' }
505
+ actor.send({ type: 'PREVIOUS' });
506
+ // logs {
507
+ // value: { method: 'check' },
508
+ // }
341
509
  ```
342
510
 
511
+ </td>
512
+ <td>
513
+ <a href="https://stately.ai/registry/editor/fa443471-b416-4014-8e6f-12417863e4d4?mode=design&machineId=d1a9bb95-db97-4af3-b38b-71b005c643d3" title="History states">
514
+ <img src="https://github.com/statelyai/xstate/assets/1093738/1be5c495-d560-4660-94f2-5341efbf7128" alt="History state" width="400" />
515
+ <br />
516
+ Open in Stately Studio
517
+ </a>
518
+ </td>
519
+ </tr>
520
+ </tbody>
521
+ </table>
522
+
343
523
  ## Sponsors
344
524
 
345
- Huge thanks to the following companies for sponsoring `xstate`. You can sponsor further `xstate` development [on OpenCollective](https://opencollective.com/xstate).
525
+ Special thanks to the sponsors who support this open-source project:
526
+
527
+ <img src="https://opencollective.com/xstate/tiers/backer/badge.svg?label=sponsors&color=brightgreen" />
528
+
529
+ <a href="https://transloadit.com/?utm_source=xstate&utm_medium=referral&utm_campaign=sponsorship&utm_content=github">
530
+ <picture>
531
+ <source media="(prefers-color-scheme: dark)" srcset="https://assets.transloadit.com/assets/images/sponsorships/logo-dark.svg">
532
+ <source media="(prefers-color-scheme: light)" srcset="https://assets.transloadit.com/assets/images/sponsorships/logo-default.svg">
533
+ <img src="https://assets.transloadit.com/assets/images/sponsorships/logo-default.svg" alt="Transloadit Logo">
534
+ </picture>
535
+ </a>
536
+
537
+ ## SemVer Policy
538
+
539
+ We understand the importance of the public contract and do not intend to release any breaking changes to the **runtime** API in a minor or patch release. We consider this with any changes we make to the XState libraries and aim to minimize their effects on existing users.
540
+
541
+ ### Breaking changes
542
+
543
+ XState executes much of the user logic itself. Therefore, almost any change to its behavior might be considered a breaking change. We recognize this as a potential problem but believe that treating every change as a breaking change is not practical. We do our best to implement new features thoughtfully to enable our users to implement their logic in a better, safer way.
544
+
545
+ Any change _could_ affect how existing XState machines behave if those machines are using particular configurations. We do not introduce behavior changes on a whim and aim to avoid making changes that affect most existing machines. But we reserve the right to make _some_ behavior changes in minor releases. Our best judgment of the situation will always dictate such changes. Please always read our release notes before deciding to upgrade.
546
+
547
+ ### TypeScript changes
548
+
549
+ We also reserve a similar right to adjust declared TypeScript definitions or drop support for older versions of TypeScript in a minor release. The TypeScript language itself evolves quickly and often introduces breaking changes in its minor releases. Our team is also continuously learning how to leverage TypeScript more effectively - and the types improve as a result.
550
+
551
+ For these reasons, it is impractical for our team to be bound by decisions taken when an older version of TypeScript was its latest version or when we didn’t know how to declare our types in a better way. We won’t introduce declaration changes often - but we are more likely to do so than with runtime changes.
552
+
553
+ ### Packages
346
554
 
347
- <a href="https://tipe.io" title="Tipe.io"><img src="https://cdn.tipe.io/tipe/tipe-logo.svg?w=240" style="background:#613DEF" /></a>
348
- <a href="https://webflow.com" title="Webflow"><img src="https://uploads-ssl.webflow.com/583347ca8f6c7ee058111b3b/5b03bde0971fdd75d75b5591_webflow.png" height="100" /></a>
555
+ Most of the packages in the XState family declare a peer dependency on XState itself. We’ll be cautious about maintaining compatibility with already-released packages when releasing a new version of XState, **but** each release of packages depending on XState will always adjust the declared peer dependency range to include the latest version of XState. For example, you should always be able to update `xstate` without `@xstate/react`. But when you update `@xstate/react`, we highly recommend updating `xstate` too.
@@ -2,8 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var log = require('../../dist/log-dca6710c.cjs.js');
6
- var guards_dist_xstateGuards = require('../../dist/raise-9f420f96.cjs.js');
5
+ var log = require('../../dist/log-74467f02.cjs.js');
6
+ var guards_dist_xstateGuards = require('../../dist/raise-746abff7.cjs.js');
7
7
  require('../../dev/dist/xstate-dev.cjs.js');
8
8
 
9
9
 
@@ -2,8 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var log = require('../../dist/log-aa639ffe.development.cjs.js');
6
- var guards_dist_xstateGuards = require('../../dist/raise-23324e7c.development.cjs.js');
5
+ var log = require('../../dist/log-a56e34a9.development.cjs.js');
6
+ var guards_dist_xstateGuards = require('../../dist/raise-6fb30f8b.development.cjs.js');
7
7
  require('../../dev/dist/xstate-dev.development.cjs.js');
8
8
 
9
9
 
@@ -1,3 +1,3 @@
1
- export { a as assign, e as enqueueActions, f as forwardTo, l as log, s as sendParent, b as sendTo } from '../../dist/log-2cbae8e5.development.esm.js';
2
- export { L as cancel, M as raise, O as spawnChild, P as stop, Q as stopChild } from '../../dist/raise-dd0e6cd2.development.esm.js';
1
+ export { a as assign, e as enqueueActions, f as forwardTo, l as log, s as sendParent, b as sendTo } from '../../dist/log-557e5fa3.development.esm.js';
2
+ export { L as cancel, M as raise, O as spawnChild, P as stop, Q as stopChild } from '../../dist/raise-0ff85b7b.development.esm.js';
3
3
  import '../../dev/dist/xstate-dev.development.esm.js';
@@ -1,3 +1,3 @@
1
- export { a as assign, e as enqueueActions, f as forwardTo, l as log, s as sendParent, b as sendTo } from '../../dist/log-6e1b5540.esm.js';
2
- export { L as cancel, M as raise, O as spawnChild, P as stop, Q as stopChild } from '../../dist/raise-525f78b5.esm.js';
1
+ export { a as assign, e as enqueueActions, f as forwardTo, l as log, s as sendParent, b as sendTo } from '../../dist/log-5409ee89.esm.js';
2
+ export { L as cancel, M as raise, O as spawnChild, P as stop, Q as stopChild } from '../../dist/raise-5d7ae4b7.esm.js';
3
3
  import '../../dev/dist/xstate-dev.esm.js';