xstate 6.0.0-alpha.7 → 6.0.0-alpha.71

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 (216) hide show
  1. package/README.md +206 -67
  2. package/bin/agent.js +347 -0
  3. package/bin/xstate.js +52 -0
  4. package/dist/createActor-2136a8ad.development.cjs.js +7110 -0
  5. package/dist/createActor-22a0534b.esm.js +6783 -0
  6. package/dist/createActor-286a0dbb.development.esm.js +6999 -0
  7. package/dist/createActor-f4978450.cjs.js +6893 -0
  8. package/dist/declarations/src/SimulatedClock.d.ts +2 -1
  9. package/dist/declarations/src/State.d.ts +66 -5
  10. package/dist/declarations/src/StateMachine.d.ts +135 -30
  11. package/dist/declarations/src/StateNode.d.ts +21 -16
  12. package/dist/declarations/src/actions.d.ts +11 -6
  13. package/dist/declarations/src/actors/callback.d.ts +11 -2
  14. package/dist/declarations/src/actors/index.d.ts +6 -5
  15. package/dist/declarations/src/actors/listener.d.ts +8 -3
  16. package/dist/declarations/src/actors/logic.d.ts +42 -52
  17. package/dist/declarations/src/actors/observable.d.ts +15 -2
  18. package/dist/declarations/src/actors/promise.d.ts +90 -22
  19. package/dist/declarations/src/actors/subscription.d.ts +9 -3
  20. package/dist/declarations/src/assert.d.ts +1 -0
  21. package/dist/declarations/src/base.types.d.ts +102 -0
  22. package/dist/declarations/src/createActor.d.ts +104 -27
  23. package/dist/declarations/src/createMachine.d.ts +37 -16
  24. package/dist/declarations/src/delay.d.ts +8 -0
  25. package/dist/declarations/src/durable/index.d.ts +222 -0
  26. package/dist/declarations/src/effectDescriptor.d.ts +95 -0
  27. package/dist/declarations/src/eventTypes.d.ts +9 -0
  28. package/dist/declarations/src/fsm/index.d.ts +2 -0
  29. package/dist/declarations/src/fsm.d.ts +169 -0
  30. package/dist/declarations/src/graph/adjacency.d.ts +6 -3
  31. package/dist/declarations/src/graph/graph.d.ts +6 -3
  32. package/dist/declarations/src/graph/index.d.ts +2 -3
  33. package/dist/declarations/src/graph/pathFromEvents.d.ts +5 -2
  34. package/dist/declarations/src/graph/shortestPaths.d.ts +5 -3
  35. package/dist/declarations/src/graph/simplePaths.d.ts +5 -3
  36. package/dist/declarations/src/graph/types.d.ts +113 -59
  37. package/dist/declarations/src/hotSwap.d.ts +18 -0
  38. package/dist/declarations/src/index.d.ts +27 -19
  39. package/dist/declarations/src/inspection.d.ts +24 -1
  40. package/dist/declarations/src/machineFromJSON.d.ts +171 -0
  41. package/dist/declarations/src/machineVersion.types.d.ts +53 -0
  42. package/dist/declarations/src/machineVersions.d.ts +105 -0
  43. package/dist/declarations/src/mapState.d.ts +2 -0
  44. package/dist/declarations/src/runtimeHelpers.d.ts +43 -0
  45. package/dist/declarations/src/schema.types.d.ts +31 -4
  46. package/dist/declarations/src/serialize.d.ts +39 -27
  47. package/dist/declarations/src/setup.d.ts +1091 -146
  48. package/dist/declarations/src/spawn.d.ts +6 -4
  49. package/dist/declarations/src/stateUtils.d.ts +57 -14
  50. package/dist/declarations/src/system.d.ts +178 -17
  51. package/dist/declarations/src/systemTransition.d.ts +108 -0
  52. package/dist/declarations/src/toPromise.d.ts +1 -0
  53. package/dist/declarations/src/transition.d.ts +48 -10
  54. package/dist/declarations/src/transitionActions.d.ts +22 -4
  55. package/dist/declarations/src/typeUtils.d.ts +52 -0
  56. package/dist/declarations/src/types.d.ts +842 -297
  57. package/dist/declarations/src/types.v6.d.ts +543 -101
  58. package/dist/declarations/src/utils.d.ts +39 -8
  59. package/dist/declarations/src/validation/index.d.ts +49 -0
  60. package/dist/declarations/src/validation.types.d.ts +29 -0
  61. package/dist/declarations/src/waitFor.d.ts +1 -0
  62. package/dist/effectDescriptor-2ae7e5e3.esm.js +343 -0
  63. package/dist/effectDescriptor-86f04325.development.esm.js +343 -0
  64. package/dist/effectDescriptor-a6247f92.cjs.js +351 -0
  65. package/dist/effectDescriptor-e41e1627.development.cjs.js +351 -0
  66. package/dist/index-31b3c878.cjs.js +1078 -0
  67. package/dist/index-5ce9cbf9.development.cjs.js +1078 -0
  68. package/dist/index-6923de25.development.esm.js +1069 -0
  69. package/dist/index-74b77771.esm.js +1069 -0
  70. package/dist/schema.types-0ecd17b8.esm.js +71 -0
  71. package/dist/schema.types-15a68ddc.cjs.js +74 -0
  72. package/dist/schema.types-1c16f035.development.cjs.js +74 -0
  73. package/dist/schema.types-1cd4652e.development.esm.js +71 -0
  74. package/dist/xstate-actors.cjs.js +5 -6
  75. package/dist/xstate-actors.cjs.mjs +2 -4
  76. package/dist/xstate-actors.development.cjs.js +5 -6
  77. package/dist/xstate-actors.development.cjs.mjs +2 -4
  78. package/dist/xstate-actors.development.esm.js +2 -1
  79. package/dist/xstate-actors.esm.js +2 -1
  80. package/dist/xstate-actors.umd.min.js +1 -1
  81. package/dist/xstate-actors.umd.min.js.map +1 -1
  82. package/dist/xstate-durable.cjs.d.mts +2 -0
  83. package/dist/xstate-durable.cjs.d.ts +2 -0
  84. package/dist/xstate-durable.cjs.js +513 -0
  85. package/dist/xstate-durable.cjs.mjs +5 -0
  86. package/dist/xstate-durable.development.cjs.js +513 -0
  87. package/dist/xstate-durable.development.cjs.mjs +5 -0
  88. package/dist/xstate-durable.development.esm.js +507 -0
  89. package/dist/xstate-durable.esm.js +507 -0
  90. package/dist/xstate-durable.umd.min.js +2 -0
  91. package/dist/xstate-durable.umd.min.js.map +1 -0
  92. package/dist/xstate-fsm.cjs.d.mts +2 -0
  93. package/dist/xstate-fsm.cjs.d.ts +2 -0
  94. package/dist/xstate-fsm.cjs.js +111 -0
  95. package/dist/xstate-fsm.cjs.mjs +5 -0
  96. package/dist/xstate-fsm.development.cjs.js +111 -0
  97. package/dist/xstate-fsm.development.cjs.mjs +5 -0
  98. package/dist/xstate-fsm.development.esm.js +105 -0
  99. package/dist/xstate-fsm.esm.js +105 -0
  100. package/dist/xstate-fsm.umd.min.js +2 -0
  101. package/dist/xstate-fsm.umd.min.js.map +1 -0
  102. package/dist/xstate-graph.cjs.js +172 -457
  103. package/dist/xstate-graph.cjs.mjs +2 -5
  104. package/dist/xstate-graph.development.cjs.js +172 -457
  105. package/dist/xstate-graph.development.cjs.mjs +2 -5
  106. package/dist/xstate-graph.development.esm.js +170 -451
  107. package/dist/xstate-graph.esm.js +170 -451
  108. package/dist/xstate-graph.umd.min.js +1 -1
  109. package/dist/xstate-graph.umd.min.js.map +1 -1
  110. package/dist/xstate-validation.cjs.d.mts +2 -0
  111. package/dist/xstate-validation.cjs.d.ts +2 -0
  112. package/dist/xstate-validation.cjs.js +330 -0
  113. package/dist/xstate-validation.cjs.mjs +5 -0
  114. package/dist/xstate-validation.development.cjs.js +330 -0
  115. package/dist/xstate-validation.development.cjs.mjs +5 -0
  116. package/dist/xstate-validation.development.esm.js +324 -0
  117. package/dist/xstate-validation.esm.js +324 -0
  118. package/dist/xstate-validation.umd.min.js +2 -0
  119. package/dist/xstate-validation.umd.min.js.map +1 -0
  120. package/dist/xstate.cjs.js +4099 -1534
  121. package/dist/xstate.cjs.mjs +22 -13
  122. package/dist/xstate.development.cjs.js +4251 -1479
  123. package/dist/xstate.development.cjs.mjs +22 -13
  124. package/dist/xstate.development.esm.js +4212 -1449
  125. package/dist/xstate.esm.js +3996 -1440
  126. package/dist/xstate.umd.min.js +1 -1
  127. package/dist/xstate.umd.min.js.map +1 -1
  128. package/docs/actions.md +75 -0
  129. package/docs/actor-logic.md +250 -0
  130. package/docs/actors.md +64 -0
  131. package/docs/agents.md +132 -0
  132. package/docs/api-stability.json +3672 -0
  133. package/docs/async-logic.md +75 -0
  134. package/docs/async-requests.md +157 -0
  135. package/docs/backend-workflows.md +121 -0
  136. package/docs/cancellation.md +42 -0
  137. package/docs/cheatsheet.md +561 -0
  138. package/docs/choice-states.md +109 -0
  139. package/docs/choose-xstate.md +47 -0
  140. package/docs/configuration.md +161 -0
  141. package/docs/context.md +67 -0
  142. package/docs/create-actor.md +157 -0
  143. package/docs/data-and-effects.md +48 -0
  144. package/docs/delays.md +81 -0
  145. package/docs/durable-execution.md +510 -0
  146. package/docs/emitted-events.md +146 -0
  147. package/docs/examples.md +75 -0
  148. package/docs/faq.md +60 -0
  149. package/docs/final-states.md +149 -0
  150. package/docs/forms-and-wizards.md +166 -0
  151. package/docs/frameworks.md +69 -0
  152. package/docs/fsm.md +164 -0
  153. package/docs/glossary.md +68 -0
  154. package/docs/guards.md +137 -0
  155. package/docs/history-states.md +159 -0
  156. package/docs/how-xstate-runs-machines.md +84 -0
  157. package/docs/index.md +73 -0
  158. package/docs/input-output.md +69 -0
  159. package/docs/inspect-actor-systems.md +116 -0
  160. package/docs/inspection.md +73 -0
  161. package/docs/internal-events.md +156 -0
  162. package/docs/invoke.md +354 -0
  163. package/docs/lifecycle-and-errors.md +48 -0
  164. package/docs/listen-and-subscribe.md +126 -0
  165. package/docs/model-based-testing.md +321 -0
  166. package/docs/modeling.md +40 -0
  167. package/docs/parallel-states.md +182 -0
  168. package/docs/persist-and-restore-actors.md +115 -0
  169. package/docs/persistence.md +325 -0
  170. package/docs/quick-start.md +55 -0
  171. package/docs/retries-and-timeouts.md +122 -0
  172. package/docs/route-states.md +104 -0
  173. package/docs/scxml.md +91 -0
  174. package/docs/selectors.md +99 -0
  175. package/docs/serialization.md +127 -0
  176. package/docs/setup-and-provide.md +271 -0
  177. package/docs/snapshots.md +134 -0
  178. package/docs/spawn.md +220 -0
  179. package/docs/state-input.md +162 -0
  180. package/docs/statecharts.md +54 -0
  181. package/docs/states-events-transitions.md +82 -0
  182. package/docs/states.md +168 -0
  183. package/docs/system-transitions.md +170 -0
  184. package/docs/systems.md +166 -0
  185. package/docs/testing.md +150 -0
  186. package/docs/timeouts.md +125 -0
  187. package/docs/transition-functions.md +89 -0
  188. package/docs/transitions.md +187 -0
  189. package/docs/troubleshooting.md +48 -0
  190. package/docs/tutorial.md +481 -0
  191. package/docs/typescript.md +211 -0
  192. package/docs/typestates.md +110 -0
  193. package/docs/utilities.md +39 -0
  194. package/docs/why-state-machines.md +59 -0
  195. package/docs/xstate-v5-to-v6.md +1771 -0
  196. package/docs/your-first-machine.md +79 -0
  197. package/durable/package.json +8 -0
  198. package/fsm/package.json +8 -0
  199. package/package.json +56 -10
  200. package/validation/package.json +8 -0
  201. package/actions/package.json +0 -8
  202. package/dev/package.json +0 -8
  203. package/dist/StateMachine-1ff90553.esm.js +0 -729
  204. package/dist/StateMachine-2b259bff.development.esm.js +0 -746
  205. package/dist/StateMachine-6673bf76.cjs.js +0 -732
  206. package/dist/StateMachine-68fe6077.development.cjs.js +0 -749
  207. package/dist/declarations/src/createMachineFromConfig.d.ts +0 -177
  208. package/dist/declarations/src/getNextSnapshot.d.ts +0 -37
  209. package/dist/declarations/src/graph/TestModel.d.ts +0 -70
  210. package/dist/declarations/src/graph/pathGenerators.d.ts +0 -4
  211. package/dist/index-87499be0.cjs.js +0 -4415
  212. package/dist/index-9594f050.development.esm.js +0 -4399
  213. package/dist/index-aaf74d09.esm.js +0 -4360
  214. package/dist/index-b063a967.development.cjs.js +0 -4454
  215. package/guards/package.json +0 -8
  216. package/invoke/package.json +0 -4
package/README.md CHANGED
@@ -1,3 +1,78 @@
1
+ # XState v6
2
+
3
+ This package contains **XState v6 alpha**. Its APIs differ from v5.
4
+
5
+ <!-- bundled documentation generated by scripts/build-package-docs.mjs from docs/meta.json -->
6
+
7
+ Before writing code with an installed package, read `docs/index.md` beside this
8
+ README, usually `node_modules/xstate/docs/index.md`. These bundled docs match the
9
+ installed package version.
10
+
11
+ For coding agents, start with `docs/agents.md`. Run `npx xstate docs` to locate
12
+ the installed documentation and read its machine-readable stability manifest.
13
+ The data-only CLI also supports `inspect`, `validate`, `simulate`, `test`,
14
+ `replay` and `diff`; see the agent guide for their contracts and limits.
15
+
16
+ Online, start with the [quick start](https://github.com/statelyai/xstate/blob/next/docs/quick-start.md)
17
+ or the [v5 to v6 migration guide](https://github.com/statelyai/xstate/blob/next/docs/xstate-v5-to-v6.md).
18
+
19
+ <!-- v6 authoring replacements from src/index.ts, src/transitionActions.ts and src/types.ts -->
20
+
21
+ | XState v5 | XState v6 |
22
+ | --- | --- |
23
+ | `assign(...)` | Return a shallow `{ context: { ... } }` patch from a transition, entry or exit function. |
24
+ | `fromPromise(fn)` | `createAsyncLogic({ run: fn })` from `xstate`. |
25
+ | `types: {} as { ... }` | `schemas` with `types<T>()` for type-only schemas or Standard Schema for runtime schemas. |
26
+ | `{ target, guard, actions }` | A transition function that checks its condition and returns `{ target, context }`; queue effects with `enq`. |
27
+
28
+ <!-- quick start using public createMachine and createActor exports from src/index.ts -->
29
+
30
+ ## Quick start
31
+
32
+ ```bash
33
+ npm install xstate@alpha
34
+ ```
35
+
36
+ ```ts
37
+ import { createMachine, createActor } from 'xstate';
38
+
39
+ // State machine
40
+ const toggleMachine = createMachine({
41
+ id: 'toggle',
42
+ initial: 'inactive',
43
+ context: {
44
+ count: 0
45
+ },
46
+ states: {
47
+ inactive: {
48
+ on: {
49
+ TOGGLE: { target: 'active' }
50
+ }
51
+ },
52
+ active: {
53
+ entry: ({ context }) => ({
54
+ context: { count: context.count + 1 }
55
+ }),
56
+ on: {
57
+ TOGGLE: { target: 'inactive' }
58
+ }
59
+ }
60
+ }
61
+ });
62
+
63
+ // Actor (instance of the machine logic, like a store)
64
+ const toggleActor = createActor(toggleMachine);
65
+ toggleActor.subscribe((state) => console.log(state.value, state.context));
66
+ toggleActor.start();
67
+ // => logs 'inactive', { count: 0 }
68
+
69
+ toggleActor.send({ type: 'TOGGLE' });
70
+ // => logs 'active', { count: 1 }
71
+
72
+ toggleActor.send({ type: 'TOGGLE' });
73
+ // => logs 'inactive', { count: 1 }
74
+ ```
75
+
1
76
  <p align="center">
2
77
  <br />
3
78
 
@@ -6,20 +81,114 @@
6
81
  <img alt="XState logotype" src="https://raw.githubusercontent.com/statelyai/public-assets/main/logos/xstate-logo-black-nobg.svg" width="200">
7
82
  </picture>
8
83
  <br />
9
- <strong>Actor-based state management & orchestration for complex app logic.</strong> <a href="https://stately.ai/docs">→ Documentation</a>
84
+ <strong>Actor-based state management & orchestration for complex app logic.</strong> <a href="https://github.com/statelyai/xstate/tree/next/docs">→ Documentation</a>
10
85
  <br />
11
86
  <br />
12
87
  </p>
13
88
 
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.
89
+ <!-- runtime dependencies and public entry points from package.json -->
90
+
91
+ XState is a state management and orchestration solution for JavaScript and TypeScript apps. The `xstate` package has _zero_ runtime dependencies. XState is useful for frontend and backend application logic.
15
92
 
16
93
  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
94
 
95
+ <!-- system-wide emission observation from packages/core/src/setup.ts and packages/core/src/system.ts -->
96
+
97
+ Observe emitted events from root and child actors with `createSystem({ onEmitted })`:
98
+
99
+ ```ts
100
+ import { createMachine, createSystem } from 'xstate';
101
+
102
+ const machine = createMachine({
103
+ entry: (_, enq) => enq.emit({ type: 'started' })
104
+ });
105
+
106
+ const system = createSystem({
107
+ onEmitted: ({ actorRef, event }) => {
108
+ console.log(actorRef.id, event);
109
+ }
110
+ });
111
+
112
+ const root = system.createActor(machine).start();
113
+ ```
114
+
115
+ Use `system.onEmitted(listener)` for a removable subscription. `actor.on(...)`
116
+ observes only that actor. See [actor systems](https://github.com/statelyai/xstate/blob/next/docs/systems.md#observe-emitted-events-across-a-system).
117
+
118
+ <!-- experimental whole-system transitions from packages/core/src/systemTransition.ts -->
119
+
120
+ For pure actor-system simulation, `initialSystemTransition`, `systemTransition`
121
+ and `advanceSystemTime` return an immutable system snapshot and external effects
122
+ as data. Branch or replay actors, messages and virtual timers without starting live
123
+ actors. See [pure system transitions](https://github.com/statelyai/xstate/blob/next/docs/system-transitions.md).
124
+
125
+ <!-- durable execution and checkpoint restoration from packages/core/src/durable/index.ts -->
126
+
127
+ For durable hosts, the experimental `xstate/durable` entry point provides
128
+ `createDurable`. Resume a checkpoint with `execution.restore(persistedSnapshot)`
129
+ and execute the returned effects to restart active embedded children and pending
130
+ timers without replaying entry actions. Await `executeEffects()` before persisting
131
+ to retain accepted timer deadlines. The host handles root error snapshots;
132
+ `run()` rejects with the root error. See [durable execution](https://github.com/statelyai/xstate/blob/next/docs/durable-execution.md).
133
+
134
+ <!-- state context refinements from packages/core/src/setup.ts and packages/core/src/State.ts -->
135
+
136
+ For [typestates](https://github.com/statelyai/xstate/blob/next/docs/typestates.md), declare state-level `schemas.context`
137
+ in `setup({ states })`. State functions receive narrowed context, transitions
138
+ check the target context requirements, and `snapshot.matches(...)` narrows
139
+ context when reading snapshots.
140
+
141
+ <!-- typed inline invocation from packages/core/src/setup.ts -->
142
+
143
+ Use `s.createInvoke({ src, input, onDone })` inline in `s.createMachine(...)` for an actor used in one state. It infers the actor's input and output and the enclosing state's narrowed context without registering that actor in `setup.actors`. See [typed inline invokes](https://github.com/statelyai/xstate/blob/next/docs/invoke.md#typed-inline-invokes).
144
+
145
+ Pass an async function directly as `src`, with `schemas.input`, `schemas.output`, and `schemas.error` on the same invoke. Output also infers from the async return when its schema is omitted. Existing logic values use their own schemas.
146
+
147
+ The helper requires input for actors whose input excludes `undefined`, and checks child IDs and source compatibility against `schemas.children` declared in the setup or machine.
148
+
149
+ <!-- graph traversal events from packages/core/src/graph/index.ts -->
150
+
151
+ Graph traversal requires samples for known event types with required payloads. Pass an `events` map such as `{ ADD: [{ value: 1 }, { value: 0 }] }`; each entry also accepts a snapshot callback returning nonempty payload cases. Maps preserve payload-free defaults, invoke completions, errors, and delayed events. Event arrays and callbacks returning events replace all defaults. Coverage remains sample-based. See [model-based testing](https://github.com/statelyai/xstate/blob/next/docs/model-based-testing.md).
152
+
153
+ <!-- JSON loading and runtime validation from packages/core/src/machineFromJSON.ts -->
154
+
155
+ Revive JSON definitions with `machineFromJSON(json, { schemas, validator, ...sources })` to restore runtime validation. The loader validates config keys and references. See [serialization](https://github.com/statelyai/xstate/blob/next/docs/serialization.md).
156
+
157
+ For flat finite state machines, `xstate/fsm` provides a tiny pure transition
158
+ table with context and TypeScript support:
159
+
160
+ <!-- public exports from packages/core/src/fsm/index.ts; exact capabilities documented in docs/fsm.md -->
161
+
162
+ ```ts
163
+ import { createFSM } from 'xstate/fsm';
164
+
165
+ const machine = createFSM({
166
+ initial: 'inactive',
167
+ states: {
168
+ inactive: { on: { toggle: 'active' } },
169
+ active: { on: { toggle: 'inactive' } }
170
+ }
171
+ });
172
+
173
+ let state = machine.initialState;
174
+ [state] = machine.transition(state, { type: 'toggle' });
175
+ ```
176
+
177
+ The FSM is also actor logic, so `createActor(machine)` from `xstate` runs it.
178
+
179
+ For typed context, event payloads, or state-specific context snapshots, use
180
+ `setup` and `types` from `xstate/fsm`. These schemas are type-only in this
181
+ subpath; use root `xstate` for runtime schema validation.
182
+
183
+ See the [exact supported surface](https://stately.ai/docs/fsm). Use the root `xstate`
184
+ entry point for compound or parallel statecharts, invocation, named sources,
185
+ runtime schemas, serialization and inspection.
186
+
18
187
  ### ✨ Create state machines visually in Stately Studio → [state.new](https://state.new)
19
188
 
20
189
  ---
21
190
 
22
- 📖 [Read the documentation](https://stately.ai/docs)
191
+ 📖 [Read the documentation](https://github.com/statelyai/xstate/tree/next/docs)
23
192
 
24
193
  ➡️ [Create state machines with the Stately Editor](https://stately.ai/editor)
25
194
 
@@ -27,9 +196,13 @@ It uses event-driven programming, state machines, statecharts, and the actor mod
27
196
 
28
197
  📑 Inspired by the [SCXML specification](https://www.w3.org/TR/scxml/)
29
198
 
199
+ <!-- public SCXML entry point from packages/xstate-scxml/src/index.ts -->
200
+
201
+ Create machines from SCXML documents with the separate [`@xstate/scxml`](https://www.npmjs.com/package/@xstate/scxml) package. See the [SCXML guide](https://github.com/statelyai/xstate/blob/next/docs/scxml.md).
202
+
30
203
  💬 Chat on the [Stately Discord Community](https://discord.gg/xstate)
31
204
 
32
- ✍️ Browse through the many [XState examples](https://github.com/statelyai/xstate/tree/main/examples)
205
+ ✍️ Browse through the many [XState examples](https://github.com/statelyai/xstate/tree/next/examples)
33
206
 
34
207
  ## Templates
35
208
 
@@ -44,14 +217,14 @@ Get started by forking one of these templates on CodeSandbox:
44
217
  <tr>
45
218
  <td>
46
219
 
47
- [🤖 XState Template (CodeSandbox)](https://codesandbox.io/p/devbox/github/statelyai/xstate/tree/main/templates/vanilla-ts)
220
+ [🤖 XState Template (CodeSandbox)](https://codesandbox.io/p/devbox/github/statelyai/xstate/tree/next/templates/vanilla-ts)
48
221
 
49
- [![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)
222
+ [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/statelyai/xstate/tree/next/templates/vanilla-ts?file=%2Fsrc%2FfeedbackMachine.ts)
50
223
 
51
224
  </td>
52
225
  <td>
53
226
 
54
- - XState v5
227
+ - XState v6 alpha
55
228
  - TypeScript
56
229
  - _No framework_
57
230
 
@@ -61,15 +234,15 @@ Get started by forking one of these templates on CodeSandbox:
61
234
  <tr>
62
235
  <td>
63
236
 
64
- [⚛️ XState + React Template (CodeSandbox)](https://codesandbox.io/p/devbox/github/statelyai/xstate/tree/main/templates/react-ts)
237
+ [⚛️ XState + React Template (CodeSandbox)](https://codesandbox.io/p/devbox/github/statelyai/xstate/tree/next/templates/react-ts)
65
238
 
66
- [![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)
239
+ [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/statelyai/xstate/tree/next/templates/react-ts?file=%2Fsrc%2FfeedbackMachine.ts)
67
240
 
68
241
  </td>
69
242
  <td>
70
243
 
71
244
  - [React](https://react.dev/)
72
- - XState v5
245
+ - XState v6 alpha
73
246
  - TypeScript
74
247
 
75
248
  </td>
@@ -78,15 +251,15 @@ Get started by forking one of these templates on CodeSandbox:
78
251
  <tr>
79
252
  <td>
80
253
 
81
- [💚 XState + Vue Template (CodeSandbox)](https://codesandbox.io/p/devbox/github/statelyai/xstate/tree/main/templates/vue-ts)
254
+ [💚 XState + Vue Template (CodeSandbox)](https://codesandbox.io/p/devbox/github/statelyai/xstate/tree/next/templates/vue-ts)
82
255
 
83
- [![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)
256
+ [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/statelyai/xstate/tree/next/templates/vue-ts?file=%2Fsrc%2FfeedbackMachine.ts)
84
257
 
85
258
  </td>
86
259
  <td>
87
260
 
88
261
  - [Vue](https://vuejs.org/)
89
- - XState v5
262
+ - XState v6 alpha
90
263
  - TypeScript
91
264
 
92
265
  </td>
@@ -95,15 +268,15 @@ Get started by forking one of these templates on CodeSandbox:
95
268
  <tr>
96
269
  <td>
97
270
 
98
- [🧡 XState + Svelte Template (CodeSandbox)](https://codesandbox.io/p/devbox/github/statelyai/xstate/tree/main/templates/svelte-ts)
271
+ [🧡 XState + Svelte Template (CodeSandbox)](https://codesandbox.io/p/devbox/github/statelyai/xstate/tree/next/templates/svelte-ts)
99
272
 
100
- [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/statelyai/xstate/tree/main/templates/svelte-ts?file=%2Fsrc%2FfeedbackMachine.ts)
273
+ [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/statelyai/xstate/tree/next/templates/svelte-ts?file=%2Fsrc%2FfeedbackMachine.ts)
101
274
 
102
275
  </td>
103
276
  <td>
104
277
 
105
278
  - [Svelte](https://svelte.dev/)
106
- - XState v5
279
+ - XState v6 alpha
107
280
  - TypeScript
108
281
 
109
282
  </td>
@@ -112,52 +285,6 @@ Get started by forking one of these templates on CodeSandbox:
112
285
  </tbody>
113
286
  </table>
114
287
 
115
- ## Super quick start
116
-
117
- ```bash
118
- npm install xstate
119
- ```
120
-
121
- ```ts
122
- import { createMachine, createActor } from 'xstate';
123
-
124
- // State machine
125
- const toggleMachine = createMachine({
126
- id: 'toggle',
127
- initial: 'inactive',
128
- context: {
129
- count: 0
130
- },
131
- states: {
132
- inactive: {
133
- on: {
134
- TOGGLE: { target: 'active' }
135
- }
136
- },
137
- active: {
138
- entry: ({ context }) => ({
139
- context: { count: context.count + 1 }
140
- }),
141
- on: {
142
- TOGGLE: { target: 'inactive' }
143
- }
144
- }
145
- }
146
- });
147
-
148
- // Actor (instance of the machine logic, like a store)
149
- const toggleActor = createActor(toggleMachine);
150
- toggleActor.subscribe((state) => console.log(state.value, state.context));
151
- toggleActor.start();
152
- // => logs 'inactive', { count: 0 }
153
-
154
- toggleActor.send({ type: 'TOGGLE' });
155
- // => logs 'active', { count: 1 }
156
-
157
- toggleActor.send({ type: 'TOGGLE' });
158
- // => logs 'inactive', { count: 1 }
159
- ```
160
-
161
288
  ## [Stately Studio](https://stately.ai)
162
289
 
163
290
  - Visually create, edit, and collaborate on state machines
@@ -166,7 +293,7 @@ toggleActor.send({ type: 'TOGGLE' });
166
293
  - Deploy to Stately Sky
167
294
  - Generate & modify machines with Stately AI
168
295
 
169
- <a href="stately.ai/registry/new?ref=github" title="Stately Studio">
296
+ <a href="https://stately.ai/registry/new?ref=github" title="Stately Studio">
170
297
  <img src="https://github.com/statelyai/xstate/assets/1093738/74ed9cbc-b824-4ed7-a16d-f104947af8a7" alt="XState Viz" width="800" />
171
298
  </a>
172
299
 
@@ -186,10 +313,10 @@ Read [📽 the slides](http://slides.com/davidkhourshid/finite-state-machines) (
186
313
  | Package | Description |
187
314
  | ------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
188
315
  | 🤖 `xstate` | Core finite state machine and statecharts library + interpreter |
189
- | [⚛️ `@xstate/react`](https://github.com/statelyai/xstate/tree/main/packages/xstate-react) | React hooks and utilities for using XState in React applications |
190
- | [💚 `@xstate/vue`](https://github.com/statelyai/xstate/tree/main/packages/xstate-vue) | Vue composition functions and utilities for using XState in Vue applications |
191
- | [🎷 `@xstate/svelte`](https://github.com/statelyai/xstate/tree/main/packages/xstate-svelte) | Svelte utilities for using XState in Svelte applications |
192
- | [🥏 `@xstate/solid`](https://github.com/statelyai/xstate/tree/main/packages/xstate-solid) | Solid hooks and utilities for using XState in Solid applications |
316
+ | [⚛️ `@xstate/react`](https://github.com/statelyai/xstate/tree/next/packages/xstate-react) | React hooks and utilities for using XState in React applications |
317
+ | [💚 `@xstate/vue`](https://github.com/statelyai/xstate/tree/next/packages/xstate-vue) | Vue composition functions and utilities for using XState in Vue applications |
318
+ | [🎷 `@xstate/svelte`](https://github.com/statelyai/xstate/tree/next/packages/xstate-svelte) | Svelte utilities for using XState in Svelte applications |
319
+ | [🥏 `@xstate/solid`](https://github.com/statelyai/xstate/tree/next/packages/xstate-solid) | Solid hooks and utilities for using XState in Solid applications |
193
320
 
194
321
  ## Finite State Machines
195
322
 
@@ -575,3 +702,15 @@ For these reasons, it is impractical for our team to be bound by decisions taken
575
702
  ### Packages
576
703
 
577
704
  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.
705
+
706
+ <!-- public input validation contract from src/StateMachine.ts -->
707
+ Validate external input with `machine.eventSchema` before `actor.send()`.
708
+ It validates complete public events, excludes internal/runtime events, and allows
709
+ explicitly configured routes. Payload checks require runtime schemas;
710
+ `types<T>()` supplies types only. See [public input validation](https://github.com/statelyai/xstate/blob/next/docs/internal-events.md#validating-public-input).
711
+
712
+ <!-- entry effects and terminal transition behavior from packages/core/src/stateUtils.ts and transitionActions.ts -->
713
+
714
+ Use the `enq` argument in transition, entry and exit functions to queue effects. Return context or child patches from those functions; the return value of an enqueued effect is ignored, with a development warning. See [actions](https://github.com/statelyai/xstate/blob/next/docs/actions.md).
715
+
716
+ For actors that are done, stopped or failed, pure transitions return the same snapshot and no effects, and `snapshot.can(...)` returns `false`. See [snapshots](https://github.com/statelyai/xstate/blob/next/docs/snapshots.md) and [states](https://github.com/statelyai/xstate/blob/next/docs/states.md).