xstate 6.0.0-alpha.47 → 6.0.0-alpha.49
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 +30 -1
- package/dist/{StateMachine-7046f677.cjs.js → StateMachine-0adb3a70.cjs.js} +15 -12
- package/dist/{StateMachine-70c06bdd.development.cjs.js → StateMachine-29450e6d.development.cjs.js} +15 -12
- package/dist/{StateMachine-74929087.esm.js → StateMachine-2af31c11.esm.js} +10 -7
- package/dist/{StateMachine-ee10f67e.development.esm.js → StateMachine-faf50c5c.development.esm.js} +10 -7
- package/dist/{createActor-915ea40c.esm.js → createActor-268165d4.esm.js} +79 -23
- package/dist/{createActor-ff132afa.development.esm.js → createActor-88709f74.development.esm.js} +79 -23
- package/dist/{createActor-6736cbbe.development.cjs.js → createActor-a1e0dffb.development.cjs.js} +78 -25
- package/dist/{createActor-bfe8b6bd.cjs.js → createActor-b4dd05ae.cjs.js} +78 -25
- package/dist/declarations/src/createMachineFromConfig.d.ts +5 -77
- package/dist/declarations/src/fsm/createFSMActor.d.ts +67 -0
- package/dist/declarations/src/fsm/index.d.ts +2 -0
- package/dist/declarations/src/fsm.d.ts +5 -4
- package/dist/declarations/src/scxml/index.d.ts +1 -0
- package/dist/declarations/src/scxml/runtime.d.ts +251 -0
- package/dist/declarations/src/scxml/scxml.d.ts +19 -0
- package/dist/declarations/src/types.d.ts +1 -0
- package/dist/{effectDescriptor-8be60443.esm.js → effectDescriptor-30c9a744.esm.js} +1 -1
- package/dist/{effectDescriptor-fbe67d5a.development.esm.js → effectDescriptor-39d22100.development.esm.js} +1 -1
- package/dist/{effectDescriptor-3c699328.development.cjs.js → effectDescriptor-7ff6802f.development.cjs.js} +1 -1
- package/dist/{effectDescriptor-a7e2d4d1.cjs.js → effectDescriptor-be348e50.cjs.js} +1 -1
- package/dist/fsm-7a2e9697.cjs.js +777 -0
- package/dist/fsm-b804b3e9.esm.js +775 -0
- package/dist/fsm-c1316948.development.cjs.js +777 -0
- package/dist/fsm-e18a7cb4.development.esm.js +775 -0
- package/dist/types-3c3455f7.esm.js +185 -0
- package/dist/types-adda3842.development.esm.js +185 -0
- package/dist/types-b3fea5bd.development.cjs.js +189 -0
- package/dist/types-fbabaeee.cjs.js +189 -0
- package/dist/validation-05f1d517.esm.js +8 -0
- package/dist/validation-4561b43c.cjs.js +10 -0
- package/dist/validation-e69470ad.development.esm.js +8 -0
- package/dist/validation-f2714a35.development.cjs.js +10 -0
- package/dist/xstate-actors.cjs.js +934 -9
- package/dist/xstate-actors.development.cjs.js +934 -9
- package/dist/xstate-actors.development.esm.js +932 -2
- package/dist/xstate-actors.esm.js +932 -2
- 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-fsm.cjs.d.mts +2 -0
- package/dist/xstate-fsm.cjs.d.ts +2 -0
- package/dist/xstate-fsm.cjs.js +409 -0
- package/dist/xstate-fsm.cjs.mjs +5 -0
- package/dist/xstate-fsm.development.cjs.js +409 -0
- package/dist/xstate-fsm.development.cjs.mjs +5 -0
- package/dist/xstate-fsm.development.esm.js +403 -0
- package/dist/xstate-fsm.esm.js +403 -0
- package/dist/xstate-fsm.umd.min.js +2 -0
- package/dist/xstate-fsm.umd.min.js.map +1 -0
- package/dist/xstate-graph.cjs.js +4 -3
- package/dist/xstate-graph.development.cjs.js +4 -3
- package/dist/xstate-graph.development.esm.js +4 -3
- package/dist/xstate-graph.esm.js +4 -3
- package/dist/xstate-graph.umd.min.js +1 -1
- package/dist/xstate-graph.umd.min.js.map +1 -1
- package/dist/xstate-scxml.cjs.d.mts +2 -0
- package/dist/xstate-scxml.cjs.d.ts +2 -0
- package/dist/xstate-scxml.cjs.js +2387 -0
- package/dist/xstate-scxml.cjs.mjs +3 -0
- package/dist/xstate-scxml.development.cjs.js +2387 -0
- package/dist/xstate-scxml.development.cjs.mjs +3 -0
- package/dist/xstate-scxml.development.esm.js +2383 -0
- package/dist/xstate-scxml.esm.js +2383 -0
- package/dist/xstate-scxml.umd.min.js +26 -0
- package/dist/xstate-scxml.umd.min.js.map +1 -0
- 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.cjs.js +143 -1412
- package/dist/xstate.development.cjs.js +143 -1412
- package/dist/xstate.development.esm.js +143 -1411
- package/dist/xstate.esm.js +143 -1411
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/fsm/package.json +8 -0
- package/package.json +37 -3
- package/scxml/package.json +8 -0
- package/dist/index-0f498ef2.development.cjs.js +0 -946
- package/dist/index-70d56425.development.esm.js +0 -937
- package/dist/index-b051c924.esm.js +0 -937
- package/dist/index-b3fe59bc.cjs.js +0 -946
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var StateMachine = require('./StateMachine-0adb3a70.cjs.js');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates a state machine (statechart) with the given configuration.
|
|
7
|
+
*
|
|
8
|
+
* The state machine represents the pure logic of a state machine actor.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { createMachine } from 'xstate';
|
|
14
|
+
*
|
|
15
|
+
* const lightMachine = createMachine({
|
|
16
|
+
* id: 'light',
|
|
17
|
+
* initial: 'green',
|
|
18
|
+
* states: {
|
|
19
|
+
* green: {
|
|
20
|
+
* on: {
|
|
21
|
+
* TIMER: { target: 'yellow' }
|
|
22
|
+
* }
|
|
23
|
+
* },
|
|
24
|
+
* yellow: {
|
|
25
|
+
* on: {
|
|
26
|
+
* TIMER: { target: 'red' }
|
|
27
|
+
* }
|
|
28
|
+
* },
|
|
29
|
+
* red: {
|
|
30
|
+
* on: {
|
|
31
|
+
* TIMER: { target: 'green' }
|
|
32
|
+
* }
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* const lightActor = createActor(lightMachine);
|
|
38
|
+
* lightActor.start();
|
|
39
|
+
*
|
|
40
|
+
* lightActor.send({ type: 'TIMER' });
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @param config The state machine configuration.
|
|
44
|
+
* @param options DEPRECATED: use `setup({ ... })` or `machine.provide({ ... })`
|
|
45
|
+
* to provide machine sources instead.
|
|
46
|
+
*/
|
|
47
|
+
// Overload 1: With schemas.context — context type inferred from schema
|
|
48
|
+
|
|
49
|
+
// Overload 2: Without schemas.context — context type inferred from config.context
|
|
50
|
+
|
|
51
|
+
// Implementation
|
|
52
|
+
function createMachine(config) {
|
|
53
|
+
return new StateMachine.StateMachine(config);
|
|
54
|
+
}
|
|
55
|
+
function createStateConfig(config) {
|
|
56
|
+
return config;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// this is needed to make JSDoc `@link` work properly
|
|
60
|
+
// oxlint-disable-next-line no-unused-vars
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @remarks
|
|
64
|
+
* `T | unknown` reduces to `unknown` and that can be problematic when it comes
|
|
65
|
+
* to contextual typing. It especially is a problem when the union has a
|
|
66
|
+
* function member, like here:
|
|
67
|
+
*
|
|
68
|
+
* ```ts
|
|
69
|
+
* declare function test(
|
|
70
|
+
* cbOrVal: ((arg: number) => unknown) | unknown
|
|
71
|
+
* ): void;
|
|
72
|
+
* test((arg) => {}); // oops, implicit any
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* This type can be used to avoid this problem. This union represents the same
|
|
76
|
+
* value space as `unknown`.
|
|
77
|
+
*/
|
|
78
|
+
|
|
79
|
+
// https://github.com/microsoft/TypeScript/issues/23182#issuecomment-379091887
|
|
80
|
+
|
|
81
|
+
// @TODO: we can't use native `NoInfer` as we need those:
|
|
82
|
+
// https://github.com/microsoft/TypeScript/pull/61092
|
|
83
|
+
// https://github.com/microsoft/TypeScript/pull/61077
|
|
84
|
+
// but even with those fixes native NoInfer still doesn't work - further issues have to be reproduced and fixed
|
|
85
|
+
|
|
86
|
+
/** @deprecated Use the built-in `NoInfer` type instead */
|
|
87
|
+
|
|
88
|
+
/** The full definition of an event, with a string `type`. */
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The string or object representing the state value relative to the parent
|
|
92
|
+
* state node.
|
|
93
|
+
*
|
|
94
|
+
* @remarks
|
|
95
|
+
* - For a child atomic state node, this is a string, e.g., `"pending"`.
|
|
96
|
+
* - For complex state nodes, this is an object, e.g., `{ success:
|
|
97
|
+
* "someChildState" }`.
|
|
98
|
+
*/
|
|
99
|
+
|
|
100
|
+
// Accept any StateNode instance regardless of generic parameters
|
|
101
|
+
// Using a union type to handle variance issues with machine.resolveState
|
|
102
|
+
|
|
103
|
+
let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
104
|
+
SpecialTargets["Internal"] = "#_internal";
|
|
105
|
+
return SpecialTargets;
|
|
106
|
+
}({});
|
|
107
|
+
|
|
108
|
+
/** A deterministic delayed-delivery declaration owned by a logic snapshot. */
|
|
109
|
+
|
|
110
|
+
/** The logical input delivered to a timer's source when its runtime delay ends. */
|
|
111
|
+
|
|
112
|
+
/** A persisted snapshot tied to a versioned actor logic identity. */
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* A persisted snapshot restorable into the given actor logic: any snapshot
|
|
116
|
+
* created by logic with the same machine `id` is accepted, regardless of
|
|
117
|
+
* version (version mismatches are handled at runtime, e.g. by `migrate`).
|
|
118
|
+
*/
|
|
119
|
+
|
|
120
|
+
/** @deprecated Use `AnyActor` instead. */
|
|
121
|
+
|
|
122
|
+
// Based on RxJS types
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* A consumer-facing actor handle.
|
|
126
|
+
*
|
|
127
|
+
* `ActorRef` describes the contract a consumer needs: which events can be sent
|
|
128
|
+
* to the actor, which snapshot it publishes for observation, and which emitted
|
|
129
|
+
* events can be listened to. It intentionally does not expose lifecycle control
|
|
130
|
+
* or runtime internals. A concrete `Actor` satisfies this interface, so APIs
|
|
131
|
+
* should accept `ActorRef` whenever they only need to send events, read
|
|
132
|
+
* snapshots, or listen to emitted events.
|
|
133
|
+
*/
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Runtime-only actor capabilities.
|
|
137
|
+
*
|
|
138
|
+
* These members are needed by the interpreter, scheduler, inspection, and child
|
|
139
|
+
* management code. Public consumer APIs should prefer `ActorRef` unless they
|
|
140
|
+
* genuinely need lifecycle control such as starting, stopping, or accessing
|
|
141
|
+
* system-owned runtime state.
|
|
142
|
+
*/
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* A concrete actor instance type.
|
|
146
|
+
*
|
|
147
|
+
* `ActorInstance` combines the consumer `ActorRef` contract with runtime
|
|
148
|
+
* lifecycle capabilities. Values returned by `createActor(...)` and
|
|
149
|
+
* `spawn(...)` naturally satisfy narrower `ActorRef` contracts.
|
|
150
|
+
*/
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* The actor's own full self handle.
|
|
154
|
+
*
|
|
155
|
+
* Internals and action/guard sources receive this shape because `self` can
|
|
156
|
+
* participate in runtime-owned behavior while still being usable wherever an
|
|
157
|
+
* `ActorRef` is expected.
|
|
158
|
+
*/
|
|
159
|
+
|
|
160
|
+
// TODO: in v6, this should only accept AnyActorLogic, like ActorRefFromLogic
|
|
161
|
+
|
|
162
|
+
/** The concrete actor instance type produced from actor logic. */
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Represents logic which can be used by an actor.
|
|
166
|
+
*
|
|
167
|
+
* @template TSnapshot - The type of the snapshot.
|
|
168
|
+
* @template TEvent - The type of the event object.
|
|
169
|
+
* @template TInput - The type of the input.
|
|
170
|
+
* @template TSystem - The type of the actor system.
|
|
171
|
+
*/
|
|
172
|
+
|
|
173
|
+
// Actors that don't have literal string IDs — these are the only ones
|
|
174
|
+
// that should appear in the index signature fallback, since actors with
|
|
175
|
+
// literal IDs are already covered by ToConcreteChildren.
|
|
176
|
+
|
|
177
|
+
/** Maps state IDs to their input types based on the StateSchema. */
|
|
178
|
+
|
|
179
|
+
/** @deprecated */
|
|
180
|
+
|
|
181
|
+
/** The terminal result published when an actor completes or errors. */
|
|
182
|
+
|
|
183
|
+
/** An executable effect that publishes an actor's terminal result. */
|
|
184
|
+
|
|
185
|
+
/** Mappers for subscribeTo - maps lifecycle events to machine events */
|
|
186
|
+
|
|
187
|
+
exports.SpecialTargets = SpecialTargets;
|
|
188
|
+
exports.createMachine = createMachine;
|
|
189
|
+
exports.createStateConfig = createStateConfig;
|