xstate 6.0.0-alpha.69 → 6.0.0-alpha.70
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.
- package/README.md +99 -75
- package/dist/{createActor-b14a387c.development.cjs.js → createActor-11e36865.development.cjs.js} +476 -251
- package/dist/{createActor-009673a7.cjs.js → createActor-54296cf2.cjs.js} +474 -249
- package/dist/{createActor-c121cbf9.development.esm.js → createActor-9529bbaf.development.esm.js} +473 -250
- package/dist/{createActor-a8baa71f.esm.js → createActor-eaa95ae0.esm.js} +471 -248
- package/dist/declarations/src/State.d.ts +1 -1
- package/dist/declarations/src/StateMachine.d.ts +25 -2
- package/dist/declarations/src/StateNode.d.ts +2 -1
- package/dist/declarations/src/actors/callback.d.ts +3 -2
- package/dist/declarations/src/actors/index.d.ts +1 -1
- package/dist/declarations/src/actors/listener.d.ts +2 -2
- package/dist/declarations/src/actors/logic.d.ts +3 -2
- package/dist/declarations/src/actors/observable.d.ts +3 -2
- package/dist/declarations/src/actors/promise.d.ts +3 -2
- package/dist/declarations/src/actors/subscription.d.ts +2 -2
- package/dist/declarations/src/createActor.d.ts +7 -0
- package/dist/declarations/src/createMachine.d.ts +6 -5
- package/dist/declarations/src/eventTypes.d.ts +2 -1
- package/dist/declarations/src/graph/adjacency.d.ts +4 -3
- package/dist/declarations/src/graph/pathFromEvents.d.ts +4 -2
- package/dist/declarations/src/graph/shortestPaths.d.ts +4 -3
- package/dist/declarations/src/graph/simplePaths.d.ts +4 -3
- package/dist/declarations/src/graph/types.d.ts +58 -4
- package/dist/declarations/src/index.d.ts +1 -1
- package/dist/declarations/src/machineFromJSON.d.ts +13 -3
- package/dist/declarations/src/setup.d.ts +24 -38
- package/dist/declarations/src/spawn.d.ts +3 -2
- package/dist/declarations/src/stateUtils.d.ts +18 -8
- package/dist/declarations/src/transitionActions.d.ts +1 -0
- package/dist/declarations/src/typeUtils.d.ts +52 -0
- package/dist/declarations/src/types.d.ts +48 -83
- package/dist/declarations/src/types.v6.d.ts +82 -28
- package/dist/declarations/src/utils.d.ts +22 -3
- package/dist/{effectDescriptor-75145bce.cjs.js → effectDescriptor-425644eb.cjs.js} +1 -1
- package/dist/{effectDescriptor-7326693b.development.esm.js → effectDescriptor-97802bb8.esm.js} +1 -1
- package/dist/{effectDescriptor-acfd606c.esm.js → effectDescriptor-df768c71.development.esm.js} +1 -1
- package/dist/{effectDescriptor-3e92534c.development.cjs.js → effectDescriptor-fd2aaf45.development.cjs.js} +1 -1
- package/dist/{index-d064963f.esm.js → index-967ad7fa.esm.js} +1 -1
- package/dist/{index-43ce8782.development.cjs.js → index-9826ee1d.development.cjs.js} +1 -1
- package/dist/{index-a2835490.cjs.js → index-986372f2.cjs.js} +1 -1
- package/dist/{index-52951124.development.esm.js → index-e30fe161.development.esm.js} +1 -1
- package/dist/xstate-actors.cjs.js +2 -2
- package/dist/xstate-actors.development.cjs.js +2 -2
- package/dist/xstate-actors.development.esm.js +2 -2
- package/dist/xstate-actors.esm.js +2 -2
- package/dist/xstate-actors.umd.min.js +1 -1
- package/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/xstate-durable.cjs.js +2 -2
- package/dist/xstate-durable.development.cjs.js +2 -2
- package/dist/xstate-durable.development.esm.js +2 -2
- package/dist/xstate-durable.esm.js +2 -2
- package/dist/xstate-durable.umd.min.js +1 -1
- package/dist/xstate-durable.umd.min.js.map +1 -1
- package/dist/xstate-graph.cjs.js +58 -22
- package/dist/xstate-graph.development.cjs.js +58 -22
- package/dist/xstate-graph.development.esm.js +59 -23
- package/dist/xstate-graph.esm.js +59 -23
- package/dist/xstate-graph.umd.min.js +1 -1
- package/dist/xstate-graph.umd.min.js.map +1 -1
- package/dist/xstate-validation.cjs.js +1 -1
- package/dist/xstate-validation.development.cjs.js +1 -1
- package/dist/xstate-validation.development.esm.js +1 -1
- package/dist/xstate-validation.esm.js +1 -1
- package/dist/xstate-validation.umd.min.js.map +1 -1
- package/dist/xstate.cjs.js +148 -56
- package/dist/xstate.cjs.mjs +1 -0
- package/dist/xstate.development.cjs.js +162 -62
- package/dist/xstate.development.cjs.mjs +1 -0
- package/dist/xstate.development.esm.js +164 -65
- package/dist/xstate.esm.js +150 -59
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/docs/actions.md +75 -0
- package/docs/actor-logic.md +250 -0
- package/docs/actors.md +64 -0
- package/docs/async-logic.md +75 -0
- package/docs/async-requests.md +157 -0
- package/docs/backend-workflows.md +121 -0
- package/docs/cancellation.md +42 -0
- package/docs/cheatsheet.md +561 -0
- package/docs/choice-states.md +109 -0
- package/docs/choose-xstate.md +47 -0
- package/docs/configuration.md +161 -0
- package/docs/context.md +63 -0
- package/docs/create-actor.md +156 -0
- package/docs/data-and-effects.md +48 -0
- package/docs/delays.md +81 -0
- package/docs/durable-execution.md +510 -0
- package/docs/emitted-events.md +127 -0
- package/docs/examples.md +75 -0
- package/docs/faq.md +60 -0
- package/docs/final-states.md +149 -0
- package/docs/forms-and-wizards.md +166 -0
- package/docs/frameworks.md +69 -0
- package/docs/fsm.md +164 -0
- package/docs/glossary.md +68 -0
- package/docs/guards.md +137 -0
- package/docs/history-states.md +159 -0
- package/docs/how-xstate-runs-machines.md +84 -0
- package/docs/index.md +71 -0
- package/docs/input-output.md +69 -0
- package/docs/inspect-actor-systems.md +116 -0
- package/docs/inspection.md +73 -0
- package/docs/internal-events.md +156 -0
- package/docs/invoke.md +354 -0
- package/docs/lifecycle-and-errors.md +48 -0
- package/docs/listen-and-subscribe.md +126 -0
- package/docs/model-based-testing.md +319 -0
- package/docs/modeling.md +40 -0
- package/docs/parallel-states.md +182 -0
- package/docs/persist-and-restore-actors.md +115 -0
- package/docs/persistence.md +325 -0
- package/docs/quick-start.md +55 -0
- package/docs/retries-and-timeouts.md +122 -0
- package/docs/route-states.md +104 -0
- package/docs/scxml.md +59 -0
- package/docs/selectors.md +99 -0
- package/docs/serialization.md +124 -0
- package/docs/setup-and-provide.md +271 -0
- package/docs/snapshots.md +134 -0
- package/docs/spawn.md +220 -0
- package/docs/state-input.md +162 -0
- package/docs/statecharts.md +54 -0
- package/docs/states-events-transitions.md +82 -0
- package/docs/states.md +168 -0
- package/docs/system-transitions.md +170 -0
- package/docs/systems.md +134 -0
- package/docs/testing.md +150 -0
- package/docs/timeouts.md +125 -0
- package/docs/transition-functions.md +87 -0
- package/docs/transitions.md +185 -0
- package/docs/troubleshooting.md +48 -0
- package/docs/tutorial.md +481 -0
- package/docs/typescript.md +211 -0
- package/docs/typestates.md +110 -0
- package/docs/utilities.md +39 -0
- package/docs/why-state-machines.md +59 -0
- package/docs/xstate-v5-to-v6.md +1756 -0
- package/docs/your-first-machine.md +79 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,3 +1,73 @@
|
|
|
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
|
+
Online, start with the [quick start](https://github.com/statelyai/xstate/blob/next/docs/quick-start.md)
|
|
12
|
+
or the [v5 to v6 migration guide](https://github.com/statelyai/xstate/blob/next/docs/xstate-v5-to-v6.md).
|
|
13
|
+
|
|
14
|
+
<!-- v6 authoring replacements from src/index.ts, src/transitionActions.ts and src/types.ts -->
|
|
15
|
+
|
|
16
|
+
| XState v5 | XState v6 |
|
|
17
|
+
| --- | --- |
|
|
18
|
+
| `assign(...)` | Return a shallow `{ context: { ... } }` patch from a transition, entry or exit function. |
|
|
19
|
+
| `fromPromise(fn)` | `createAsyncLogic({ run: fn })` from `xstate`. |
|
|
20
|
+
| `types: {} as { ... }` | `schemas` with `types<T>()` for type-only schemas or Standard Schema for runtime schemas. |
|
|
21
|
+
| `{ target, guard, actions }` | A transition function that checks its condition and returns `{ target, context }`; queue effects with `enq`. |
|
|
22
|
+
|
|
23
|
+
<!-- quick start using public createMachine and createActor exports from src/index.ts -->
|
|
24
|
+
|
|
25
|
+
## Quick start
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm install xstate@alpha
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { createMachine, createActor } from 'xstate';
|
|
33
|
+
|
|
34
|
+
// State machine
|
|
35
|
+
const toggleMachine = createMachine({
|
|
36
|
+
id: 'toggle',
|
|
37
|
+
initial: 'inactive',
|
|
38
|
+
context: {
|
|
39
|
+
count: 0
|
|
40
|
+
},
|
|
41
|
+
states: {
|
|
42
|
+
inactive: {
|
|
43
|
+
on: {
|
|
44
|
+
TOGGLE: { target: 'active' }
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
active: {
|
|
48
|
+
entry: ({ context }) => ({
|
|
49
|
+
context: { count: context.count + 1 }
|
|
50
|
+
}),
|
|
51
|
+
on: {
|
|
52
|
+
TOGGLE: { target: 'inactive' }
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// Actor (instance of the machine logic, like a store)
|
|
59
|
+
const toggleActor = createActor(toggleMachine);
|
|
60
|
+
toggleActor.subscribe((state) => console.log(state.value, state.context));
|
|
61
|
+
toggleActor.start();
|
|
62
|
+
// => logs 'inactive', { count: 0 }
|
|
63
|
+
|
|
64
|
+
toggleActor.send({ type: 'TOGGLE' });
|
|
65
|
+
// => logs 'active', { count: 1 }
|
|
66
|
+
|
|
67
|
+
toggleActor.send({ type: 'TOGGLE' });
|
|
68
|
+
// => logs 'inactive', { count: 1 }
|
|
69
|
+
```
|
|
70
|
+
|
|
1
71
|
<p align="center">
|
|
2
72
|
<br />
|
|
3
73
|
|
|
@@ -6,7 +76,7 @@
|
|
|
6
76
|
<img alt="XState logotype" src="https://raw.githubusercontent.com/statelyai/public-assets/main/logos/xstate-logo-black-nobg.svg" width="200">
|
|
7
77
|
</picture>
|
|
8
78
|
<br />
|
|
9
|
-
<strong>Actor-based state management & orchestration for complex app logic.</strong> <a href="https://
|
|
79
|
+
<strong>Actor-based state management & orchestration for complex app logic.</strong> <a href="https://github.com/statelyai/xstate/tree/next/docs">→ Documentation</a>
|
|
10
80
|
<br />
|
|
11
81
|
<br />
|
|
12
82
|
</p>
|
|
@@ -22,7 +92,7 @@ It uses event-driven programming, state machines, statecharts, and the actor mod
|
|
|
22
92
|
For pure actor-system simulation, `initialSystemTransition`, `systemTransition`
|
|
23
93
|
and `advanceSystemTime` return an immutable system snapshot and external effects
|
|
24
94
|
as data. Branch or replay actors, messages and virtual timers without starting live
|
|
25
|
-
actors. See [pure system transitions](
|
|
95
|
+
actors. See [pure system transitions](https://github.com/statelyai/xstate/blob/next/docs/system-transitions.md).
|
|
26
96
|
|
|
27
97
|
<!-- durable execution and checkpoint restoration from packages/core/src/durable/index.ts -->
|
|
28
98
|
|
|
@@ -31,18 +101,18 @@ For durable hosts, the experimental `xstate/durable` entry point provides
|
|
|
31
101
|
and execute the returned effects to restart active embedded children and pending
|
|
32
102
|
timers without replaying entry actions. Await `executeEffects()` before persisting
|
|
33
103
|
to retain accepted timer deadlines. The host handles root error snapshots;
|
|
34
|
-
`run()` rejects with the root error. See [durable execution](
|
|
104
|
+
`run()` rejects with the root error. See [durable execution](https://github.com/statelyai/xstate/blob/next/docs/durable-execution.md).
|
|
35
105
|
|
|
36
106
|
<!-- state context refinements from packages/core/src/setup.ts and packages/core/src/State.ts -->
|
|
37
107
|
|
|
38
|
-
For [typestates](
|
|
108
|
+
For [typestates](https://github.com/statelyai/xstate/blob/next/docs/typestates.md), declare state-level `schemas.context`
|
|
39
109
|
in `setup({ states })`. State functions receive narrowed context, transitions
|
|
40
110
|
check the target context requirements, and `snapshot.matches(...)` narrows
|
|
41
111
|
context when reading snapshots.
|
|
42
112
|
|
|
43
113
|
<!-- typed inline invocation from packages/core/src/setup.ts -->
|
|
44
114
|
|
|
45
|
-
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](
|
|
115
|
+
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).
|
|
46
116
|
|
|
47
117
|
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.
|
|
48
118
|
|
|
@@ -50,11 +120,11 @@ The helper requires input for actors whose input excludes `undefined`, and check
|
|
|
50
120
|
|
|
51
121
|
<!-- graph traversal events from packages/core/src/graph/index.ts -->
|
|
52
122
|
|
|
53
|
-
`
|
|
123
|
+
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).
|
|
54
124
|
|
|
55
125
|
<!-- JSON loading and runtime validation from packages/core/src/machineFromJSON.ts -->
|
|
56
126
|
|
|
57
|
-
Revive JSON definitions with `machineFromJSON(json, { schemas, validator, ...sources })` to restore runtime validation. The loader validates config keys and references. See [serialization](
|
|
127
|
+
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).
|
|
58
128
|
|
|
59
129
|
For flat finite state machines, `xstate/fsm` provides a tiny pure transition
|
|
60
130
|
table with context and TypeScript support:
|
|
@@ -90,7 +160,7 @@ runtime schemas, serialization and inspection.
|
|
|
90
160
|
|
|
91
161
|
---
|
|
92
162
|
|
|
93
|
-
📖 [Read the documentation](https://
|
|
163
|
+
📖 [Read the documentation](https://github.com/statelyai/xstate/tree/next/docs)
|
|
94
164
|
|
|
95
165
|
➡️ [Create state machines with the Stately Editor](https://stately.ai/editor)
|
|
96
166
|
|
|
@@ -100,11 +170,11 @@ runtime schemas, serialization and inspection.
|
|
|
100
170
|
|
|
101
171
|
<!-- public SCXML entry point from packages/xstate-scxml/src/index.ts -->
|
|
102
172
|
|
|
103
|
-
Create machines from SCXML documents with the separate [`@xstate/scxml`](
|
|
173
|
+
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).
|
|
104
174
|
|
|
105
175
|
💬 Chat on the [Stately Discord Community](https://discord.gg/xstate)
|
|
106
176
|
|
|
107
|
-
✍️ Browse through the many [XState examples](https://github.com/statelyai/xstate/tree/
|
|
177
|
+
✍️ Browse through the many [XState examples](https://github.com/statelyai/xstate/tree/next/examples)
|
|
108
178
|
|
|
109
179
|
## Templates
|
|
110
180
|
|
|
@@ -119,14 +189,14 @@ Get started by forking one of these templates on CodeSandbox:
|
|
|
119
189
|
<tr>
|
|
120
190
|
<td>
|
|
121
191
|
|
|
122
|
-
[🤖 XState Template (CodeSandbox)](https://codesandbox.io/p/devbox/github/statelyai/xstate/tree/
|
|
192
|
+
[🤖 XState Template (CodeSandbox)](https://codesandbox.io/p/devbox/github/statelyai/xstate/tree/next/templates/vanilla-ts)
|
|
123
193
|
|
|
124
|
-
[](https://stackblitz.com/github/statelyai/xstate/tree/
|
|
194
|
+
[](https://stackblitz.com/github/statelyai/xstate/tree/next/templates/vanilla-ts?file=%2Fsrc%2FfeedbackMachine.ts)
|
|
125
195
|
|
|
126
196
|
</td>
|
|
127
197
|
<td>
|
|
128
198
|
|
|
129
|
-
- XState
|
|
199
|
+
- XState v6 alpha
|
|
130
200
|
- TypeScript
|
|
131
201
|
- _No framework_
|
|
132
202
|
|
|
@@ -136,15 +206,15 @@ Get started by forking one of these templates on CodeSandbox:
|
|
|
136
206
|
<tr>
|
|
137
207
|
<td>
|
|
138
208
|
|
|
139
|
-
[⚛️ XState + React Template (CodeSandbox)](https://codesandbox.io/p/devbox/github/statelyai/xstate/tree/
|
|
209
|
+
[⚛️ XState + React Template (CodeSandbox)](https://codesandbox.io/p/devbox/github/statelyai/xstate/tree/next/templates/react-ts)
|
|
140
210
|
|
|
141
|
-
[](https://stackblitz.com/github/statelyai/xstate/tree/
|
|
211
|
+
[](https://stackblitz.com/github/statelyai/xstate/tree/next/templates/react-ts?file=%2Fsrc%2FfeedbackMachine.ts)
|
|
142
212
|
|
|
143
213
|
</td>
|
|
144
214
|
<td>
|
|
145
215
|
|
|
146
216
|
- [React](https://react.dev/)
|
|
147
|
-
- XState
|
|
217
|
+
- XState v6 alpha
|
|
148
218
|
- TypeScript
|
|
149
219
|
|
|
150
220
|
</td>
|
|
@@ -153,15 +223,15 @@ Get started by forking one of these templates on CodeSandbox:
|
|
|
153
223
|
<tr>
|
|
154
224
|
<td>
|
|
155
225
|
|
|
156
|
-
[💚 XState + Vue Template (CodeSandbox)](https://codesandbox.io/p/devbox/github/statelyai/xstate/tree/
|
|
226
|
+
[💚 XState + Vue Template (CodeSandbox)](https://codesandbox.io/p/devbox/github/statelyai/xstate/tree/next/templates/vue-ts)
|
|
157
227
|
|
|
158
|
-
[](https://stackblitz.com/github/statelyai/xstate/tree/
|
|
228
|
+
[](https://stackblitz.com/github/statelyai/xstate/tree/next/templates/vue-ts?file=%2Fsrc%2FfeedbackMachine.ts)
|
|
159
229
|
|
|
160
230
|
</td>
|
|
161
231
|
<td>
|
|
162
232
|
|
|
163
233
|
- [Vue](https://vuejs.org/)
|
|
164
|
-
- XState
|
|
234
|
+
- XState v6 alpha
|
|
165
235
|
- TypeScript
|
|
166
236
|
|
|
167
237
|
</td>
|
|
@@ -170,15 +240,15 @@ Get started by forking one of these templates on CodeSandbox:
|
|
|
170
240
|
<tr>
|
|
171
241
|
<td>
|
|
172
242
|
|
|
173
|
-
[🧡 XState + Svelte Template (CodeSandbox)](https://codesandbox.io/p/devbox/github/statelyai/xstate/tree/
|
|
243
|
+
[🧡 XState + Svelte Template (CodeSandbox)](https://codesandbox.io/p/devbox/github/statelyai/xstate/tree/next/templates/svelte-ts)
|
|
174
244
|
|
|
175
|
-
[](https://stackblitz.com/github/statelyai/xstate/tree/
|
|
245
|
+
[](https://stackblitz.com/github/statelyai/xstate/tree/next/templates/svelte-ts?file=%2Fsrc%2FfeedbackMachine.ts)
|
|
176
246
|
|
|
177
247
|
</td>
|
|
178
248
|
<td>
|
|
179
249
|
|
|
180
250
|
- [Svelte](https://svelte.dev/)
|
|
181
|
-
- XState
|
|
251
|
+
- XState v6 alpha
|
|
182
252
|
- TypeScript
|
|
183
253
|
|
|
184
254
|
</td>
|
|
@@ -187,52 +257,6 @@ Get started by forking one of these templates on CodeSandbox:
|
|
|
187
257
|
</tbody>
|
|
188
258
|
</table>
|
|
189
259
|
|
|
190
|
-
## Super quick start
|
|
191
|
-
|
|
192
|
-
```bash
|
|
193
|
-
npm install xstate
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
```ts
|
|
197
|
-
import { createMachine, createActor } from 'xstate';
|
|
198
|
-
|
|
199
|
-
// State machine
|
|
200
|
-
const toggleMachine = createMachine({
|
|
201
|
-
id: 'toggle',
|
|
202
|
-
initial: 'inactive',
|
|
203
|
-
context: {
|
|
204
|
-
count: 0
|
|
205
|
-
},
|
|
206
|
-
states: {
|
|
207
|
-
inactive: {
|
|
208
|
-
on: {
|
|
209
|
-
TOGGLE: { target: 'active' }
|
|
210
|
-
}
|
|
211
|
-
},
|
|
212
|
-
active: {
|
|
213
|
-
entry: ({ context }) => ({
|
|
214
|
-
context: { count: context.count + 1 }
|
|
215
|
-
}),
|
|
216
|
-
on: {
|
|
217
|
-
TOGGLE: { target: 'inactive' }
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
// Actor (instance of the machine logic, like a store)
|
|
224
|
-
const toggleActor = createActor(toggleMachine);
|
|
225
|
-
toggleActor.subscribe((state) => console.log(state.value, state.context));
|
|
226
|
-
toggleActor.start();
|
|
227
|
-
// => logs 'inactive', { count: 0 }
|
|
228
|
-
|
|
229
|
-
toggleActor.send({ type: 'TOGGLE' });
|
|
230
|
-
// => logs 'active', { count: 1 }
|
|
231
|
-
|
|
232
|
-
toggleActor.send({ type: 'TOGGLE' });
|
|
233
|
-
// => logs 'inactive', { count: 1 }
|
|
234
|
-
```
|
|
235
|
-
|
|
236
260
|
## [Stately Studio](https://stately.ai)
|
|
237
261
|
|
|
238
262
|
- Visually create, edit, and collaborate on state machines
|
|
@@ -261,10 +285,10 @@ Read [📽 the slides](http://slides.com/davidkhourshid/finite-state-machines) (
|
|
|
261
285
|
| Package | Description |
|
|
262
286
|
| ------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
|
|
263
287
|
| 🤖 `xstate` | Core finite state machine and statecharts library + interpreter |
|
|
264
|
-
| [⚛️ `@xstate/react`](https://github.com/statelyai/xstate/tree/
|
|
265
|
-
| [💚 `@xstate/vue`](https://github.com/statelyai/xstate/tree/
|
|
266
|
-
| [🎷 `@xstate/svelte`](https://github.com/statelyai/xstate/tree/
|
|
267
|
-
| [🥏 `@xstate/solid`](https://github.com/statelyai/xstate/tree/
|
|
288
|
+
| [⚛️ `@xstate/react`](https://github.com/statelyai/xstate/tree/next/packages/xstate-react) | React hooks and utilities for using XState in React applications |
|
|
289
|
+
| [💚 `@xstate/vue`](https://github.com/statelyai/xstate/tree/next/packages/xstate-vue) | Vue composition functions and utilities for using XState in Vue applications |
|
|
290
|
+
| [🎷 `@xstate/svelte`](https://github.com/statelyai/xstate/tree/next/packages/xstate-svelte) | Svelte utilities for using XState in Svelte applications |
|
|
291
|
+
| [🥏 `@xstate/solid`](https://github.com/statelyai/xstate/tree/next/packages/xstate-solid) | Solid hooks and utilities for using XState in Solid applications |
|
|
268
292
|
|
|
269
293
|
## Finite State Machines
|
|
270
294
|
|
|
@@ -655,10 +679,10 @@ Most of the packages in the XState family declare a peer dependency on XState it
|
|
|
655
679
|
Validate external input with `machine.eventSchema` before `actor.send()`.
|
|
656
680
|
It validates complete public events, excludes internal/runtime events, and allows
|
|
657
681
|
explicitly configured routes. Payload checks require runtime schemas;
|
|
658
|
-
`types<T>()` supplies types only. See [public input validation](
|
|
682
|
+
`types<T>()` supplies types only. See [public input validation](https://github.com/statelyai/xstate/blob/next/docs/internal-events.md#validating-public-input).
|
|
659
683
|
|
|
660
684
|
<!-- entry effects and terminal transition behavior from packages/core/src/stateUtils.ts and transitionActions.ts -->
|
|
661
685
|
|
|
662
|
-
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](
|
|
686
|
+
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).
|
|
663
687
|
|
|
664
|
-
For actors that are done, stopped or failed, pure transitions return the same snapshot and no effects, and `snapshot.can(...)` returns `false`. See [snapshots](
|
|
688
|
+
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).
|