xstate 6.0.0-alpha.48 → 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 +23 -0
- package/dist/{StateMachine-b09d2b00.cjs.js → StateMachine-0adb3a70.cjs.js} +1 -1
- package/dist/{StateMachine-b3a890bf.development.cjs.js → StateMachine-29450e6d.development.cjs.js} +1 -1
- package/dist/{StateMachine-8329769a.esm.js → StateMachine-2af31c11.esm.js} +1 -1
- package/dist/{StateMachine-88b3c26a.development.esm.js → StateMachine-faf50c5c.development.esm.js} +1 -1
- package/dist/{createActor-27287c65.esm.js → createActor-268165d4.esm.js} +1 -1
- package/dist/{createActor-309d77eb.development.esm.js → createActor-88709f74.development.esm.js} +1 -1
- package/dist/{createActor-cc3d6dde.development.cjs.js → createActor-a1e0dffb.development.cjs.js} +0 -3
- package/dist/{createActor-9b41ade9.cjs.js → createActor-b4dd05ae.cjs.js} +0 -3
- 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/{effectDescriptor-b1f5deb6.esm.js → effectDescriptor-30c9a744.esm.js} +1 -1
- package/dist/{effectDescriptor-7707794b.development.esm.js → effectDescriptor-39d22100.development.esm.js} +1 -1
- package/dist/{effectDescriptor-a1678d06.development.cjs.js → effectDescriptor-7ff6802f.development.cjs.js} +1 -1
- package/dist/{effectDescriptor-bd36a33e.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-81d03bef.esm.js → types-3c3455f7.esm.js} +1 -1
- package/dist/{types-1793b8b6.development.esm.js → types-adda3842.development.esm.js} +1 -1
- package/dist/{types-7e468202.development.cjs.js → types-b3fea5bd.development.cjs.js} +1 -1
- package/dist/{types-9c1bc85f.cjs.js → types-fbabaeee.cjs.js} +1 -1
- package/dist/xstate-actors.cjs.js +1 -1
- package/dist/xstate-actors.development.cjs.js +1 -1
- package/dist/xstate-actors.development.esm.js +2 -2
- package/dist/xstate-actors.esm.js +2 -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 +2 -2
- package/dist/xstate-graph.development.cjs.js +2 -2
- package/dist/xstate-graph.development.esm.js +2 -2
- package/dist/xstate-graph.esm.js +2 -2
- package/dist/xstate-scxml.cjs.js +3 -3
- package/dist/xstate-scxml.development.cjs.js +3 -3
- package/dist/xstate-scxml.development.esm.js +3 -3
- package/dist/xstate-scxml.esm.js +3 -3
- 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 +6 -380
- package/dist/xstate.development.cjs.js +6 -380
- package/dist/xstate.development.esm.js +10 -384
- package/dist/xstate.esm.js +10 -384
- 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 +18 -2
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
export { TimeoutError, createAsyncLogic, createCallbackLogic, createEmptyActor, createEventObservableLogic, createLogic, createObservableLogic } from './xstate-actors.development.esm.js';
|
|
2
|
-
import { m as matchesEventDescriptor, t as toArray
|
|
3
|
-
export { A as Actor,
|
|
4
|
-
import { c as createMachine } from './types-
|
|
5
|
-
export { S as SpecialTargets, c as createMachine, a as createStateConfig } from './types-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export {
|
|
2
|
+
import { m as matchesEventDescriptor, t as toArray, p as parseDelayToMilliseconds, i as isAtomicStateNode, c as createActor } from './createActor-88709f74.development.esm.js';
|
|
3
|
+
export { A as Actor, h as __unsafe_getAllOwnEventDescriptors, k as checkStateIn, c as createActor, a as createListenerLogic, b as createSubscriptionLogic, u as deliverEvent, q as executeEffects, g as getInitialSnapshot, d as getNextSnapshot, f as getStateNodes, r as isBuiltInExecutableAction, e as isMachineSnapshot, l as listenerLogic, j as matchesState, n as pathToStateValue, v as runStep, w as stopActor, s as subscriptionLogic, x as terminateActor, o as toObserver } from './createActor-88709f74.development.esm.js';
|
|
4
|
+
import { c as createMachine } from './types-adda3842.development.esm.js';
|
|
5
|
+
export { S as SpecialTargets, c as createMachine, a as createStateConfig } from './types-adda3842.development.esm.js';
|
|
6
|
+
export { c as createFSM } from './fsm-e18a7cb4.development.esm.js';
|
|
7
|
+
import { S as StateMachine } from './StateMachine-faf50c5c.development.esm.js';
|
|
8
|
+
export { S as StateMachine, a as StateNode } from './StateMachine-faf50c5c.development.esm.js';
|
|
9
|
+
export { c as getEffectDescriptor, a as getInitialMicrosteps, g as getMicrosteps, b as getNextTransitions, i as initialTransition, t as transition } from './effectDescriptor-39d22100.development.esm.js';
|
|
9
10
|
import './validation-e69470ad.development.esm.js';
|
|
10
11
|
|
|
11
12
|
/**
|
|
@@ -32,7 +33,7 @@ import './validation-e69470ad.development.esm.js';
|
|
|
32
33
|
* ```
|
|
33
34
|
*/
|
|
34
35
|
function assertEvent(event, type) {
|
|
35
|
-
const types = toArray
|
|
36
|
+
const types = toArray(type);
|
|
36
37
|
const matches = types.some(descriptor => matchesEventDescriptor(event.type, descriptor));
|
|
37
38
|
if (!matches) {
|
|
38
39
|
const typesText = types.length === 1 ? `type matching "${types[0]}"` : `one of types matching "${types.join('", "')}"`;
|
|
@@ -40,381 +41,6 @@ function assertEvent(event, type) {
|
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
|
|
43
|
-
const emptySources = {
|
|
44
|
-
actions: {},
|
|
45
|
-
actors: {},
|
|
46
|
-
guards: {},
|
|
47
|
-
delays: {}
|
|
48
|
-
};
|
|
49
|
-
const emptyExecutableActions = [];
|
|
50
|
-
const emptyRawActions = [];
|
|
51
|
-
const builtInActionSet = new Set(Object.values(builtInActions));
|
|
52
|
-
function toArray(value) {
|
|
53
|
-
return value === undefined ? [] : Array.isArray(value) ? value : [value];
|
|
54
|
-
}
|
|
55
|
-
function resolveContext(context, input) {
|
|
56
|
-
return typeof context === 'function' ? context({
|
|
57
|
-
input
|
|
58
|
-
}) : context ?? {};
|
|
59
|
-
}
|
|
60
|
-
function resolveTransitionContext(context, args) {
|
|
61
|
-
return typeof context === 'function' ? context(args) : context;
|
|
62
|
-
}
|
|
63
|
-
function resolveInput(input, context, event) {
|
|
64
|
-
return typeof input === 'function' ? input({
|
|
65
|
-
context,
|
|
66
|
-
event
|
|
67
|
-
}) : input;
|
|
68
|
-
}
|
|
69
|
-
function mergeContextPatch(context, patch) {
|
|
70
|
-
for (const key of Object.keys(patch)) {
|
|
71
|
-
if (!Object.prototype.hasOwnProperty.call(context, key) || !Object.is(context[key], patch[key])) {
|
|
72
|
-
return {
|
|
73
|
-
...context,
|
|
74
|
-
...patch
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return context;
|
|
79
|
-
}
|
|
80
|
-
function createSnapshot(value, context, input, machine, stateInput) {
|
|
81
|
-
return {
|
|
82
|
-
status: 'active',
|
|
83
|
-
output: undefined,
|
|
84
|
-
error: undefined,
|
|
85
|
-
value,
|
|
86
|
-
context,
|
|
87
|
-
input,
|
|
88
|
-
children: {},
|
|
89
|
-
timers: {},
|
|
90
|
-
_nextTimerId: 0,
|
|
91
|
-
_stateInput: stateInput,
|
|
92
|
-
machine
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
function cloneSnapshot(snapshot, value, context, stateInput) {
|
|
96
|
-
return {
|
|
97
|
-
status: snapshot.status,
|
|
98
|
-
output: snapshot.output,
|
|
99
|
-
error: snapshot.error,
|
|
100
|
-
value,
|
|
101
|
-
context,
|
|
102
|
-
input: snapshot.input,
|
|
103
|
-
children: snapshot.children,
|
|
104
|
-
timers: snapshot.timers,
|
|
105
|
-
_nextTimerId: snapshot._nextTimerId,
|
|
106
|
-
// Carried across state changes: dropping these would let a later spawn
|
|
107
|
-
// reuse the id of a still-running child.
|
|
108
|
-
_nextActorIds: snapshot._nextActorIds,
|
|
109
|
-
_stateInput: stateInput,
|
|
110
|
-
machine: snapshot.machine
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
function stopSnapshot(snapshot) {
|
|
114
|
-
return {
|
|
115
|
-
status: 'stopped',
|
|
116
|
-
output: undefined,
|
|
117
|
-
error: undefined,
|
|
118
|
-
value: snapshot.value,
|
|
119
|
-
context: snapshot.context,
|
|
120
|
-
input: undefined,
|
|
121
|
-
children: snapshot.children,
|
|
122
|
-
timers: snapshot.timers,
|
|
123
|
-
_nextTimerId: snapshot._nextTimerId,
|
|
124
|
-
_nextActorIds: snapshot._nextActorIds,
|
|
125
|
-
_stateInput: snapshot._stateInput,
|
|
126
|
-
machine: snapshot.machine
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
function assertNoStringTransitions(config) {
|
|
130
|
-
for (const [stateKey, stateConfig] of Object.entries(config.states)) {
|
|
131
|
-
for (const [eventType, transitionConfig] of Object.entries(stateConfig.on ?? {})) {
|
|
132
|
-
for (const transition of toArray(transitionConfig)) {
|
|
133
|
-
if (typeof transition === 'string') {
|
|
134
|
-
const target = transition;
|
|
135
|
-
throw new Error(`Invalid transition for "${stateKey}.${eventType}": use { target: "${target}" } instead of a string target.`);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
function resolveSimpleEnqueuedActions(rawActions) {
|
|
142
|
-
const executableActions = [];
|
|
143
|
-
for (const action of rawActions) {
|
|
144
|
-
if (!action || typeof action !== 'object' || !('action' in action) || typeof action.action !== 'function' || builtInActionSet.has(action.action) || '_special' in action.action) {
|
|
145
|
-
return undefined;
|
|
146
|
-
}
|
|
147
|
-
executableActions.push({
|
|
148
|
-
kind: 'action',
|
|
149
|
-
type: action.action.name || '(anonymous)',
|
|
150
|
-
params: undefined,
|
|
151
|
-
args: action.args,
|
|
152
|
-
action: action.action,
|
|
153
|
-
exec() {
|
|
154
|
-
return this.action?.(...this.args);
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
return executableActions;
|
|
159
|
-
}
|
|
160
|
-
function createFSM(config) {
|
|
161
|
-
const machine = {
|
|
162
|
-
id: config.id ?? '(fsm)',
|
|
163
|
-
sources: emptySources
|
|
164
|
-
};
|
|
165
|
-
assertNoStringTransitions(config);
|
|
166
|
-
const runActions = (snapshot, event, actorScope, rawActions) => {
|
|
167
|
-
if (!rawActions?.length) {
|
|
168
|
-
return [snapshot, emptyExecutableActions];
|
|
169
|
-
}
|
|
170
|
-
const simpleExecutableActions = resolveSimpleEnqueuedActions(rawActions);
|
|
171
|
-
if (simpleExecutableActions) {
|
|
172
|
-
return [snapshot, simpleExecutableActions];
|
|
173
|
-
}
|
|
174
|
-
return resolveActionsWithContext(snapshot, event, actorScope, rawActions);
|
|
175
|
-
};
|
|
176
|
-
const runStateActions = (snapshot, event, actorScope, actionsConfig, stateInput, internalQueue) => {
|
|
177
|
-
if (!actionsConfig) {
|
|
178
|
-
return [snapshot, emptyExecutableActions];
|
|
179
|
-
}
|
|
180
|
-
const actions = [];
|
|
181
|
-
const enq = createTransitionEnqueue(actorScope, actions, internalQueue, true);
|
|
182
|
-
let context;
|
|
183
|
-
const actionCount = Array.isArray(actionsConfig) ? actionsConfig.length : 1;
|
|
184
|
-
for (let i = 0; i < actionCount; i++) {
|
|
185
|
-
const action = Array.isArray(actionsConfig) ? actionsConfig[i] : actionsConfig;
|
|
186
|
-
const result = action(withActorScope({
|
|
187
|
-
context: context ?? snapshot.context,
|
|
188
|
-
event: event,
|
|
189
|
-
input: stateInput,
|
|
190
|
-
value: snapshot.value,
|
|
191
|
-
children: snapshot.children
|
|
192
|
-
}, actorScope), enq);
|
|
193
|
-
if (result?.context !== undefined) {
|
|
194
|
-
const currentContext = context ?? snapshot.context;
|
|
195
|
-
const nextContext = mergeContextPatch(currentContext, result.context);
|
|
196
|
-
if (nextContext !== currentContext) {
|
|
197
|
-
context = nextContext;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
const nextSnapshot = context !== undefined ? cloneSnapshot(snapshot, snapshot.value, context, snapshot._stateInput) : snapshot;
|
|
202
|
-
return runActions(nextSnapshot, event, actorScope, actions);
|
|
203
|
-
};
|
|
204
|
-
const selectTransition = (snapshot, event, actorScope, internalQueue) => {
|
|
205
|
-
const state = config.states[snapshot.value];
|
|
206
|
-
const transitionsConfig = state?.on?.[event.type];
|
|
207
|
-
if (!transitionsConfig) {
|
|
208
|
-
return undefined;
|
|
209
|
-
}
|
|
210
|
-
const transitionCount = Array.isArray(transitionsConfig) ? transitionsConfig.length : 1;
|
|
211
|
-
for (let i = 0; i < transitionCount; i++) {
|
|
212
|
-
const transition = Array.isArray(transitionsConfig) ? transitionsConfig[i] : transitionsConfig;
|
|
213
|
-
const args = withActorScope({
|
|
214
|
-
context: snapshot.context,
|
|
215
|
-
event,
|
|
216
|
-
input: snapshot.input,
|
|
217
|
-
value: snapshot.value,
|
|
218
|
-
children: snapshot.children
|
|
219
|
-
}, actorScope);
|
|
220
|
-
if (typeof transition === 'function') {
|
|
221
|
-
const actions = [];
|
|
222
|
-
const enq = createTransitionEnqueue(actorScope, actions, internalQueue, true);
|
|
223
|
-
const result = transition(args, enq);
|
|
224
|
-
if (!result) {
|
|
225
|
-
if (actions.length) {
|
|
226
|
-
return {
|
|
227
|
-
actions
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
continue;
|
|
231
|
-
}
|
|
232
|
-
return {
|
|
233
|
-
target: result.target,
|
|
234
|
-
context: result.context,
|
|
235
|
-
input: result.input,
|
|
236
|
-
actions
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
if ('guard' in transition && transition.guard && !transition.guard(args)) {
|
|
240
|
-
continue;
|
|
241
|
-
}
|
|
242
|
-
return {
|
|
243
|
-
target: transition.target,
|
|
244
|
-
context: resolveTransitionContext(transition.context, args),
|
|
245
|
-
input: transition.input,
|
|
246
|
-
actions: 'actions' in transition && transition.actions ? toArray(transition.actions) : emptyRawActions
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
return undefined;
|
|
250
|
-
};
|
|
251
|
-
const transitionCore = (snapshot, event, actorScope) => {
|
|
252
|
-
if (snapshot.status !== 'active') {
|
|
253
|
-
return [snapshot, []];
|
|
254
|
-
}
|
|
255
|
-
if (event.type === XSTATE_STOP) {
|
|
256
|
-
const actions = [];
|
|
257
|
-
const enqueue = createTransitionEnqueue(actorScope, actions, []);
|
|
258
|
-
for (const id of Object.keys(snapshot.timers)) {
|
|
259
|
-
enqueue.cancel(id);
|
|
260
|
-
}
|
|
261
|
-
const [withoutTimers, cancelEffects] = resolveActionsWithContext(snapshot, event, actorScope, actions);
|
|
262
|
-
return [stopSnapshot(withoutTimers), cancelEffects];
|
|
263
|
-
}
|
|
264
|
-
if (event.type === XSTATE_TIMER) {
|
|
265
|
-
const timer = snapshot.timers[event.id];
|
|
266
|
-
if (!timer) {
|
|
267
|
-
return [snapshot, emptyExecutableActions];
|
|
268
|
-
}
|
|
269
|
-
const timers = {
|
|
270
|
-
...snapshot.timers
|
|
271
|
-
};
|
|
272
|
-
delete timers[timer.id];
|
|
273
|
-
const nextSnapshot = {
|
|
274
|
-
...snapshot,
|
|
275
|
-
timers
|
|
276
|
-
};
|
|
277
|
-
if (timer.type === '@xstate.raise') {
|
|
278
|
-
return transitionCore(nextSnapshot, timer.event, actorScope);
|
|
279
|
-
}
|
|
280
|
-
const target = timer.target === 'self' ? actorScope.self : timer.target;
|
|
281
|
-
return [nextSnapshot, [createSendToEffect(actorScope, target, timer.event)]];
|
|
282
|
-
}
|
|
283
|
-
const stateConfig = config.states[snapshot.value];
|
|
284
|
-
const directTransition = stateConfig?.on?.[event.type];
|
|
285
|
-
if (!directTransition) {
|
|
286
|
-
return [snapshot, emptyExecutableActions];
|
|
287
|
-
}
|
|
288
|
-
if (!Array.isArray(directTransition) && typeof directTransition !== 'function' && !('guard' in directTransition) && !('actions' in directTransition && directTransition.actions) && typeof directTransition.input !== 'function') {
|
|
289
|
-
const target = directTransition.target ?? snapshot.value;
|
|
290
|
-
const stateChanged = target !== snapshot.value;
|
|
291
|
-
if (stateChanged && (stateConfig.exit || config.states[target]?.entry)) ; else {
|
|
292
|
-
const hasContext = directTransition.context !== undefined;
|
|
293
|
-
const hasInput = directTransition.input !== undefined;
|
|
294
|
-
const resolvedContext = !isLazyActorScope(actorScope) ? resolveTransitionContext(directTransition.context, {
|
|
295
|
-
context: snapshot.context,
|
|
296
|
-
event,
|
|
297
|
-
input: snapshot.input,
|
|
298
|
-
value: snapshot.value,
|
|
299
|
-
self: actorScope.self,
|
|
300
|
-
system: actorScope.system,
|
|
301
|
-
parent: actorScope.self._parent,
|
|
302
|
-
children: snapshot.children
|
|
303
|
-
}) : typeof directTransition.context === 'function' ? directTransition.context(withActorScope({
|
|
304
|
-
context: snapshot.context,
|
|
305
|
-
event,
|
|
306
|
-
input: snapshot.input,
|
|
307
|
-
value: snapshot.value,
|
|
308
|
-
children: snapshot.children
|
|
309
|
-
}, actorScope)) : directTransition.context;
|
|
310
|
-
const context = hasContext && resolvedContext ? mergeContextPatch(snapshot.context, resolvedContext) : snapshot.context;
|
|
311
|
-
if (!stateChanged && context === snapshot.context && !hasInput && snapshot._stateInput === undefined) {
|
|
312
|
-
return [snapshot, emptyExecutableActions];
|
|
313
|
-
}
|
|
314
|
-
return [cloneSnapshot(snapshot, target, context, hasInput ? resolveInput(directTransition.input, context, event) : undefined), emptyExecutableActions];
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
if (typeof directTransition === 'function' && directTransition.length < 2 && !stateConfig?.exit) {
|
|
318
|
-
const result = directTransition(withActorScope({
|
|
319
|
-
context: snapshot.context,
|
|
320
|
-
event,
|
|
321
|
-
input: snapshot.input,
|
|
322
|
-
value: snapshot.value,
|
|
323
|
-
children: snapshot.children
|
|
324
|
-
}, actorScope), undefined);
|
|
325
|
-
if (result) {
|
|
326
|
-
const target = result.target ?? snapshot.value;
|
|
327
|
-
if (!config.states[target]?.entry) {
|
|
328
|
-
const hasContext = result.context !== undefined;
|
|
329
|
-
const hasInput = result.input !== undefined;
|
|
330
|
-
const context = hasContext && result.context ? mergeContextPatch(snapshot.context, result.context) : snapshot.context;
|
|
331
|
-
if (target === snapshot.value && context === snapshot.context && !hasInput && snapshot._stateInput === undefined) {
|
|
332
|
-
return [snapshot, emptyExecutableActions];
|
|
333
|
-
}
|
|
334
|
-
return [cloneSnapshot(snapshot, target, context, hasInput ? resolveInput(result.input, context, event) : undefined), emptyExecutableActions];
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
let nextSnapshot = snapshot;
|
|
339
|
-
const executableActions = [];
|
|
340
|
-
const internalQueue = [event];
|
|
341
|
-
let iterations = 0;
|
|
342
|
-
while (internalQueue.length) {
|
|
343
|
-
if (++iterations > 1000) {
|
|
344
|
-
throw new Error('FSM microstep count exceeded 1000');
|
|
345
|
-
}
|
|
346
|
-
const nextEvent = internalQueue.shift();
|
|
347
|
-
const selected = selectTransition(nextSnapshot, nextEvent, actorScope, internalQueue);
|
|
348
|
-
if (!selected) {
|
|
349
|
-
continue;
|
|
350
|
-
}
|
|
351
|
-
const nextValue = selected.target ?? nextSnapshot.value;
|
|
352
|
-
const stateChanged = nextValue !== nextSnapshot.value;
|
|
353
|
-
if (stateChanged) {
|
|
354
|
-
const [exited, exitActions] = runStateActions(nextSnapshot, nextEvent, actorScope, config.states[nextSnapshot.value]?.exit, nextSnapshot._stateInput, internalQueue);
|
|
355
|
-
nextSnapshot = exited;
|
|
356
|
-
executableActions.push(...exitActions);
|
|
357
|
-
}
|
|
358
|
-
let context = nextSnapshot.context;
|
|
359
|
-
if (selected.context !== undefined) {
|
|
360
|
-
context = mergeContextPatch(context, selected.context);
|
|
361
|
-
}
|
|
362
|
-
const hasInput = selected.input !== undefined;
|
|
363
|
-
const stateInput = hasInput ? resolveInput(selected.input, context, nextEvent) : undefined;
|
|
364
|
-
if (stateChanged || context !== nextSnapshot.context || hasInput || nextSnapshot._stateInput !== undefined) {
|
|
365
|
-
nextSnapshot = cloneSnapshot(nextSnapshot, nextValue, context, stateInput);
|
|
366
|
-
}
|
|
367
|
-
const [afterTransition, transitionActions] = runActions(nextSnapshot, nextEvent, actorScope, selected.actions);
|
|
368
|
-
nextSnapshot = afterTransition;
|
|
369
|
-
executableActions.push(...transitionActions);
|
|
370
|
-
if (stateChanged) {
|
|
371
|
-
const [entered, entryActions] = runStateActions(nextSnapshot, nextEvent, actorScope, config.states[nextValue]?.entry, stateInput, internalQueue);
|
|
372
|
-
nextSnapshot = entered;
|
|
373
|
-
executableActions.push(...entryActions);
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
return [nextSnapshot, executableActions];
|
|
377
|
-
};
|
|
378
|
-
const transition = (...args) => {
|
|
379
|
-
beginSpawnAllocation(args[2]);
|
|
380
|
-
const [nextSnapshot, effects] = transitionCore(...args);
|
|
381
|
-
return finalizeTransitionResult(args[2], args[0], [nextSnapshot, [...effects, ...deriveDeferredStarts(effects)]]);
|
|
382
|
-
};
|
|
383
|
-
const logic = {
|
|
384
|
-
id: config.id,
|
|
385
|
-
config,
|
|
386
|
-
transition,
|
|
387
|
-
initialTransition: (input, actorScope) => {
|
|
388
|
-
beginSpawnAllocation(actorScope);
|
|
389
|
-
const context = resolveContext(config.context, input);
|
|
390
|
-
const snapshot = createSnapshot(config.initial, context, input, machine);
|
|
391
|
-
const internalQueue = [];
|
|
392
|
-
let [nextSnapshot, actions] = runStateActions(snapshot, {
|
|
393
|
-
type: XSTATE_INIT
|
|
394
|
-
}, actorScope, config.states[config.initial]?.entry, undefined, internalQueue);
|
|
395
|
-
if (!actions.length) {
|
|
396
|
-
actions = [];
|
|
397
|
-
}
|
|
398
|
-
while (internalQueue.length) {
|
|
399
|
-
const [raisedSnapshot, raisedActions] = transitionCore(nextSnapshot, internalQueue.shift(), actorScope);
|
|
400
|
-
nextSnapshot = raisedSnapshot;
|
|
401
|
-
actions.push(...raisedActions);
|
|
402
|
-
}
|
|
403
|
-
return finalizeTransitionResult(actorScope, undefined, [nextSnapshot, [...actions, ...deriveDeferredStarts(actions)]]);
|
|
404
|
-
},
|
|
405
|
-
getInitialSnapshot: (actorScope, input) => logic.initialTransition(input, actorScope)[0],
|
|
406
|
-
getPersistedSnapshot: ({
|
|
407
|
-
machine: _,
|
|
408
|
-
...snapshot
|
|
409
|
-
}) => snapshot,
|
|
410
|
-
restoreSnapshot: snapshot => ({
|
|
411
|
-
...snapshot,
|
|
412
|
-
machine: machine
|
|
413
|
-
})
|
|
414
|
-
};
|
|
415
|
-
return logic;
|
|
416
|
-
}
|
|
417
|
-
|
|
418
44
|
function delayToMs(delay) {
|
|
419
45
|
const parsedDelay = parseDelayToMilliseconds(delay);
|
|
420
46
|
if (parsedDelay !== undefined) return parsedDelay;
|
|
@@ -1964,4 +1590,4 @@ function waitFor(actorRef, predicate, options) {
|
|
|
1964
1590
|
});
|
|
1965
1591
|
}
|
|
1966
1592
|
|
|
1967
|
-
export { SimulatedClock, assertEvent,
|
|
1593
|
+
export { SimulatedClock, assertEvent, createMachineFromConfig, createSystem, isTypeSchema, machineConfigToJSON, machineVersions, mapState, serializeMachine, setup, toPromise, types, waitFor };
|