xstate 5.31.0 → 5.32.0
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/actions/package.json +3 -3
- package/actors/package.json +3 -3
- package/dev/package.json +3 -3
- package/dist/{StateMachine-b9937861.esm.js → StateMachine-45e79c35.esm.js} +2 -2
- package/dist/{StateMachine-a2514a01.development.cjs.js → StateMachine-be2e51a3.development.cjs.js} +39 -39
- package/dist/{StateMachine-880c1b22.development.esm.js → StateMachine-e0178d48.development.esm.js} +2 -2
- package/dist/{StateMachine-37420c93.cjs.js → StateMachine-e6732977.cjs.js} +39 -39
- package/dist/{assign-c15c199c.esm.js → assign-2aa58daa.esm.js} +1 -1
- package/dist/{assign-6da0bff4.development.cjs.js → assign-927227d6.development.cjs.js} +7 -7
- package/dist/{assign-53a98e5d.cjs.js → assign-e8f2bd75.cjs.js} +6 -6
- package/dist/{assign-4f7ce317.development.esm.js → assign-f338cee3.development.esm.js} +1 -1
- package/dist/declarations/src/index.d.ts +1 -1
- package/dist/declarations/src/inspection.d.ts +6 -1
- package/dist/{log-8ca142b5.development.cjs.js → log-029f180b.development.cjs.js} +10 -10
- package/dist/{log-3e4dba89.development.esm.js → log-5a37e0ee.development.esm.js} +2 -2
- package/dist/{log-ce7cb9aa.esm.js → log-605ef461.esm.js} +2 -2
- package/dist/{log-279b177f.cjs.js → log-fedf0966.cjs.js} +8 -8
- package/dist/{raise-b724c245.development.esm.js → raise-74097812.development.esm.js} +5 -14
- package/dist/{raise-69f5aed0.cjs.js → raise-7c948725.cjs.js} +6 -15
- package/dist/{raise-6e65c93f.development.cjs.js → raise-964cd4e9.development.cjs.js} +6 -15
- package/dist/{raise-56f87e05.esm.js → raise-e974d1c9.esm.js} +5 -14
- package/dist/xstate-actions.cjs.d.mts +2 -0
- package/dist/xstate-actions.cjs.d.ts +2 -0
- package/dist/xstate-actions.cjs.js +23 -0
- package/dist/xstate-actions.development.cjs.js +23 -0
- package/dist/xstate-actions.development.esm.js +4 -0
- package/dist/xstate-actions.esm.js +4 -0
- package/dist/xstate-actions.umd.min.js.map +1 -0
- package/dist/xstate-actors.cjs.d.mts +2 -0
- package/dist/xstate-actors.cjs.d.ts +2 -0
- package/{actors/dist → dist}/xstate-actors.cjs.js +7 -7
- package/{actors/dist → dist}/xstate-actors.development.cjs.js +7 -7
- package/{actors/dist → dist}/xstate-actors.development.esm.js +2 -2
- package/{actors/dist → dist}/xstate-actors.esm.js +2 -2
- package/dist/xstate-actors.umd.min.js.map +1 -0
- package/dist/xstate-dev.cjs.d.mts +2 -0
- package/dist/xstate-dev.cjs.d.ts +2 -0
- package/dist/xstate-dev.umd.min.js.map +1 -0
- package/dist/xstate-graph.cjs.d.mts +2 -0
- package/dist/xstate-graph.cjs.d.ts +2 -0
- package/{graph/dist/xstate-graph.development.cjs.js → dist/xstate-graph.cjs.js} +9 -9
- package/{graph/dist/xstate-graph.cjs.js → dist/xstate-graph.development.cjs.js} +9 -9
- package/{graph/dist → dist}/xstate-graph.development.esm.js +5 -5
- package/{graph/dist → dist}/xstate-graph.esm.js +5 -5
- package/dist/xstate-graph.umd.min.js +2 -0
- package/dist/xstate-graph.umd.min.js.map +1 -0
- package/dist/xstate-guards.cjs.d.mts +2 -0
- package/dist/xstate-guards.cjs.d.ts +2 -0
- package/dist/xstate-guards.cjs.js +14 -0
- package/dist/xstate-guards.development.cjs.js +14 -0
- package/dist/xstate-guards.development.esm.js +2 -0
- package/dist/xstate-guards.esm.js +2 -0
- package/dist/xstate-guards.umd.min.js.map +1 -0
- package/dist/xstate.cjs.js +44 -44
- package/dist/xstate.development.cjs.js +44 -44
- package/dist/xstate.development.esm.js +10 -10
- package/dist/xstate.esm.js +10 -10
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/graph/package.json +3 -3
- package/guards/package.json +3 -3
- package/package.json +41 -41
- package/actions/dist/xstate-actions.cjs.d.mts +0 -2
- package/actions/dist/xstate-actions.cjs.d.ts +0 -2
- package/actions/dist/xstate-actions.cjs.js +0 -23
- package/actions/dist/xstate-actions.development.cjs.js +0 -23
- package/actions/dist/xstate-actions.development.esm.js +0 -4
- package/actions/dist/xstate-actions.esm.js +0 -4
- package/actions/dist/xstate-actions.umd.min.js.map +0 -1
- package/actors/dist/xstate-actors.cjs.d.mts +0 -2
- package/actors/dist/xstate-actors.cjs.d.ts +0 -2
- package/actors/dist/xstate-actors.umd.min.js.map +0 -1
- package/dev/dist/xstate-dev.cjs.d.mts +0 -2
- package/dev/dist/xstate-dev.cjs.d.ts +0 -2
- package/dev/dist/xstate-dev.umd.min.js.map +0 -1
- package/graph/dist/xstate-graph.cjs.d.mts +0 -2
- package/graph/dist/xstate-graph.cjs.d.ts +0 -2
- package/graph/dist/xstate-graph.umd.min.js +0 -2
- package/graph/dist/xstate-graph.umd.min.js.map +0 -1
- package/guards/dist/xstate-guards.cjs.d.mts +0 -2
- package/guards/dist/xstate-guards.cjs.d.ts +0 -2
- package/guards/dist/xstate-guards.cjs.js +0 -14
- package/guards/dist/xstate-guards.development.cjs.js +0 -14
- package/guards/dist/xstate-guards.development.esm.js +0 -2
- package/guards/dist/xstate-guards.esm.js +0 -2
- package/guards/dist/xstate-guards.umd.min.js.map +0 -1
- /package/{actions/dist → dist}/xstate-actions.cjs.mjs +0 -0
- /package/{actions/dist → dist}/xstate-actions.development.cjs.mjs +0 -0
- /package/{actions/dist → dist}/xstate-actions.umd.min.js +0 -0
- /package/{actors/dist → dist}/xstate-actors.cjs.mjs +0 -0
- /package/{actors/dist → dist}/xstate-actors.development.cjs.mjs +0 -0
- /package/{actors/dist → dist}/xstate-actors.umd.min.js +0 -0
- /package/{dev/dist → dist}/xstate-dev.cjs.js +0 -0
- /package/{dev/dist → dist}/xstate-dev.cjs.mjs +0 -0
- /package/{dev/dist → dist}/xstate-dev.development.cjs.js +0 -0
- /package/{dev/dist → dist}/xstate-dev.development.cjs.mjs +0 -0
- /package/{dev/dist → dist}/xstate-dev.development.esm.js +0 -0
- /package/{dev/dist → dist}/xstate-dev.esm.js +0 -0
- /package/{dev/dist → dist}/xstate-dev.umd.min.js +0 -0
- /package/{graph/dist → dist}/xstate-graph.cjs.mjs +0 -0
- /package/{graph/dist → dist}/xstate-graph.development.cjs.mjs +0 -0
- /package/{guards/dist → dist}/xstate-guards.cjs.mjs +0 -0
- /package/{guards/dist → dist}/xstate-guards.development.cjs.mjs +0 -0
- /package/{guards/dist → dist}/xstate-guards.umd.min.js +0 -0
package/actions/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"main": "dist/xstate-actions.cjs.js",
|
|
3
|
-
"module": "dist/xstate-actions.esm.js",
|
|
4
|
-
"umd:main": "dist/xstate-actions.umd.min.js",
|
|
2
|
+
"main": "../dist/xstate-actions.cjs.js",
|
|
3
|
+
"module": "../dist/xstate-actions.esm.js",
|
|
4
|
+
"umd:main": "../dist/xstate-actions.umd.min.js",
|
|
5
5
|
"preconstruct": {
|
|
6
6
|
"umdName": "XStateActions"
|
|
7
7
|
}
|
package/actors/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"main": "dist/xstate-actors.cjs.js",
|
|
3
|
-
"module": "dist/xstate-actors.esm.js",
|
|
4
|
-
"umd:main": "dist/xstate-actors.umd.min.js",
|
|
2
|
+
"main": "../dist/xstate-actors.cjs.js",
|
|
3
|
+
"module": "../dist/xstate-actors.esm.js",
|
|
4
|
+
"umd:main": "../dist/xstate-actors.umd.min.js",
|
|
5
5
|
"preconstruct": {
|
|
6
6
|
"umdName": "XStateActors"
|
|
7
7
|
}
|
package/dev/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"main": "dist/xstate-dev.cjs.js",
|
|
3
|
-
"module": "dist/xstate-dev.esm.js",
|
|
4
|
-
"umd:main": "dist/xstate-dev.umd.min.js",
|
|
2
|
+
"main": "../dist/xstate-dev.cjs.js",
|
|
3
|
+
"module": "../dist/xstate-dev.esm.js",
|
|
4
|
+
"umd:main": "../dist/xstate-dev.umd.min.js",
|
|
5
5
|
"preconstruct": {
|
|
6
6
|
"umdName": "XStateDev"
|
|
7
7
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as STATE_DELIMITER, y as mapValues, t as toArray, z as formatTransitions, B as toTransitionConfigArray, C as formatTransition, N as NULL_EVENT, D as evaluateGuard, E as createInvokeId, F as getDelayedTransitions, G as formatInitialTransition, H as getCandidates, I as formatRouteTransitions, J as resolveStateValue, K as getAllStateNodes, p as getStateNodes, L as createMachineSnapshot, M as isInFinalState, d as macrostep, O as transitionNode, P as resolveActionsAndContext, e as createInitEvent, f as initialMicrostep, Q as toStatePath, R as isStateId, T as getStateNodeByPath, U as getPersistedSnapshot, V as resolveReferencedActor, c as createActor, $ as $$ACTOR_TYPE } from './raise-
|
|
2
|
-
import { a as assign } from './assign-
|
|
1
|
+
import { S as STATE_DELIMITER, y as mapValues, t as toArray, z as formatTransitions, B as toTransitionConfigArray, C as formatTransition, N as NULL_EVENT, D as evaluateGuard, E as createInvokeId, F as getDelayedTransitions, G as formatInitialTransition, H as getCandidates, I as formatRouteTransitions, J as resolveStateValue, K as getAllStateNodes, p as getStateNodes, L as createMachineSnapshot, M as isInFinalState, d as macrostep, O as transitionNode, P as resolveActionsAndContext, e as createInitEvent, f as initialMicrostep, Q as toStatePath, R as isStateId, T as getStateNodeByPath, U as getPersistedSnapshot, V as resolveReferencedActor, c as createActor, $ as $$ACTOR_TYPE } from './raise-e974d1c9.esm.js';
|
|
2
|
+
import { a as assign } from './assign-2aa58daa.esm.js';
|
|
3
3
|
|
|
4
4
|
const cache = new WeakMap();
|
|
5
5
|
function memo(object, key, fn) {
|
package/dist/{StateMachine-a2514a01.development.cjs.js → StateMachine-be2e51a3.development.cjs.js}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var assign = require('./assign-
|
|
3
|
+
var dist_xstateGuards = require('./raise-964cd4e9.development.cjs.js');
|
|
4
|
+
var assign = require('./assign-927227d6.development.cjs.js');
|
|
5
5
|
|
|
6
6
|
const cache = new WeakMap();
|
|
7
7
|
function memo(object, key, fn) {
|
|
@@ -99,12 +99,12 @@ class StateNode {
|
|
|
99
99
|
this.key = options._key;
|
|
100
100
|
this.machine = options._machine;
|
|
101
101
|
this.path = this.parent ? this.parent.path.concat(this.key) : [];
|
|
102
|
-
this.id = this.config.id || [this.machine.id, ...this.path].join(
|
|
102
|
+
this.id = this.config.id || [this.machine.id, ...this.path].join(dist_xstateGuards.STATE_DELIMITER);
|
|
103
103
|
this.type = this.config.type || (this.config.states && Object.keys(this.config.states).length ? 'compound' : this.config.history ? 'history' : 'atomic');
|
|
104
104
|
this.description = this.config.description;
|
|
105
105
|
this.order = this.machine.idMap.size;
|
|
106
106
|
this.machine.idMap.set(this.id, this);
|
|
107
|
-
this.states = this.config.states ?
|
|
107
|
+
this.states = this.config.states ? dist_xstateGuards.mapValues(this.config.states, (stateConfig, key) => {
|
|
108
108
|
const stateNode = new StateNode(stateConfig, {
|
|
109
109
|
_parent: this,
|
|
110
110
|
_key: key,
|
|
@@ -118,18 +118,18 @@ class StateNode {
|
|
|
118
118
|
|
|
119
119
|
// History config
|
|
120
120
|
this.history = this.config.history === true ? 'shallow' : this.config.history || false;
|
|
121
|
-
this.entry =
|
|
122
|
-
this.exit =
|
|
121
|
+
this.entry = dist_xstateGuards.toArray(this.config.entry).slice();
|
|
122
|
+
this.exit = dist_xstateGuards.toArray(this.config.exit).slice();
|
|
123
123
|
this.meta = this.config.meta;
|
|
124
124
|
this.output = this.type === 'final' || !this.parent ? this.config.output : undefined;
|
|
125
|
-
this.tags =
|
|
125
|
+
this.tags = dist_xstateGuards.toArray(config.tags).slice();
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
/** @internal */
|
|
129
129
|
_initialize() {
|
|
130
|
-
this.transitions =
|
|
130
|
+
this.transitions = dist_xstateGuards.formatTransitions(this);
|
|
131
131
|
if (this.config.always) {
|
|
132
|
-
this.always =
|
|
132
|
+
this.always = dist_xstateGuards.toTransitionConfigArray(this.config.always).map(t => dist_xstateGuards.formatTransition(this, dist_xstateGuards.NULL_EVENT, t));
|
|
133
133
|
}
|
|
134
134
|
Object.keys(this.states).forEach(key => {
|
|
135
135
|
this.states[key]._initialize();
|
|
@@ -157,7 +157,7 @@ class StateNode {
|
|
|
157
157
|
})
|
|
158
158
|
} : undefined,
|
|
159
159
|
history: this.history,
|
|
160
|
-
states:
|
|
160
|
+
states: dist_xstateGuards.mapValues(this.states, state => {
|
|
161
161
|
return state.definition;
|
|
162
162
|
}),
|
|
163
163
|
on: this.on,
|
|
@@ -183,13 +183,13 @@ class StateNode {
|
|
|
183
183
|
|
|
184
184
|
/** The logic invoked as actors by this state node. */
|
|
185
185
|
get invoke() {
|
|
186
|
-
return memo(this, 'invoke', () =>
|
|
186
|
+
return memo(this, 'invoke', () => dist_xstateGuards.toArray(this.config.invoke).map((invokeConfig, i) => {
|
|
187
187
|
const {
|
|
188
188
|
src,
|
|
189
189
|
systemId
|
|
190
190
|
} = invokeConfig;
|
|
191
|
-
const resolvedId = invokeConfig.id ??
|
|
192
|
-
const sourceName = typeof src === 'string' ? src : `xstate.invoke.${
|
|
191
|
+
const resolvedId = invokeConfig.id ?? dist_xstateGuards.createInvokeId(this.id, i);
|
|
192
|
+
const sourceName = typeof src === 'string' ? src : `xstate.invoke.${dist_xstateGuards.createInvokeId(this.id, i)}`;
|
|
193
193
|
return {
|
|
194
194
|
...invokeConfig,
|
|
195
195
|
src: sourceName,
|
|
@@ -224,10 +224,10 @@ class StateNode {
|
|
|
224
224
|
});
|
|
225
225
|
}
|
|
226
226
|
get after() {
|
|
227
|
-
return memo(this, 'delayedTransitions', () =>
|
|
227
|
+
return memo(this, 'delayedTransitions', () => dist_xstateGuards.getDelayedTransitions(this));
|
|
228
228
|
}
|
|
229
229
|
get initial() {
|
|
230
|
-
return memo(this, 'initial', () =>
|
|
230
|
+
return memo(this, 'initial', () => dist_xstateGuards.formatInitialTransition(this, this.config.initial));
|
|
231
231
|
}
|
|
232
232
|
|
|
233
233
|
/** @internal */
|
|
@@ -235,7 +235,7 @@ class StateNode {
|
|
|
235
235
|
const eventType = event.type;
|
|
236
236
|
const actions = [];
|
|
237
237
|
let selectedTransition;
|
|
238
|
-
const candidates = memo(this, `candidates-${eventType}`, () =>
|
|
238
|
+
const candidates = memo(this, `candidates-${eventType}`, () => dist_xstateGuards.getCandidates(this, eventType));
|
|
239
239
|
for (const candidate of candidates) {
|
|
240
240
|
const {
|
|
241
241
|
guard
|
|
@@ -243,7 +243,7 @@ class StateNode {
|
|
|
243
243
|
const resolvedContext = snapshot.context;
|
|
244
244
|
let guardPassed = false;
|
|
245
245
|
try {
|
|
246
|
-
guardPassed = !guard ||
|
|
246
|
+
guardPassed = !guard || dist_xstateGuards.evaluateGuard(guard, resolvedContext, event, snapshot);
|
|
247
247
|
} catch (err) {
|
|
248
248
|
const guardType = typeof guard === 'string' ? guard : typeof guard === 'object' ? guard.type : undefined;
|
|
249
249
|
throw new Error(`Unable to evaluate guard ${guardType ? `'${guardType}' ` : ''}in transition for event '${eventType}' in state node '${this.id}':\n${err.message}`);
|
|
@@ -334,7 +334,7 @@ class StateMachine {
|
|
|
334
334
|
_machine: this
|
|
335
335
|
});
|
|
336
336
|
this.root._initialize();
|
|
337
|
-
|
|
337
|
+
dist_xstateGuards.formatRouteTransitions(this.root);
|
|
338
338
|
this.states = this.root.states; // TODO: remove!
|
|
339
339
|
this.events = this.root.events;
|
|
340
340
|
if (!('output' in this.root) && Object.values(this.states).some(state => state.type === 'final' && 'output' in state)) {
|
|
@@ -376,13 +376,13 @@ class StateMachine {
|
|
|
376
376
|
});
|
|
377
377
|
}
|
|
378
378
|
resolveState(config) {
|
|
379
|
-
const resolvedStateValue =
|
|
380
|
-
const nodeSet =
|
|
381
|
-
return
|
|
379
|
+
const resolvedStateValue = dist_xstateGuards.resolveStateValue(this.root, config.value);
|
|
380
|
+
const nodeSet = dist_xstateGuards.getAllStateNodes(dist_xstateGuards.getStateNodes(this.root, resolvedStateValue));
|
|
381
|
+
return dist_xstateGuards.createMachineSnapshot({
|
|
382
382
|
_nodes: [...nodeSet],
|
|
383
383
|
context: config.context || {},
|
|
384
384
|
children: {},
|
|
385
|
-
status:
|
|
385
|
+
status: dist_xstateGuards.isInFinalState(nodeSet, this.root) ? 'done' : config.status || 'active',
|
|
386
386
|
output: config.output,
|
|
387
387
|
error: config.error,
|
|
388
388
|
historyValue: config.historyValue
|
|
@@ -397,7 +397,7 @@ class StateMachine {
|
|
|
397
397
|
* @param event The received event
|
|
398
398
|
*/
|
|
399
399
|
transition(snapshot, event, actorScope) {
|
|
400
|
-
return
|
|
400
|
+
return dist_xstateGuards.macrostep(snapshot, event, actorScope, []).snapshot;
|
|
401
401
|
}
|
|
402
402
|
|
|
403
403
|
/**
|
|
@@ -408,10 +408,10 @@ class StateMachine {
|
|
|
408
408
|
* @param event The received event
|
|
409
409
|
*/
|
|
410
410
|
microstep(snapshot, event, actorScope) {
|
|
411
|
-
return
|
|
411
|
+
return dist_xstateGuards.macrostep(snapshot, event, actorScope, []).microsteps.map(([s]) => s);
|
|
412
412
|
}
|
|
413
413
|
getTransitionData(snapshot, event) {
|
|
414
|
-
return
|
|
414
|
+
return dist_xstateGuards.transitionNode(this.root, snapshot.value, snapshot, event) || [];
|
|
415
415
|
}
|
|
416
416
|
|
|
417
417
|
/**
|
|
@@ -424,7 +424,7 @@ class StateMachine {
|
|
|
424
424
|
const {
|
|
425
425
|
context
|
|
426
426
|
} = this.config;
|
|
427
|
-
const preInitial =
|
|
427
|
+
const preInitial = dist_xstateGuards.createMachineSnapshot({
|
|
428
428
|
context: typeof context !== 'function' && context ? context : {},
|
|
429
429
|
_nodes: [this.root],
|
|
430
430
|
children: {},
|
|
@@ -440,7 +440,7 @@ class StateMachine {
|
|
|
440
440
|
input: event.input,
|
|
441
441
|
self
|
|
442
442
|
});
|
|
443
|
-
return
|
|
443
|
+
return dist_xstateGuards.resolveActionsAndContext(preInitial, initEvent, actorScope, [assign.assign(assignment)], internalQueue, undefined);
|
|
444
444
|
}
|
|
445
445
|
return preInitial;
|
|
446
446
|
}
|
|
@@ -450,13 +450,13 @@ class StateMachine {
|
|
|
450
450
|
* `ActorRef`.
|
|
451
451
|
*/
|
|
452
452
|
getInitialSnapshot(actorScope, input) {
|
|
453
|
-
const initEvent =
|
|
453
|
+
const initEvent = dist_xstateGuards.createInitEvent(input); // TODO: fix;
|
|
454
454
|
const internalQueue = [];
|
|
455
455
|
const preInitialState = this._getPreInitialState(actorScope, initEvent, internalQueue);
|
|
456
|
-
const [nextState] =
|
|
456
|
+
const [nextState] = dist_xstateGuards.initialMicrostep(this.root, preInitialState, actorScope, initEvent, internalQueue);
|
|
457
457
|
const {
|
|
458
458
|
snapshot: macroState
|
|
459
|
-
} =
|
|
459
|
+
} = dist_xstateGuards.macrostep(nextState, initEvent, actorScope, internalQueue);
|
|
460
460
|
return macroState;
|
|
461
461
|
}
|
|
462
462
|
start(snapshot) {
|
|
@@ -467,14 +467,14 @@ class StateMachine {
|
|
|
467
467
|
});
|
|
468
468
|
}
|
|
469
469
|
getStateNodeById(stateId) {
|
|
470
|
-
const fullPath =
|
|
470
|
+
const fullPath = dist_xstateGuards.toStatePath(stateId);
|
|
471
471
|
const relativePath = fullPath.slice(1);
|
|
472
|
-
const resolvedStateId =
|
|
472
|
+
const resolvedStateId = dist_xstateGuards.isStateId(fullPath[0]) ? fullPath[0].slice(STATE_IDENTIFIER.length) : fullPath[0];
|
|
473
473
|
const stateNode = this.idMap.get(resolvedStateId);
|
|
474
474
|
if (!stateNode) {
|
|
475
475
|
throw new Error(`Child state node '#${resolvedStateId}' does not exist on machine '${this.id}'`);
|
|
476
476
|
}
|
|
477
|
-
return
|
|
477
|
+
return dist_xstateGuards.getStateNodeByPath(stateNode, relativePath);
|
|
478
478
|
}
|
|
479
479
|
get definition() {
|
|
480
480
|
return this.root.definition;
|
|
@@ -483,7 +483,7 @@ class StateMachine {
|
|
|
483
483
|
return this.definition;
|
|
484
484
|
}
|
|
485
485
|
getPersistedSnapshot(snapshot, options) {
|
|
486
|
-
return
|
|
486
|
+
return dist_xstateGuards.getPersistedSnapshot(snapshot, options);
|
|
487
487
|
}
|
|
488
488
|
restoreSnapshot(snapshot, _actorScope) {
|
|
489
489
|
const children = {};
|
|
@@ -492,11 +492,11 @@ class StateMachine {
|
|
|
492
492
|
const actorData = snapshotChildren[actorId];
|
|
493
493
|
const childState = actorData.snapshot;
|
|
494
494
|
const src = actorData.src;
|
|
495
|
-
const logic = typeof src === 'string' ?
|
|
495
|
+
const logic = typeof src === 'string' ? dist_xstateGuards.resolveReferencedActor(this, src) : src;
|
|
496
496
|
if (!logic) {
|
|
497
497
|
return;
|
|
498
498
|
}
|
|
499
|
-
const actorRef =
|
|
499
|
+
const actorRef = dist_xstateGuards.createActor(logic, {
|
|
500
500
|
id: actorId,
|
|
501
501
|
parent: _actorScope.self,
|
|
502
502
|
syncSnapshot: actorData.syncSnapshot,
|
|
@@ -537,10 +537,10 @@ class StateMachine {
|
|
|
537
537
|
return revived;
|
|
538
538
|
}
|
|
539
539
|
const revivedHistoryValue = reviveHistoryValue(this.root, snapshot.historyValue);
|
|
540
|
-
const restoredSnapshot =
|
|
540
|
+
const restoredSnapshot = dist_xstateGuards.createMachineSnapshot({
|
|
541
541
|
...snapshot,
|
|
542
542
|
children,
|
|
543
|
-
_nodes: Array.from(
|
|
543
|
+
_nodes: Array.from(dist_xstateGuards.getAllStateNodes(dist_xstateGuards.getStateNodes(this.root, snapshot.value))),
|
|
544
544
|
historyValue: revivedHistoryValue
|
|
545
545
|
}, this);
|
|
546
546
|
const seen = new Set();
|
|
@@ -552,7 +552,7 @@ class StateMachine {
|
|
|
552
552
|
for (const key in contextPart) {
|
|
553
553
|
const value = contextPart[key];
|
|
554
554
|
if (value && typeof value === 'object') {
|
|
555
|
-
if ('xstate$$type' in value && value.xstate$$type ===
|
|
555
|
+
if ('xstate$$type' in value && value.xstate$$type === dist_xstateGuards.$$ACTOR_TYPE) {
|
|
556
556
|
contextPart[key] = children[value.id];
|
|
557
557
|
continue;
|
|
558
558
|
}
|
package/dist/{StateMachine-880c1b22.development.esm.js → StateMachine-e0178d48.development.esm.js}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as STATE_DELIMITER, y as mapValues, t as toArray, z as formatTransitions, B as toTransitionConfigArray, C as formatTransition, N as NULL_EVENT, D as evaluateGuard, E as createInvokeId, F as getDelayedTransitions, G as formatInitialTransition, H as getCandidates, I as formatRouteTransitions, J as resolveStateValue, K as getAllStateNodes, p as getStateNodes, L as createMachineSnapshot, M as isInFinalState, d as macrostep, O as transitionNode, P as resolveActionsAndContext, e as createInitEvent, f as initialMicrostep, Q as toStatePath, R as isStateId, T as getStateNodeByPath, U as getPersistedSnapshot, V as resolveReferencedActor, c as createActor, $ as $$ACTOR_TYPE } from './raise-
|
|
2
|
-
import { a as assign } from './assign-
|
|
1
|
+
import { S as STATE_DELIMITER, y as mapValues, t as toArray, z as formatTransitions, B as toTransitionConfigArray, C as formatTransition, N as NULL_EVENT, D as evaluateGuard, E as createInvokeId, F as getDelayedTransitions, G as formatInitialTransition, H as getCandidates, I as formatRouteTransitions, J as resolveStateValue, K as getAllStateNodes, p as getStateNodes, L as createMachineSnapshot, M as isInFinalState, d as macrostep, O as transitionNode, P as resolveActionsAndContext, e as createInitEvent, f as initialMicrostep, Q as toStatePath, R as isStateId, T as getStateNodeByPath, U as getPersistedSnapshot, V as resolveReferencedActor, c as createActor, $ as $$ACTOR_TYPE } from './raise-74097812.development.esm.js';
|
|
2
|
+
import { a as assign } from './assign-f338cee3.development.esm.js';
|
|
3
3
|
|
|
4
4
|
const cache = new WeakMap();
|
|
5
5
|
function memo(object, key, fn) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var assign = require('./assign-
|
|
3
|
+
var dist_xstateGuards = require('./raise-7c948725.cjs.js');
|
|
4
|
+
var assign = require('./assign-e8f2bd75.cjs.js');
|
|
5
5
|
|
|
6
6
|
const cache = new WeakMap();
|
|
7
7
|
function memo(object, key, fn) {
|
|
@@ -99,12 +99,12 @@ class StateNode {
|
|
|
99
99
|
this.key = options._key;
|
|
100
100
|
this.machine = options._machine;
|
|
101
101
|
this.path = this.parent ? this.parent.path.concat(this.key) : [];
|
|
102
|
-
this.id = this.config.id || [this.machine.id, ...this.path].join(
|
|
102
|
+
this.id = this.config.id || [this.machine.id, ...this.path].join(dist_xstateGuards.STATE_DELIMITER);
|
|
103
103
|
this.type = this.config.type || (this.config.states && Object.keys(this.config.states).length ? 'compound' : this.config.history ? 'history' : 'atomic');
|
|
104
104
|
this.description = this.config.description;
|
|
105
105
|
this.order = this.machine.idMap.size;
|
|
106
106
|
this.machine.idMap.set(this.id, this);
|
|
107
|
-
this.states = this.config.states ?
|
|
107
|
+
this.states = this.config.states ? dist_xstateGuards.mapValues(this.config.states, (stateConfig, key) => {
|
|
108
108
|
const stateNode = new StateNode(stateConfig, {
|
|
109
109
|
_parent: this,
|
|
110
110
|
_key: key,
|
|
@@ -118,18 +118,18 @@ class StateNode {
|
|
|
118
118
|
|
|
119
119
|
// History config
|
|
120
120
|
this.history = this.config.history === true ? 'shallow' : this.config.history || false;
|
|
121
|
-
this.entry =
|
|
122
|
-
this.exit =
|
|
121
|
+
this.entry = dist_xstateGuards.toArray(this.config.entry).slice();
|
|
122
|
+
this.exit = dist_xstateGuards.toArray(this.config.exit).slice();
|
|
123
123
|
this.meta = this.config.meta;
|
|
124
124
|
this.output = this.type === 'final' || !this.parent ? this.config.output : undefined;
|
|
125
|
-
this.tags =
|
|
125
|
+
this.tags = dist_xstateGuards.toArray(config.tags).slice();
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
/** @internal */
|
|
129
129
|
_initialize() {
|
|
130
|
-
this.transitions =
|
|
130
|
+
this.transitions = dist_xstateGuards.formatTransitions(this);
|
|
131
131
|
if (this.config.always) {
|
|
132
|
-
this.always =
|
|
132
|
+
this.always = dist_xstateGuards.toTransitionConfigArray(this.config.always).map(t => dist_xstateGuards.formatTransition(this, dist_xstateGuards.NULL_EVENT, t));
|
|
133
133
|
}
|
|
134
134
|
Object.keys(this.states).forEach(key => {
|
|
135
135
|
this.states[key]._initialize();
|
|
@@ -157,7 +157,7 @@ class StateNode {
|
|
|
157
157
|
})
|
|
158
158
|
} : undefined,
|
|
159
159
|
history: this.history,
|
|
160
|
-
states:
|
|
160
|
+
states: dist_xstateGuards.mapValues(this.states, state => {
|
|
161
161
|
return state.definition;
|
|
162
162
|
}),
|
|
163
163
|
on: this.on,
|
|
@@ -183,13 +183,13 @@ class StateNode {
|
|
|
183
183
|
|
|
184
184
|
/** The logic invoked as actors by this state node. */
|
|
185
185
|
get invoke() {
|
|
186
|
-
return memo(this, 'invoke', () =>
|
|
186
|
+
return memo(this, 'invoke', () => dist_xstateGuards.toArray(this.config.invoke).map((invokeConfig, i) => {
|
|
187
187
|
const {
|
|
188
188
|
src,
|
|
189
189
|
systemId
|
|
190
190
|
} = invokeConfig;
|
|
191
|
-
const resolvedId = invokeConfig.id ??
|
|
192
|
-
const sourceName = typeof src === 'string' ? src : `xstate.invoke.${
|
|
191
|
+
const resolvedId = invokeConfig.id ?? dist_xstateGuards.createInvokeId(this.id, i);
|
|
192
|
+
const sourceName = typeof src === 'string' ? src : `xstate.invoke.${dist_xstateGuards.createInvokeId(this.id, i)}`;
|
|
193
193
|
return {
|
|
194
194
|
...invokeConfig,
|
|
195
195
|
src: sourceName,
|
|
@@ -224,10 +224,10 @@ class StateNode {
|
|
|
224
224
|
});
|
|
225
225
|
}
|
|
226
226
|
get after() {
|
|
227
|
-
return memo(this, 'delayedTransitions', () =>
|
|
227
|
+
return memo(this, 'delayedTransitions', () => dist_xstateGuards.getDelayedTransitions(this));
|
|
228
228
|
}
|
|
229
229
|
get initial() {
|
|
230
|
-
return memo(this, 'initial', () =>
|
|
230
|
+
return memo(this, 'initial', () => dist_xstateGuards.formatInitialTransition(this, this.config.initial));
|
|
231
231
|
}
|
|
232
232
|
|
|
233
233
|
/** @internal */
|
|
@@ -235,7 +235,7 @@ class StateNode {
|
|
|
235
235
|
const eventType = event.type;
|
|
236
236
|
const actions = [];
|
|
237
237
|
let selectedTransition;
|
|
238
|
-
const candidates = memo(this, `candidates-${eventType}`, () =>
|
|
238
|
+
const candidates = memo(this, `candidates-${eventType}`, () => dist_xstateGuards.getCandidates(this, eventType));
|
|
239
239
|
for (const candidate of candidates) {
|
|
240
240
|
const {
|
|
241
241
|
guard
|
|
@@ -243,7 +243,7 @@ class StateNode {
|
|
|
243
243
|
const resolvedContext = snapshot.context;
|
|
244
244
|
let guardPassed = false;
|
|
245
245
|
try {
|
|
246
|
-
guardPassed = !guard ||
|
|
246
|
+
guardPassed = !guard || dist_xstateGuards.evaluateGuard(guard, resolvedContext, event, snapshot);
|
|
247
247
|
} catch (err) {
|
|
248
248
|
const guardType = typeof guard === 'string' ? guard : typeof guard === 'object' ? guard.type : undefined;
|
|
249
249
|
throw new Error(`Unable to evaluate guard ${guardType ? `'${guardType}' ` : ''}in transition for event '${eventType}' in state node '${this.id}':\n${err.message}`);
|
|
@@ -334,7 +334,7 @@ class StateMachine {
|
|
|
334
334
|
_machine: this
|
|
335
335
|
});
|
|
336
336
|
this.root._initialize();
|
|
337
|
-
|
|
337
|
+
dist_xstateGuards.formatRouteTransitions(this.root);
|
|
338
338
|
this.states = this.root.states; // TODO: remove!
|
|
339
339
|
this.events = this.root.events;
|
|
340
340
|
}
|
|
@@ -373,13 +373,13 @@ class StateMachine {
|
|
|
373
373
|
});
|
|
374
374
|
}
|
|
375
375
|
resolveState(config) {
|
|
376
|
-
const resolvedStateValue =
|
|
377
|
-
const nodeSet =
|
|
378
|
-
return
|
|
376
|
+
const resolvedStateValue = dist_xstateGuards.resolveStateValue(this.root, config.value);
|
|
377
|
+
const nodeSet = dist_xstateGuards.getAllStateNodes(dist_xstateGuards.getStateNodes(this.root, resolvedStateValue));
|
|
378
|
+
return dist_xstateGuards.createMachineSnapshot({
|
|
379
379
|
_nodes: [...nodeSet],
|
|
380
380
|
context: config.context || {},
|
|
381
381
|
children: {},
|
|
382
|
-
status:
|
|
382
|
+
status: dist_xstateGuards.isInFinalState(nodeSet, this.root) ? 'done' : config.status || 'active',
|
|
383
383
|
output: config.output,
|
|
384
384
|
error: config.error,
|
|
385
385
|
historyValue: config.historyValue
|
|
@@ -394,7 +394,7 @@ class StateMachine {
|
|
|
394
394
|
* @param event The received event
|
|
395
395
|
*/
|
|
396
396
|
transition(snapshot, event, actorScope) {
|
|
397
|
-
return
|
|
397
|
+
return dist_xstateGuards.macrostep(snapshot, event, actorScope, []).snapshot;
|
|
398
398
|
}
|
|
399
399
|
|
|
400
400
|
/**
|
|
@@ -405,10 +405,10 @@ class StateMachine {
|
|
|
405
405
|
* @param event The received event
|
|
406
406
|
*/
|
|
407
407
|
microstep(snapshot, event, actorScope) {
|
|
408
|
-
return
|
|
408
|
+
return dist_xstateGuards.macrostep(snapshot, event, actorScope, []).microsteps.map(([s]) => s);
|
|
409
409
|
}
|
|
410
410
|
getTransitionData(snapshot, event) {
|
|
411
|
-
return
|
|
411
|
+
return dist_xstateGuards.transitionNode(this.root, snapshot.value, snapshot, event) || [];
|
|
412
412
|
}
|
|
413
413
|
|
|
414
414
|
/**
|
|
@@ -421,7 +421,7 @@ class StateMachine {
|
|
|
421
421
|
const {
|
|
422
422
|
context
|
|
423
423
|
} = this.config;
|
|
424
|
-
const preInitial =
|
|
424
|
+
const preInitial = dist_xstateGuards.createMachineSnapshot({
|
|
425
425
|
context: typeof context !== 'function' && context ? context : {},
|
|
426
426
|
_nodes: [this.root],
|
|
427
427
|
children: {},
|
|
@@ -437,7 +437,7 @@ class StateMachine {
|
|
|
437
437
|
input: event.input,
|
|
438
438
|
self
|
|
439
439
|
});
|
|
440
|
-
return
|
|
440
|
+
return dist_xstateGuards.resolveActionsAndContext(preInitial, initEvent, actorScope, [assign.assign(assignment)], internalQueue, undefined);
|
|
441
441
|
}
|
|
442
442
|
return preInitial;
|
|
443
443
|
}
|
|
@@ -447,13 +447,13 @@ class StateMachine {
|
|
|
447
447
|
* `ActorRef`.
|
|
448
448
|
*/
|
|
449
449
|
getInitialSnapshot(actorScope, input) {
|
|
450
|
-
const initEvent =
|
|
450
|
+
const initEvent = dist_xstateGuards.createInitEvent(input); // TODO: fix;
|
|
451
451
|
const internalQueue = [];
|
|
452
452
|
const preInitialState = this._getPreInitialState(actorScope, initEvent, internalQueue);
|
|
453
|
-
const [nextState] =
|
|
453
|
+
const [nextState] = dist_xstateGuards.initialMicrostep(this.root, preInitialState, actorScope, initEvent, internalQueue);
|
|
454
454
|
const {
|
|
455
455
|
snapshot: macroState
|
|
456
|
-
} =
|
|
456
|
+
} = dist_xstateGuards.macrostep(nextState, initEvent, actorScope, internalQueue);
|
|
457
457
|
return macroState;
|
|
458
458
|
}
|
|
459
459
|
start(snapshot) {
|
|
@@ -464,14 +464,14 @@ class StateMachine {
|
|
|
464
464
|
});
|
|
465
465
|
}
|
|
466
466
|
getStateNodeById(stateId) {
|
|
467
|
-
const fullPath =
|
|
467
|
+
const fullPath = dist_xstateGuards.toStatePath(stateId);
|
|
468
468
|
const relativePath = fullPath.slice(1);
|
|
469
|
-
const resolvedStateId =
|
|
469
|
+
const resolvedStateId = dist_xstateGuards.isStateId(fullPath[0]) ? fullPath[0].slice(STATE_IDENTIFIER.length) : fullPath[0];
|
|
470
470
|
const stateNode = this.idMap.get(resolvedStateId);
|
|
471
471
|
if (!stateNode) {
|
|
472
472
|
throw new Error(`Child state node '#${resolvedStateId}' does not exist on machine '${this.id}'`);
|
|
473
473
|
}
|
|
474
|
-
return
|
|
474
|
+
return dist_xstateGuards.getStateNodeByPath(stateNode, relativePath);
|
|
475
475
|
}
|
|
476
476
|
get definition() {
|
|
477
477
|
return this.root.definition;
|
|
@@ -480,7 +480,7 @@ class StateMachine {
|
|
|
480
480
|
return this.definition;
|
|
481
481
|
}
|
|
482
482
|
getPersistedSnapshot(snapshot, options) {
|
|
483
|
-
return
|
|
483
|
+
return dist_xstateGuards.getPersistedSnapshot(snapshot, options);
|
|
484
484
|
}
|
|
485
485
|
restoreSnapshot(snapshot, _actorScope) {
|
|
486
486
|
const children = {};
|
|
@@ -489,11 +489,11 @@ class StateMachine {
|
|
|
489
489
|
const actorData = snapshotChildren[actorId];
|
|
490
490
|
const childState = actorData.snapshot;
|
|
491
491
|
const src = actorData.src;
|
|
492
|
-
const logic = typeof src === 'string' ?
|
|
492
|
+
const logic = typeof src === 'string' ? dist_xstateGuards.resolveReferencedActor(this, src) : src;
|
|
493
493
|
if (!logic) {
|
|
494
494
|
return;
|
|
495
495
|
}
|
|
496
|
-
const actorRef =
|
|
496
|
+
const actorRef = dist_xstateGuards.createActor(logic, {
|
|
497
497
|
id: actorId,
|
|
498
498
|
parent: _actorScope.self,
|
|
499
499
|
syncSnapshot: actorData.syncSnapshot,
|
|
@@ -531,10 +531,10 @@ class StateMachine {
|
|
|
531
531
|
return revived;
|
|
532
532
|
}
|
|
533
533
|
const revivedHistoryValue = reviveHistoryValue(this.root, snapshot.historyValue);
|
|
534
|
-
const restoredSnapshot =
|
|
534
|
+
const restoredSnapshot = dist_xstateGuards.createMachineSnapshot({
|
|
535
535
|
...snapshot,
|
|
536
536
|
children,
|
|
537
|
-
_nodes: Array.from(
|
|
537
|
+
_nodes: Array.from(dist_xstateGuards.getAllStateNodes(dist_xstateGuards.getStateNodes(this.root, snapshot.value))),
|
|
538
538
|
historyValue: revivedHistoryValue
|
|
539
539
|
}, this);
|
|
540
540
|
const seen = new Set();
|
|
@@ -546,7 +546,7 @@ class StateMachine {
|
|
|
546
546
|
for (const key in contextPart) {
|
|
547
547
|
const value = contextPart[key];
|
|
548
548
|
if (value && typeof value === 'object') {
|
|
549
|
-
if ('xstate$$type' in value && value.xstate$$type ===
|
|
549
|
+
if ('xstate$$type' in value && value.xstate$$type === dist_xstateGuards.$$ACTOR_TYPE) {
|
|
550
550
|
contextPart[key] = children[value.id];
|
|
551
551
|
continue;
|
|
552
552
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Z as ProcessingStatus, V as resolveReferencedActor, c as createActor, _ as cloneMachineSnapshot } from './raise-
|
|
1
|
+
import { Z as ProcessingStatus, V as resolveReferencedActor, c as createActor, _ as cloneMachineSnapshot } from './raise-e974d1c9.esm.js';
|
|
2
2
|
|
|
3
3
|
function createSpawner(actorScope, {
|
|
4
4
|
machine,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var dist_xstateGuards = require('./raise-964cd4e9.development.cjs.js');
|
|
4
4
|
|
|
5
5
|
function createSpawner(actorScope, {
|
|
6
6
|
machine,
|
|
@@ -8,11 +8,11 @@ function createSpawner(actorScope, {
|
|
|
8
8
|
}, event, spawnedChildren) {
|
|
9
9
|
const spawn = (src, options) => {
|
|
10
10
|
if (typeof src === 'string') {
|
|
11
|
-
const logic =
|
|
11
|
+
const logic = dist_xstateGuards.resolveReferencedActor(machine, src);
|
|
12
12
|
if (!logic) {
|
|
13
13
|
throw new Error(`Actor logic '${src}' not implemented in machine '${machine.id}'`);
|
|
14
14
|
}
|
|
15
|
-
const actorRef =
|
|
15
|
+
const actorRef = dist_xstateGuards.createActor(logic, {
|
|
16
16
|
id: options?.id,
|
|
17
17
|
parent: actorScope.self,
|
|
18
18
|
syncSnapshot: options?.syncSnapshot,
|
|
@@ -27,7 +27,7 @@ function createSpawner(actorScope, {
|
|
|
27
27
|
spawnedChildren[actorRef.id] = actorRef;
|
|
28
28
|
return actorRef;
|
|
29
29
|
} else {
|
|
30
|
-
const actorRef =
|
|
30
|
+
const actorRef = dist_xstateGuards.createActor(src, {
|
|
31
31
|
id: options?.id,
|
|
32
32
|
parent: actorScope.self,
|
|
33
33
|
syncSnapshot: options?.syncSnapshot,
|
|
@@ -42,7 +42,7 @@ function createSpawner(actorScope, {
|
|
|
42
42
|
const actorRef = spawn(src, options); // TODO: fix types
|
|
43
43
|
spawnedChildren[actorRef.id] = actorRef;
|
|
44
44
|
actorScope.defer(() => {
|
|
45
|
-
if (actorRef._processingStatus ===
|
|
45
|
+
if (actorRef._processingStatus === dist_xstateGuards.ProcessingStatus.Stopped) {
|
|
46
46
|
return;
|
|
47
47
|
}
|
|
48
48
|
actorRef.start();
|
|
@@ -75,7 +75,7 @@ function resolveAssign(actorScope, snapshot, actionArgs, actionParams, {
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
const updatedContext = Object.assign({}, snapshot.context, partialUpdate);
|
|
78
|
-
return [
|
|
78
|
+
return [dist_xstateGuards.cloneMachineSnapshot(snapshot, {
|
|
79
79
|
context: updatedContext,
|
|
80
80
|
children: Object.keys(spawnedChildren).length ? {
|
|
81
81
|
...snapshot.children,
|
|
@@ -118,7 +118,7 @@ function resolveAssign(actorScope, snapshot, actionArgs, actionParams, {
|
|
|
118
118
|
* update.
|
|
119
119
|
*/
|
|
120
120
|
function assign(assignment) {
|
|
121
|
-
if (
|
|
121
|
+
if (dist_xstateGuards.executingCustomAction) {
|
|
122
122
|
console.warn('Custom actions should not call `assign()` directly, as it is not imperative. See https://stately.ai/docs/actions#built-in-actions for more details.');
|
|
123
123
|
}
|
|
124
124
|
function assign(_args, _params) {
|