xstate 5.0.0-beta.43 → 5.0.0-beta.45
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/dist/xstate-actions.cjs.js +2 -3
- package/actions/dist/xstate-actions.development.cjs.js +2 -3
- package/actions/dist/xstate-actions.development.esm.js +2 -3
- package/actions/dist/xstate-actions.esm.js +2 -3
- package/actions/dist/xstate-actions.umd.min.js +1 -1
- package/actions/dist/xstate-actions.umd.min.js.map +1 -1
- package/actors/dist/xstate-actors.cjs.js +98 -10
- package/actors/dist/xstate-actors.development.cjs.js +98 -10
- package/actors/dist/xstate-actors.development.esm.js +93 -5
- package/actors/dist/xstate-actors.esm.js +93 -5
- package/actors/dist/xstate-actors.umd.min.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/declarations/src/State.d.ts +14 -18
- package/dist/declarations/src/StateMachine.d.ts +1 -1
- package/dist/declarations/src/actions/choose.d.ts +3 -3
- package/dist/declarations/src/actions/pure.d.ts +4 -4
- package/dist/declarations/src/actions/spawn.d.ts +11 -16
- package/dist/declarations/src/actors/observable.d.ts +39 -0
- package/dist/declarations/src/actors/transition.d.ts +53 -4
- package/dist/declarations/src/{Machine.d.ts → createMachine.d.ts} +1 -1
- package/dist/declarations/src/guards.d.ts +27 -5
- package/dist/declarations/src/index.d.ts +3 -2
- package/dist/declarations/src/interpreter.d.ts +1 -0
- package/dist/declarations/src/setup.d.ts +32 -0
- package/dist/declarations/src/spawn.d.ts +9 -13
- package/dist/declarations/src/stateUtils.d.ts +11 -11
- package/dist/declarations/src/types.d.ts +31 -29
- package/dist/declarations/src/utils.d.ts +1 -3
- package/dist/{raise-8dc8e1aa.esm.js → raise-2b5a4e4c.esm.js} +934 -103
- package/dist/{raise-f4ad5a87.development.esm.js → raise-90139fbc.development.esm.js} +945 -103
- package/dist/{raise-23dea0d7.development.cjs.js → raise-b3fb3c65.development.cjs.js} +999 -137
- package/dist/{raise-e0fe5c2d.cjs.js → raise-fabffc3d.cjs.js} +986 -135
- package/dist/{send-5d129d95.development.esm.js → send-24cc8018.development.esm.js} +4 -30
- package/dist/{send-84e2e742.esm.js → send-8e7e41e7.esm.js} +4 -30
- package/dist/{send-87bbaaab.cjs.js → send-c124176f.cjs.js} +13 -39
- package/dist/{send-0174c155.development.cjs.js → send-d0bc7eed.development.cjs.js} +13 -39
- package/dist/xstate.cjs.js +67 -35
- package/dist/xstate.cjs.mjs +2 -0
- package/dist/xstate.development.cjs.js +67 -35
- package/dist/xstate.development.cjs.mjs +2 -0
- package/dist/xstate.development.esm.js +42 -13
- package/dist/xstate.esm.js +42 -13
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.js +1 -2
- package/guards/dist/xstate-guards.development.cjs.js +1 -2
- package/guards/dist/xstate-guards.development.esm.js +1 -2
- package/guards/dist/xstate-guards.esm.js +1 -2
- package/guards/dist/xstate-guards.umd.min.js +1 -1
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/dist/interpreter-36d5556e.cjs.js +0 -887
- package/dist/interpreter-4e8e2a0d.development.cjs.js +0 -898
- package/dist/interpreter-63c80754.esm.js +0 -857
- package/dist/interpreter-80eb3bec.development.esm.js +0 -868
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var actors_dist_xstateActors = require('../actors/dist/xstate-actors.development.cjs.js');
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var send = require('./send-0174c155.development.cjs.js');
|
|
6
|
+
var guards_dist_xstateGuards = require('./raise-b3fb3c65.development.cjs.js');
|
|
7
|
+
var send = require('./send-d0bc7eed.development.cjs.js');
|
|
9
8
|
require('../dev/dist/xstate-dev.development.cjs.js');
|
|
10
9
|
|
|
11
10
|
class SimulatedClock {
|
|
@@ -57,6 +56,20 @@ class SimulatedClock {
|
|
|
57
56
|
}
|
|
58
57
|
}
|
|
59
58
|
|
|
59
|
+
const cache = new WeakMap();
|
|
60
|
+
function memo(object, key, fn) {
|
|
61
|
+
let memoizedData = cache.get(object);
|
|
62
|
+
if (!memoizedData) {
|
|
63
|
+
memoizedData = {
|
|
64
|
+
[key]: fn()
|
|
65
|
+
};
|
|
66
|
+
cache.set(object, memoizedData);
|
|
67
|
+
} else if (!(key in memoizedData)) {
|
|
68
|
+
memoizedData[key] = fn();
|
|
69
|
+
}
|
|
70
|
+
return memoizedData[key];
|
|
71
|
+
}
|
|
72
|
+
|
|
60
73
|
const EMPTY_OBJECT = {};
|
|
61
74
|
const toSerializableAction = action => {
|
|
62
75
|
if (typeof action === 'string') {
|
|
@@ -165,12 +178,12 @@ class StateNode {
|
|
|
165
178
|
this.key = options._key;
|
|
166
179
|
this.machine = options._machine;
|
|
167
180
|
this.path = this.parent ? this.parent.path.concat(this.key) : [];
|
|
168
|
-
this.id = this.config.id || [this.machine.id, ...this.path].join(
|
|
181
|
+
this.id = this.config.id || [this.machine.id, ...this.path].join(guards_dist_xstateGuards.STATE_DELIMITER);
|
|
169
182
|
this.type = this.config.type || (this.config.states && Object.keys(this.config.states).length ? 'compound' : this.config.history ? 'history' : 'atomic');
|
|
170
183
|
this.description = this.config.description;
|
|
171
184
|
this.order = this.machine.idMap.size;
|
|
172
185
|
this.machine.idMap.set(this.id, this);
|
|
173
|
-
this.states = this.config.states ?
|
|
186
|
+
this.states = this.config.states ? guards_dist_xstateGuards.mapValues(this.config.states, (stateConfig, key) => {
|
|
174
187
|
const stateNode = new StateNode(stateConfig, {
|
|
175
188
|
_parent: this,
|
|
176
189
|
_key: key,
|
|
@@ -184,16 +197,16 @@ class StateNode {
|
|
|
184
197
|
|
|
185
198
|
// History config
|
|
186
199
|
this.history = this.config.history === true ? 'shallow' : this.config.history || false;
|
|
187
|
-
this.entry =
|
|
188
|
-
this.exit =
|
|
200
|
+
this.entry = guards_dist_xstateGuards.toArray(this.config.entry).slice();
|
|
201
|
+
this.exit = guards_dist_xstateGuards.toArray(this.config.exit).slice();
|
|
189
202
|
this.meta = this.config.meta;
|
|
190
203
|
this.output = this.type === 'final' || !this.parent ? this.config.output : undefined;
|
|
191
|
-
this.tags =
|
|
204
|
+
this.tags = guards_dist_xstateGuards.toArray(config.tags).slice();
|
|
192
205
|
}
|
|
193
206
|
_initialize() {
|
|
194
207
|
this.transitions = guards_dist_xstateGuards.formatTransitions(this);
|
|
195
208
|
if (this.config.always) {
|
|
196
|
-
this.always =
|
|
209
|
+
this.always = guards_dist_xstateGuards.toTransitionConfigArray(this.config.always).map(t => guards_dist_xstateGuards.formatTransition(this, guards_dist_xstateGuards.NULL_EVENT, t));
|
|
197
210
|
}
|
|
198
211
|
Object.keys(this.states).forEach(key => {
|
|
199
212
|
this.states[key]._initialize();
|
|
@@ -223,7 +236,7 @@ class StateNode {
|
|
|
223
236
|
})
|
|
224
237
|
} : undefined,
|
|
225
238
|
history: this.history,
|
|
226
|
-
states:
|
|
239
|
+
states: guards_dist_xstateGuards.mapValues(this.states, state => {
|
|
227
240
|
return state.definition;
|
|
228
241
|
}),
|
|
229
242
|
on: this.on,
|
|
@@ -249,13 +262,13 @@ class StateNode {
|
|
|
249
262
|
* The logic invoked as actors by this state node.
|
|
250
263
|
*/
|
|
251
264
|
get invoke() {
|
|
252
|
-
return
|
|
265
|
+
return memo(this, 'invoke', () => guards_dist_xstateGuards.toArray(this.config.invoke).map((invokeConfig, i) => {
|
|
253
266
|
const {
|
|
254
267
|
src,
|
|
255
268
|
systemId
|
|
256
269
|
} = invokeConfig;
|
|
257
|
-
const resolvedId = invokeConfig.id ||
|
|
258
|
-
const resolvedSrc = typeof src === 'string' ? src : `xstate#${
|
|
270
|
+
const resolvedId = invokeConfig.id || guards_dist_xstateGuards.createInvokeId(this.id, i);
|
|
271
|
+
const resolvedSrc = typeof src === 'string' ? src : `xstate#${guards_dist_xstateGuards.createInvokeId(this.id, i)}`;
|
|
259
272
|
return {
|
|
260
273
|
...invokeConfig,
|
|
261
274
|
src: resolvedSrc,
|
|
@@ -282,7 +295,7 @@ class StateNode {
|
|
|
282
295
|
* The mapping of events to transitions.
|
|
283
296
|
*/
|
|
284
297
|
get on() {
|
|
285
|
-
return
|
|
298
|
+
return memo(this, 'on', () => {
|
|
286
299
|
const transitions = this.transitions;
|
|
287
300
|
return [...transitions].flatMap(([descriptor, t]) => t.map(t => [descriptor, t])).reduce((map, [descriptor, transition]) => {
|
|
288
301
|
map[descriptor] = map[descriptor] || [];
|
|
@@ -292,16 +305,16 @@ class StateNode {
|
|
|
292
305
|
});
|
|
293
306
|
}
|
|
294
307
|
get after() {
|
|
295
|
-
return
|
|
308
|
+
return memo(this, 'delayedTransitions', () => guards_dist_xstateGuards.getDelayedTransitions(this));
|
|
296
309
|
}
|
|
297
310
|
get initial() {
|
|
298
|
-
return
|
|
311
|
+
return memo(this, 'initial', () => guards_dist_xstateGuards.formatInitialTransition(this, this.config.initial));
|
|
299
312
|
}
|
|
300
313
|
next(state, event) {
|
|
301
314
|
const eventType = event.type;
|
|
302
315
|
const actions = [];
|
|
303
316
|
let selectedTransition;
|
|
304
|
-
const candidates =
|
|
317
|
+
const candidates = memo(this, `candidates-${eventType}`, () => guards_dist_xstateGuards.getCandidates(this, eventType));
|
|
305
318
|
for (const candidate of candidates) {
|
|
306
319
|
const {
|
|
307
320
|
guard
|
|
@@ -327,7 +340,7 @@ class StateNode {
|
|
|
327
340
|
* All the event types accepted by this state node and its descendants.
|
|
328
341
|
*/
|
|
329
342
|
get events() {
|
|
330
|
-
return
|
|
343
|
+
return memo(this, 'events', () => {
|
|
331
344
|
const {
|
|
332
345
|
states
|
|
333
346
|
} = this;
|
|
@@ -452,12 +465,12 @@ class StateMachine {
|
|
|
452
465
|
}
|
|
453
466
|
resolveState(config) {
|
|
454
467
|
const resolvedStateValue = guards_dist_xstateGuards.resolveStateValue(this.root, config.value);
|
|
455
|
-
const
|
|
468
|
+
const nodeSet = guards_dist_xstateGuards.getAllStateNodes(guards_dist_xstateGuards.getStateNodes(this.root, resolvedStateValue));
|
|
456
469
|
return guards_dist_xstateGuards.createMachineSnapshot({
|
|
457
|
-
|
|
470
|
+
_nodes: [...nodeSet],
|
|
458
471
|
context: config.context || {},
|
|
459
472
|
children: {},
|
|
460
|
-
status: guards_dist_xstateGuards.isInFinalState(
|
|
473
|
+
status: guards_dist_xstateGuards.isInFinalState(nodeSet, this.root) ? 'done' : config.status || 'active',
|
|
461
474
|
output: config.output,
|
|
462
475
|
error: config.error,
|
|
463
476
|
historyValue: config.historyValue
|
|
@@ -473,7 +486,7 @@ class StateMachine {
|
|
|
473
486
|
*/
|
|
474
487
|
transition(state, event, actorScope) {
|
|
475
488
|
// TODO: handle error events in a better way
|
|
476
|
-
if (
|
|
489
|
+
if (guards_dist_xstateGuards.isErrorActorEvent(event) && !state.getNextEvents().some(nextEvent => nextEvent === event.type)) {
|
|
477
490
|
return guards_dist_xstateGuards.cloneMachineSnapshot(state, {
|
|
478
491
|
status: 'error',
|
|
479
492
|
error: event.data
|
|
@@ -509,7 +522,7 @@ class StateMachine {
|
|
|
509
522
|
} = this.config;
|
|
510
523
|
const preInitial = guards_dist_xstateGuards.createMachineSnapshot({
|
|
511
524
|
context: typeof context !== 'function' && context ? context : {},
|
|
512
|
-
|
|
525
|
+
_nodes: [this.root],
|
|
513
526
|
children: {},
|
|
514
527
|
status: 'active'
|
|
515
528
|
}, this);
|
|
@@ -530,7 +543,7 @@ class StateMachine {
|
|
|
530
543
|
* Returns the initial `State` instance, with reference to `self` as an `ActorRef`.
|
|
531
544
|
*/
|
|
532
545
|
getInitialState(actorScope, input) {
|
|
533
|
-
const initEvent =
|
|
546
|
+
const initEvent = guards_dist_xstateGuards.createInitEvent(input); // TODO: fix;
|
|
534
547
|
const internalQueue = [];
|
|
535
548
|
const preInitialState = this.getPreInitialState(actorScope, initEvent, internalQueue);
|
|
536
549
|
const nextState = guards_dist_xstateGuards.microstep([{
|
|
@@ -554,7 +567,7 @@ class StateMachine {
|
|
|
554
567
|
});
|
|
555
568
|
}
|
|
556
569
|
getStateNodeById(stateId) {
|
|
557
|
-
const fullPath = stateId.split(
|
|
570
|
+
const fullPath = stateId.split(guards_dist_xstateGuards.STATE_DELIMITER);
|
|
558
571
|
const relativePath = fullPath.slice(1);
|
|
559
572
|
const resolvedStateId = guards_dist_xstateGuards.isStateId(fullPath[0]) ? fullPath[0].slice(STATE_IDENTIFIER.length) : fullPath[0];
|
|
560
573
|
const stateNode = this.idMap.get(resolvedStateId);
|
|
@@ -579,14 +592,15 @@ class StateMachine {
|
|
|
579
592
|
const actorData = snapshotChildren[actorId];
|
|
580
593
|
const childState = actorData.state;
|
|
581
594
|
const src = actorData.src;
|
|
582
|
-
const logic = typeof src === 'string' ?
|
|
595
|
+
const logic = typeof src === 'string' ? guards_dist_xstateGuards.resolveReferencedActor(this, src) : src;
|
|
583
596
|
if (!logic) {
|
|
584
597
|
return;
|
|
585
598
|
}
|
|
586
599
|
const actorState = logic.restoreState?.(childState, _actorScope);
|
|
587
|
-
const actorRef =
|
|
600
|
+
const actorRef = guards_dist_xstateGuards.createActor(logic, {
|
|
588
601
|
id: actorId,
|
|
589
602
|
parent: _actorScope?.self,
|
|
603
|
+
syncSnapshot: actorData.syncSnapshot,
|
|
590
604
|
state: actorState,
|
|
591
605
|
src,
|
|
592
606
|
systemId: actorData.systemId
|
|
@@ -596,7 +610,7 @@ class StateMachine {
|
|
|
596
610
|
const restoredSnapshot = guards_dist_xstateGuards.createMachineSnapshot({
|
|
597
611
|
...snapshot,
|
|
598
612
|
children,
|
|
599
|
-
|
|
613
|
+
_nodes: Array.from(guards_dist_xstateGuards.getAllStateNodes(guards_dist_xstateGuards.getStateNodes(this.root, snapshot.value)))
|
|
600
614
|
}, this);
|
|
601
615
|
let seen = new Set();
|
|
602
616
|
function reviveContext(contextPart, children) {
|
|
@@ -607,7 +621,7 @@ class StateMachine {
|
|
|
607
621
|
for (let key in contextPart) {
|
|
608
622
|
const value = contextPart[key];
|
|
609
623
|
if (value && typeof value === 'object') {
|
|
610
|
-
if ('xstate$$type' in value && value.xstate$$type ===
|
|
624
|
+
if ('xstate$$type' in value && value.xstate$$type === guards_dist_xstateGuards.$$ACTOR_TYPE) {
|
|
611
625
|
contextPart[key] = children[value.id];
|
|
612
626
|
continue;
|
|
613
627
|
}
|
|
@@ -700,27 +714,44 @@ function createMachine(config, implementations) {
|
|
|
700
714
|
return new StateMachine(config, implementations);
|
|
701
715
|
}
|
|
702
716
|
|
|
717
|
+
function setup({
|
|
718
|
+
actors,
|
|
719
|
+
actions,
|
|
720
|
+
guards,
|
|
721
|
+
delays
|
|
722
|
+
}) {
|
|
723
|
+
return {
|
|
724
|
+
createMachine: config => createMachine(config, {
|
|
725
|
+
actors,
|
|
726
|
+
actions,
|
|
727
|
+
guards,
|
|
728
|
+
delays
|
|
729
|
+
})
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
|
|
703
733
|
exports.createEmptyActor = actors_dist_xstateActors.createEmptyActor;
|
|
704
734
|
exports.fromCallback = actors_dist_xstateActors.fromCallback;
|
|
705
735
|
exports.fromEventObservable = actors_dist_xstateActors.fromEventObservable;
|
|
706
736
|
exports.fromObservable = actors_dist_xstateActors.fromObservable;
|
|
707
737
|
exports.fromPromise = actors_dist_xstateActors.fromPromise;
|
|
708
738
|
exports.fromTransition = actors_dist_xstateActors.fromTransition;
|
|
709
|
-
exports.Actor =
|
|
710
|
-
exports.createActor = interpreter.createActor;
|
|
711
|
-
exports.interpret = interpreter.interpret;
|
|
712
|
-
exports.matchesState = interpreter.matchesState;
|
|
713
|
-
exports.pathToStateValue = interpreter.pathToStateValue;
|
|
714
|
-
exports.toObserver = interpreter.toObserver;
|
|
739
|
+
exports.Actor = guards_dist_xstateGuards.Actor;
|
|
715
740
|
exports.and = guards_dist_xstateGuards.and;
|
|
716
741
|
exports.cancel = guards_dist_xstateGuards.cancel;
|
|
742
|
+
exports.createActor = guards_dist_xstateGuards.createActor;
|
|
717
743
|
exports.getStateNodes = guards_dist_xstateGuards.getStateNodes;
|
|
744
|
+
exports.interpret = guards_dist_xstateGuards.interpret;
|
|
745
|
+
exports.isMachineSnapshot = guards_dist_xstateGuards.isMachineSnapshot;
|
|
746
|
+
exports.matchesState = guards_dist_xstateGuards.matchesState;
|
|
718
747
|
exports.not = guards_dist_xstateGuards.not;
|
|
719
748
|
exports.or = guards_dist_xstateGuards.or;
|
|
749
|
+
exports.pathToStateValue = guards_dist_xstateGuards.pathToStateValue;
|
|
720
750
|
exports.raise = guards_dist_xstateGuards.raise;
|
|
721
751
|
exports.spawn = guards_dist_xstateGuards.spawn;
|
|
722
752
|
exports.stateIn = guards_dist_xstateGuards.stateIn;
|
|
723
753
|
exports.stop = guards_dist_xstateGuards.stop;
|
|
754
|
+
exports.toObserver = guards_dist_xstateGuards.toObserver;
|
|
724
755
|
exports.SpecialTargets = send.SpecialTargets;
|
|
725
756
|
exports.assign = send.assign;
|
|
726
757
|
exports.choose = send.choose;
|
|
@@ -734,4 +765,5 @@ exports.SimulatedClock = SimulatedClock;
|
|
|
734
765
|
exports.StateMachine = StateMachine;
|
|
735
766
|
exports.StateNode = StateNode;
|
|
736
767
|
exports.createMachine = createMachine;
|
|
768
|
+
exports.setup = setup;
|
|
737
769
|
exports.waitFor = waitFor;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
export { createEmptyActor, fromCallback, fromEventObservable, fromObservable, fromPromise, fromTransition } from '../actors/dist/xstate-actors.development.esm.js';
|
|
2
|
-
import { S as STATE_DELIMITER, m as mapValues, t as toArray, a as toTransitionConfigArray, N as NULL_EVENT, c as createInvokeId, i as isErrorActorEvent,
|
|
3
|
-
export {
|
|
4
|
-
import {
|
|
5
|
-
export {
|
|
6
|
-
import { a as assign } from './send-5d129d95.development.esm.js';
|
|
7
|
-
export { S as SpecialTargets, a as assign, c as choose, e as escalate, f as forwardTo, l as log, p as pure, s as sendParent, b as sendTo } from './send-5d129d95.development.esm.js';
|
|
2
|
+
import { S as STATE_DELIMITER, m as mapValues, t as toArray, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, e as evaluateGuard, c as createInvokeId, g as getDelayedTransitions, d as formatInitialTransition, h as getCandidates, r as resolveStateValue, i as getAllStateNodes, j as getStateNodes, k as createMachineSnapshot, l as isInFinalState, n as isErrorActorEvent, o as cloneMachineSnapshot, p as macrostep, q as transitionNode, s as resolveActionsAndContext, u as createInitEvent, v as microstep, w as getInitialStateNodes, x as isStateId, y as getStateNodeByPath, z as getPersistedState, A as resolveReferencedActor, B as createActor, $ as $$ACTOR_TYPE } from './raise-90139fbc.development.esm.js';
|
|
3
|
+
export { C as Actor, I as and, M as cancel, B as createActor, j as getStateNodes, D as interpret, E as isMachineSnapshot, F as matchesState, J as not, K as or, G as pathToStateValue, O as raise, Q as spawn, L as stateIn, P as stop, H as toObserver } from './raise-90139fbc.development.esm.js';
|
|
4
|
+
import { a as assign } from './send-24cc8018.development.esm.js';
|
|
5
|
+
export { S as SpecialTargets, a as assign, c as choose, e as escalate, f as forwardTo, l as log, p as pure, s as sendParent, b as sendTo } from './send-24cc8018.development.esm.js';
|
|
8
6
|
import '../dev/dist/xstate-dev.development.esm.js';
|
|
9
7
|
|
|
10
8
|
class SimulatedClock {
|
|
@@ -56,6 +54,20 @@ class SimulatedClock {
|
|
|
56
54
|
}
|
|
57
55
|
}
|
|
58
56
|
|
|
57
|
+
const cache = new WeakMap();
|
|
58
|
+
function memo(object, key, fn) {
|
|
59
|
+
let memoizedData = cache.get(object);
|
|
60
|
+
if (!memoizedData) {
|
|
61
|
+
memoizedData = {
|
|
62
|
+
[key]: fn()
|
|
63
|
+
};
|
|
64
|
+
cache.set(object, memoizedData);
|
|
65
|
+
} else if (!(key in memoizedData)) {
|
|
66
|
+
memoizedData[key] = fn();
|
|
67
|
+
}
|
|
68
|
+
return memoizedData[key];
|
|
69
|
+
}
|
|
70
|
+
|
|
59
71
|
const EMPTY_OBJECT = {};
|
|
60
72
|
const toSerializableAction = action => {
|
|
61
73
|
if (typeof action === 'string') {
|
|
@@ -451,12 +463,12 @@ class StateMachine {
|
|
|
451
463
|
}
|
|
452
464
|
resolveState(config) {
|
|
453
465
|
const resolvedStateValue = resolveStateValue(this.root, config.value);
|
|
454
|
-
const
|
|
466
|
+
const nodeSet = getAllStateNodes(getStateNodes(this.root, resolvedStateValue));
|
|
455
467
|
return createMachineSnapshot({
|
|
456
|
-
|
|
468
|
+
_nodes: [...nodeSet],
|
|
457
469
|
context: config.context || {},
|
|
458
470
|
children: {},
|
|
459
|
-
status: isInFinalState(
|
|
471
|
+
status: isInFinalState(nodeSet, this.root) ? 'done' : config.status || 'active',
|
|
460
472
|
output: config.output,
|
|
461
473
|
error: config.error,
|
|
462
474
|
historyValue: config.historyValue
|
|
@@ -472,7 +484,7 @@ class StateMachine {
|
|
|
472
484
|
*/
|
|
473
485
|
transition(state, event, actorScope) {
|
|
474
486
|
// TODO: handle error events in a better way
|
|
475
|
-
if (isErrorActorEvent(event) && !state.
|
|
487
|
+
if (isErrorActorEvent(event) && !state.getNextEvents().some(nextEvent => nextEvent === event.type)) {
|
|
476
488
|
return cloneMachineSnapshot(state, {
|
|
477
489
|
status: 'error',
|
|
478
490
|
error: event.data
|
|
@@ -508,7 +520,7 @@ class StateMachine {
|
|
|
508
520
|
} = this.config;
|
|
509
521
|
const preInitial = createMachineSnapshot({
|
|
510
522
|
context: typeof context !== 'function' && context ? context : {},
|
|
511
|
-
|
|
523
|
+
_nodes: [this.root],
|
|
512
524
|
children: {},
|
|
513
525
|
status: 'active'
|
|
514
526
|
}, this);
|
|
@@ -586,6 +598,7 @@ class StateMachine {
|
|
|
586
598
|
const actorRef = createActor(logic, {
|
|
587
599
|
id: actorId,
|
|
588
600
|
parent: _actorScope?.self,
|
|
601
|
+
syncSnapshot: actorData.syncSnapshot,
|
|
589
602
|
state: actorState,
|
|
590
603
|
src,
|
|
591
604
|
systemId: actorData.systemId
|
|
@@ -595,7 +608,7 @@ class StateMachine {
|
|
|
595
608
|
const restoredSnapshot = createMachineSnapshot({
|
|
596
609
|
...snapshot,
|
|
597
610
|
children,
|
|
598
|
-
|
|
611
|
+
_nodes: Array.from(getAllStateNodes(getStateNodes(this.root, snapshot.value)))
|
|
599
612
|
}, this);
|
|
600
613
|
let seen = new Set();
|
|
601
614
|
function reviveContext(contextPart, children) {
|
|
@@ -699,4 +712,20 @@ function createMachine(config, implementations) {
|
|
|
699
712
|
return new StateMachine(config, implementations);
|
|
700
713
|
}
|
|
701
714
|
|
|
702
|
-
|
|
715
|
+
function setup({
|
|
716
|
+
actors,
|
|
717
|
+
actions,
|
|
718
|
+
guards,
|
|
719
|
+
delays
|
|
720
|
+
}) {
|
|
721
|
+
return {
|
|
722
|
+
createMachine: config => createMachine(config, {
|
|
723
|
+
actors,
|
|
724
|
+
actions,
|
|
725
|
+
guards,
|
|
726
|
+
delays
|
|
727
|
+
})
|
|
728
|
+
};
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
export { SimulatedClock, StateMachine, StateNode, createMachine, setup, waitFor };
|
package/dist/xstate.esm.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
export { createEmptyActor, fromCallback, fromEventObservable, fromObservable, fromPromise, fromTransition } from '../actors/dist/xstate-actors.esm.js';
|
|
2
|
-
import { S as STATE_DELIMITER, m as mapValues, t as toArray, a as toTransitionConfigArray, N as NULL_EVENT, c as createInvokeId, i as isErrorActorEvent,
|
|
3
|
-
export {
|
|
4
|
-
import {
|
|
5
|
-
export {
|
|
6
|
-
import { a as assign } from './send-84e2e742.esm.js';
|
|
7
|
-
export { S as SpecialTargets, a as assign, c as choose, e as escalate, f as forwardTo, l as log, p as pure, s as sendParent, b as sendTo } from './send-84e2e742.esm.js';
|
|
2
|
+
import { S as STATE_DELIMITER, m as mapValues, t as toArray, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, e as evaluateGuard, c as createInvokeId, g as getDelayedTransitions, d as formatInitialTransition, h as getCandidates, r as resolveStateValue, i as getAllStateNodes, j as getStateNodes, k as createMachineSnapshot, l as isInFinalState, n as isErrorActorEvent, o as cloneMachineSnapshot, p as macrostep, q as transitionNode, s as resolveActionsAndContext, u as createInitEvent, v as microstep, w as getInitialStateNodes, x as isStateId, y as getStateNodeByPath, z as getPersistedState, A as resolveReferencedActor, B as createActor, $ as $$ACTOR_TYPE } from './raise-2b5a4e4c.esm.js';
|
|
3
|
+
export { C as Actor, I as and, M as cancel, B as createActor, j as getStateNodes, D as interpret, E as isMachineSnapshot, F as matchesState, J as not, K as or, G as pathToStateValue, O as raise, Q as spawn, L as stateIn, P as stop, H as toObserver } from './raise-2b5a4e4c.esm.js';
|
|
4
|
+
import { a as assign } from './send-8e7e41e7.esm.js';
|
|
5
|
+
export { S as SpecialTargets, a as assign, c as choose, e as escalate, f as forwardTo, l as log, p as pure, s as sendParent, b as sendTo } from './send-8e7e41e7.esm.js';
|
|
8
6
|
import '../dev/dist/xstate-dev.esm.js';
|
|
9
7
|
|
|
10
8
|
class SimulatedClock {
|
|
@@ -56,6 +54,20 @@ class SimulatedClock {
|
|
|
56
54
|
}
|
|
57
55
|
}
|
|
58
56
|
|
|
57
|
+
const cache = new WeakMap();
|
|
58
|
+
function memo(object, key, fn) {
|
|
59
|
+
let memoizedData = cache.get(object);
|
|
60
|
+
if (!memoizedData) {
|
|
61
|
+
memoizedData = {
|
|
62
|
+
[key]: fn()
|
|
63
|
+
};
|
|
64
|
+
cache.set(object, memoizedData);
|
|
65
|
+
} else if (!(key in memoizedData)) {
|
|
66
|
+
memoizedData[key] = fn();
|
|
67
|
+
}
|
|
68
|
+
return memoizedData[key];
|
|
69
|
+
}
|
|
70
|
+
|
|
59
71
|
const EMPTY_OBJECT = {};
|
|
60
72
|
const toSerializableAction = action => {
|
|
61
73
|
if (typeof action === 'string') {
|
|
@@ -448,12 +460,12 @@ class StateMachine {
|
|
|
448
460
|
}
|
|
449
461
|
resolveState(config) {
|
|
450
462
|
const resolvedStateValue = resolveStateValue(this.root, config.value);
|
|
451
|
-
const
|
|
463
|
+
const nodeSet = getAllStateNodes(getStateNodes(this.root, resolvedStateValue));
|
|
452
464
|
return createMachineSnapshot({
|
|
453
|
-
|
|
465
|
+
_nodes: [...nodeSet],
|
|
454
466
|
context: config.context || {},
|
|
455
467
|
children: {},
|
|
456
|
-
status: isInFinalState(
|
|
468
|
+
status: isInFinalState(nodeSet, this.root) ? 'done' : config.status || 'active',
|
|
457
469
|
output: config.output,
|
|
458
470
|
error: config.error,
|
|
459
471
|
historyValue: config.historyValue
|
|
@@ -469,7 +481,7 @@ class StateMachine {
|
|
|
469
481
|
*/
|
|
470
482
|
transition(state, event, actorScope) {
|
|
471
483
|
// TODO: handle error events in a better way
|
|
472
|
-
if (isErrorActorEvent(event) && !state.
|
|
484
|
+
if (isErrorActorEvent(event) && !state.getNextEvents().some(nextEvent => nextEvent === event.type)) {
|
|
473
485
|
return cloneMachineSnapshot(state, {
|
|
474
486
|
status: 'error',
|
|
475
487
|
error: event.data
|
|
@@ -505,7 +517,7 @@ class StateMachine {
|
|
|
505
517
|
} = this.config;
|
|
506
518
|
const preInitial = createMachineSnapshot({
|
|
507
519
|
context: typeof context !== 'function' && context ? context : {},
|
|
508
|
-
|
|
520
|
+
_nodes: [this.root],
|
|
509
521
|
children: {},
|
|
510
522
|
status: 'active'
|
|
511
523
|
}, this);
|
|
@@ -583,6 +595,7 @@ class StateMachine {
|
|
|
583
595
|
const actorRef = createActor(logic, {
|
|
584
596
|
id: actorId,
|
|
585
597
|
parent: _actorScope?.self,
|
|
598
|
+
syncSnapshot: actorData.syncSnapshot,
|
|
586
599
|
state: actorState,
|
|
587
600
|
src,
|
|
588
601
|
systemId: actorData.systemId
|
|
@@ -592,7 +605,7 @@ class StateMachine {
|
|
|
592
605
|
const restoredSnapshot = createMachineSnapshot({
|
|
593
606
|
...snapshot,
|
|
594
607
|
children,
|
|
595
|
-
|
|
608
|
+
_nodes: Array.from(getAllStateNodes(getStateNodes(this.root, snapshot.value)))
|
|
596
609
|
}, this);
|
|
597
610
|
let seen = new Set();
|
|
598
611
|
function reviveContext(contextPart, children) {
|
|
@@ -693,4 +706,20 @@ function createMachine(config, implementations) {
|
|
|
693
706
|
return new StateMachine(config, implementations);
|
|
694
707
|
}
|
|
695
708
|
|
|
696
|
-
|
|
709
|
+
function setup({
|
|
710
|
+
actors,
|
|
711
|
+
actions,
|
|
712
|
+
guards,
|
|
713
|
+
delays
|
|
714
|
+
}) {
|
|
715
|
+
return {
|
|
716
|
+
createMachine: config => createMachine(config, {
|
|
717
|
+
actors,
|
|
718
|
+
actions,
|
|
719
|
+
guards,
|
|
720
|
+
delays
|
|
721
|
+
})
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
export { SimulatedClock, StateMachine, StateNode, createMachine, setup, waitFor };
|