xstate 5.0.0-beta.48 → 5.0.0-beta.50
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 -2
- package/actions/dist/xstate-actions.development.cjs.js +2 -2
- package/actions/dist/xstate-actions.development.esm.js +2 -2
- package/actions/dist/xstate-actions.esm.js +2 -2
- 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 +53 -74
- package/actors/dist/xstate-actors.development.cjs.js +53 -74
- package/actors/dist/xstate-actors.development.esm.js +53 -74
- package/actors/dist/xstate-actors.esm.js +53 -74
- 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 +20 -17
- package/dist/declarations/src/StateMachine.d.ts +13 -14
- package/dist/declarations/src/actors/callback.d.ts +6 -9
- package/dist/declarations/src/actors/index.d.ts +3 -3
- package/dist/declarations/src/actors/observable.d.ts +5 -5
- package/dist/declarations/src/actors/promise.d.ts +6 -6
- package/dist/declarations/src/actors/transition.d.ts +3 -3
- package/dist/declarations/src/createMachine.d.ts +17 -2
- package/dist/declarations/src/interpreter.d.ts +2 -2
- package/dist/declarations/src/setup.d.ts +19 -3
- package/dist/declarations/src/stateUtils.d.ts +1 -1
- package/dist/declarations/src/types.d.ts +19 -13
- package/dist/declarations/src/utils.d.ts +0 -1
- package/dist/{raise-84fd7a92.esm.js → raise-32ec7226.esm.js} +94 -33
- package/dist/{raise-286581d5.development.esm.js → raise-6c05c91b.development.esm.js} +94 -33
- package/dist/{raise-cd0dde81.cjs.js → raise-8176cd35.cjs.js} +93 -33
- package/dist/{raise-0eafc1df.development.cjs.js → raise-dc9c2c58.development.cjs.js} +93 -33
- package/dist/{send-f0a3179c.development.esm.js → send-2b001f05.development.esm.js} +2 -7
- package/dist/{send-355ba004.cjs.js → send-7f3db830.cjs.js} +2 -7
- package/dist/{send-ae491737.esm.js → send-88351a33.esm.js} +2 -7
- package/dist/{send-32a63473.development.cjs.js → send-df1c8ef2.development.cjs.js} +2 -7
- package/dist/xstate.cjs.js +11 -20
- package/dist/xstate.development.cjs.js +11 -20
- package/dist/xstate.development.esm.js +13 -22
- package/dist/xstate.esm.js +13 -22
- 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 -1
- package/guards/dist/xstate-guards.development.cjs.js +1 -1
- package/guards/dist/xstate-guards.development.esm.js +1 -1
- package/guards/dist/xstate-guards.esm.js +1 -1
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -250,9 +250,6 @@ function mapValues(collection, iteratee) {
|
|
|
250
250
|
}
|
|
251
251
|
return result;
|
|
252
252
|
}
|
|
253
|
-
function flatten(array) {
|
|
254
|
-
return [].concat(...array);
|
|
255
|
-
}
|
|
256
253
|
function toArrayStrict(value) {
|
|
257
254
|
if (isArray(value)) {
|
|
258
255
|
return value;
|
|
@@ -322,7 +319,7 @@ function resolveReferencedActor(machine, src) {
|
|
|
322
319
|
return machine.implementations.actors[src];
|
|
323
320
|
}
|
|
324
321
|
function getAllOwnEventDescriptors(snapshot) {
|
|
325
|
-
return [...new Set(
|
|
322
|
+
return [...new Set([...snapshot._nodes.flatMap(sn => sn.ownEvents)])];
|
|
326
323
|
}
|
|
327
324
|
|
|
328
325
|
const $$ACTOR_TYPE = 1;
|
|
@@ -457,7 +454,18 @@ class Actor {
|
|
|
457
454
|
}
|
|
458
455
|
}
|
|
459
456
|
_initState(persistedState) {
|
|
460
|
-
|
|
457
|
+
try {
|
|
458
|
+
this._state = persistedState ? this.logic.restoreState ? this.logic.restoreState(persistedState, this._actorScope) : persistedState : this.logic.getInitialState(this._actorScope, this.options?.input);
|
|
459
|
+
} catch (err) {
|
|
460
|
+
// if we get here then it means that we assign a value to this._state that is not of the correct type
|
|
461
|
+
// we can't get the true `TSnapshot & { status: 'error'; }`, it's impossible
|
|
462
|
+
// so right now this is a lie of sorts
|
|
463
|
+
this._state = {
|
|
464
|
+
status: 'error',
|
|
465
|
+
output: undefined,
|
|
466
|
+
error: err
|
|
467
|
+
};
|
|
468
|
+
}
|
|
461
469
|
}
|
|
462
470
|
update(snapshot, event) {
|
|
463
471
|
// Update state
|
|
@@ -466,17 +474,46 @@ class Actor {
|
|
|
466
474
|
// Execute deferred effects
|
|
467
475
|
let deferredFn;
|
|
468
476
|
while (deferredFn = this._deferred.shift()) {
|
|
469
|
-
deferredFn();
|
|
470
|
-
}
|
|
471
|
-
for (const observer of this.observers) {
|
|
472
477
|
try {
|
|
473
|
-
|
|
478
|
+
deferredFn();
|
|
474
479
|
} catch (err) {
|
|
475
|
-
|
|
480
|
+
// this error can only be caught when executing *initial* actions
|
|
481
|
+
// it's the only time when we call actions provided by the user through those deferreds
|
|
482
|
+
// when the actor is already running we always execute them synchronously while transitioning
|
|
483
|
+
// no "builtin deferred" should actually throw an error since they are either safe
|
|
484
|
+
// or the control flow is passed through the mailbox and errors should be caught by the `_process` used by the mailbox
|
|
485
|
+
this._deferred.length = 0;
|
|
486
|
+
this._state = {
|
|
487
|
+
...snapshot,
|
|
488
|
+
status: 'error',
|
|
489
|
+
error: err
|
|
490
|
+
};
|
|
476
491
|
}
|
|
477
492
|
}
|
|
478
493
|
switch (this._state.status) {
|
|
494
|
+
case 'active':
|
|
495
|
+
for (const observer of this.observers) {
|
|
496
|
+
try {
|
|
497
|
+
observer.next?.(snapshot);
|
|
498
|
+
} catch (err) {
|
|
499
|
+
reportUnhandledError(err);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
break;
|
|
479
503
|
case 'done':
|
|
504
|
+
// next observers are meant to be notified about done snapshots
|
|
505
|
+
// this can be seen as something that is different from how observable work
|
|
506
|
+
// but with observables `complete` callback is called without any arguments
|
|
507
|
+
// it's more ergonomic for XState to treat a done snapshot as a "next" value
|
|
508
|
+
// and the completion event as something that is separate,
|
|
509
|
+
// something that merely follows emitting that done snapshot
|
|
510
|
+
for (const observer of this.observers) {
|
|
511
|
+
try {
|
|
512
|
+
observer.next?.(snapshot);
|
|
513
|
+
} catch (err) {
|
|
514
|
+
reportUnhandledError(err);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
480
517
|
this._stopProcedure();
|
|
481
518
|
this._complete();
|
|
482
519
|
this._doneEvent = createDoneActorEvent(this.id, this._state.output);
|
|
@@ -485,11 +522,7 @@ class Actor {
|
|
|
485
522
|
}
|
|
486
523
|
break;
|
|
487
524
|
case 'error':
|
|
488
|
-
this._stopProcedure();
|
|
489
525
|
this._error(this._state.error);
|
|
490
|
-
if (this._parent) {
|
|
491
|
-
this.system._relay(this, this._parent, createErrorActorEvent(this.id, this._state.error));
|
|
492
|
-
}
|
|
493
526
|
break;
|
|
494
527
|
}
|
|
495
528
|
this.system._sendInspectionEvent({
|
|
@@ -579,7 +612,7 @@ class Actor {
|
|
|
579
612
|
this.subscribe({
|
|
580
613
|
next: snapshot => {
|
|
581
614
|
if (snapshot.status === 'active') {
|
|
582
|
-
this.
|
|
615
|
+
this.system._relay(this, this._parent, {
|
|
583
616
|
type: `xstate.snapshot.${this.id}`,
|
|
584
617
|
snapshot
|
|
585
618
|
});
|
|
@@ -608,18 +641,22 @@ class Actor {
|
|
|
608
641
|
// a state machine can be "done" upon initialization (it could reach a final state using initial microsteps)
|
|
609
642
|
// we still need to complete observers, flush deferreds etc
|
|
610
643
|
this.update(this._state, initEvent);
|
|
611
|
-
// fallthrough
|
|
612
|
-
case 'error':
|
|
613
644
|
// TODO: rethink cleanup of observers, mailbox, etc
|
|
614
645
|
return this;
|
|
646
|
+
case 'error':
|
|
647
|
+
this._error(this._state.error);
|
|
648
|
+
return this;
|
|
615
649
|
}
|
|
616
650
|
if (this.logic.start) {
|
|
617
651
|
try {
|
|
618
652
|
this.logic.start(this._state, this._actorScope);
|
|
619
653
|
} catch (err) {
|
|
620
|
-
this.
|
|
654
|
+
this._state = {
|
|
655
|
+
...this._state,
|
|
656
|
+
status: 'error',
|
|
657
|
+
error: err
|
|
658
|
+
};
|
|
621
659
|
this._error(err);
|
|
622
|
-
this._parent?.send(createErrorActorEvent(this.id, err));
|
|
623
660
|
return this;
|
|
624
661
|
}
|
|
625
662
|
}
|
|
@@ -635,7 +672,6 @@ class Actor {
|
|
|
635
672
|
return this;
|
|
636
673
|
}
|
|
637
674
|
_process(event) {
|
|
638
|
-
// TODO: reexamine what happens when an action (or a guard or smth) throws
|
|
639
675
|
let nextState;
|
|
640
676
|
let caughtError;
|
|
641
677
|
try {
|
|
@@ -650,9 +686,12 @@ class Actor {
|
|
|
650
686
|
const {
|
|
651
687
|
err
|
|
652
688
|
} = caughtError;
|
|
653
|
-
this.
|
|
689
|
+
this._state = {
|
|
690
|
+
...this._state,
|
|
691
|
+
status: 'error',
|
|
692
|
+
error: err
|
|
693
|
+
};
|
|
654
694
|
this._error(err);
|
|
655
|
-
this._parent?.send(createErrorActorEvent(this.id, err));
|
|
656
695
|
return;
|
|
657
696
|
}
|
|
658
697
|
this.update(nextState, event);
|
|
@@ -695,7 +734,7 @@ class Actor {
|
|
|
695
734
|
}
|
|
696
735
|
this.observers.clear();
|
|
697
736
|
}
|
|
698
|
-
|
|
737
|
+
_reportError(err) {
|
|
699
738
|
if (!this.observers.size) {
|
|
700
739
|
if (!this._parent) {
|
|
701
740
|
reportUnhandledError(err);
|
|
@@ -717,6 +756,18 @@ class Actor {
|
|
|
717
756
|
reportUnhandledError(err);
|
|
718
757
|
}
|
|
719
758
|
}
|
|
759
|
+
_error(err) {
|
|
760
|
+
this._stopProcedure();
|
|
761
|
+
this._reportError(err);
|
|
762
|
+
if (this._parent) {
|
|
763
|
+
this.system._relay(this, this._parent, createErrorActorEvent(this.id, err));
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
// TODO: atm children don't belong entirely to the actor so
|
|
767
|
+
// in a way - it's not even super aware of them
|
|
768
|
+
// so we can't stop them from here but we really should!
|
|
769
|
+
// right now, they are being stopped within the machine's transition
|
|
770
|
+
// but that could throw and leave us with "orphaned" active actors
|
|
720
771
|
_stopProcedure() {
|
|
721
772
|
if (this._processingStatus !== ProcessingStatus.Running) {
|
|
722
773
|
// Actor already stopped; do nothing
|
|
@@ -976,12 +1027,7 @@ function executeSpawn(actorScope, {
|
|
|
976
1027
|
if (actorRef._processingStatus === ProcessingStatus.Stopped) {
|
|
977
1028
|
return;
|
|
978
1029
|
}
|
|
979
|
-
|
|
980
|
-
actorRef.start?.();
|
|
981
|
-
} catch (err) {
|
|
982
|
-
actorScope.self.send(createErrorActorEvent(id, err));
|
|
983
|
-
return;
|
|
984
|
-
}
|
|
1030
|
+
actorRef.start();
|
|
985
1031
|
});
|
|
986
1032
|
}
|
|
987
1033
|
function spawnChild(...[src, {
|
|
@@ -2064,7 +2110,23 @@ function macrostep(state, event, actorScope, internalQueue = []) {
|
|
|
2064
2110
|
// Assume the state is at rest (no raised events)
|
|
2065
2111
|
// Determine the next state based on the next microstep
|
|
2066
2112
|
if (nextEvent.type !== XSTATE_INIT) {
|
|
2067
|
-
const
|
|
2113
|
+
const currentEvent = nextEvent;
|
|
2114
|
+
const isErr = isErrorActorEvent(currentEvent);
|
|
2115
|
+
const transitions = selectTransitions(currentEvent, nextState);
|
|
2116
|
+
if (isErr && !transitions.length) {
|
|
2117
|
+
// TODO: we should likely only allow transitions selected by very explicit descriptors
|
|
2118
|
+
// `*` shouldn't be matched, likely `xstate.error.*` shouldnt be either
|
|
2119
|
+
// similarly `xstate.error.actor.*` and `xstate.error.actor.todo.*` have to be considered too
|
|
2120
|
+
nextState = cloneMachineSnapshot(state, {
|
|
2121
|
+
status: 'error',
|
|
2122
|
+
error: currentEvent.data
|
|
2123
|
+
});
|
|
2124
|
+
states.push(nextState);
|
|
2125
|
+
return {
|
|
2126
|
+
state: nextState,
|
|
2127
|
+
microstates: states
|
|
2128
|
+
};
|
|
2129
|
+
}
|
|
2068
2130
|
nextState = microstep(transitions, state, actorScope, nextEvent, false, internalQueue);
|
|
2069
2131
|
states.push(nextState);
|
|
2070
2132
|
}
|
|
@@ -2181,10 +2243,9 @@ function createMachineSnapshot(config, machine) {
|
|
|
2181
2243
|
context: config.context,
|
|
2182
2244
|
_nodes: config._nodes,
|
|
2183
2245
|
value: getStateValue(machine.root, config._nodes),
|
|
2184
|
-
tags: new Set(
|
|
2246
|
+
tags: new Set(config._nodes.flatMap(sn => sn.tags)),
|
|
2185
2247
|
children: config.children,
|
|
2186
2248
|
historyValue: config.historyValue || {},
|
|
2187
|
-
// this one is generic in the target and it's hard to create a matching non-generic source signature
|
|
2188
2249
|
matches: machineSnapshotMatches,
|
|
2189
2250
|
hasTag: machineSnapshotHasTag,
|
|
2190
2251
|
can: machineSnapshotCan,
|
|
@@ -2342,7 +2403,6 @@ exports.getPersistedState = getPersistedState;
|
|
|
2342
2403
|
exports.getStateNodeByPath = getStateNodeByPath;
|
|
2343
2404
|
exports.getStateNodes = getStateNodes;
|
|
2344
2405
|
exports.interpret = interpret;
|
|
2345
|
-
exports.isErrorActorEvent = isErrorActorEvent;
|
|
2346
2406
|
exports.isInFinalState = isInFinalState;
|
|
2347
2407
|
exports.isMachineSnapshot = isMachineSnapshot;
|
|
2348
2408
|
exports.isStateId = isStateId;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { R as ProcessingStatus, y as resolveReferencedActor, z as createActor, T as cloneMachineSnapshot, e as evaluateGuard, t as toArray, U as XSTATE_ERROR, V as createErrorActorEvent } from './raise-6c05c91b.development.esm.js';
|
|
2
2
|
|
|
3
3
|
function createSpawner(actorScope, {
|
|
4
4
|
machine,
|
|
@@ -47,12 +47,7 @@ function createSpawner(actorScope, {
|
|
|
47
47
|
if (actorRef._processingStatus === ProcessingStatus.Stopped) {
|
|
48
48
|
return;
|
|
49
49
|
}
|
|
50
|
-
|
|
51
|
-
actorRef.start?.();
|
|
52
|
-
} catch (err) {
|
|
53
|
-
actorScope.self.send(createErrorActorEvent(actorRef.id, err));
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
50
|
+
actorRef.start();
|
|
56
51
|
});
|
|
57
52
|
return actorRef;
|
|
58
53
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
3
|
+
var guards_dist_xstateGuards = require('./raise-8176cd35.cjs.js');
|
|
4
4
|
|
|
5
5
|
function createSpawner(actorScope, {
|
|
6
6
|
machine,
|
|
@@ -49,12 +49,7 @@ function createSpawner(actorScope, {
|
|
|
49
49
|
if (actorRef._processingStatus === guards_dist_xstateGuards.ProcessingStatus.Stopped) {
|
|
50
50
|
return;
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
actorRef.start?.();
|
|
54
|
-
} catch (err) {
|
|
55
|
-
actorScope.self.send(guards_dist_xstateGuards.createErrorActorEvent(actorRef.id, err));
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
52
|
+
actorRef.start();
|
|
58
53
|
});
|
|
59
54
|
return actorRef;
|
|
60
55
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { R as ProcessingStatus, y as resolveReferencedActor, z as createActor, T as cloneMachineSnapshot, e as evaluateGuard, t as toArray, U as XSTATE_ERROR, V as createErrorActorEvent } from './raise-32ec7226.esm.js';
|
|
2
2
|
|
|
3
3
|
function createSpawner(actorScope, {
|
|
4
4
|
machine,
|
|
@@ -47,12 +47,7 @@ function createSpawner(actorScope, {
|
|
|
47
47
|
if (actorRef._processingStatus === ProcessingStatus.Stopped) {
|
|
48
48
|
return;
|
|
49
49
|
}
|
|
50
|
-
|
|
51
|
-
actorRef.start?.();
|
|
52
|
-
} catch (err) {
|
|
53
|
-
actorScope.self.send(createErrorActorEvent(actorRef.id, err));
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
50
|
+
actorRef.start();
|
|
56
51
|
});
|
|
57
52
|
return actorRef;
|
|
58
53
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
3
|
+
var guards_dist_xstateGuards = require('./raise-dc9c2c58.development.cjs.js');
|
|
4
4
|
|
|
5
5
|
function createSpawner(actorScope, {
|
|
6
6
|
machine,
|
|
@@ -49,12 +49,7 @@ function createSpawner(actorScope, {
|
|
|
49
49
|
if (actorRef._processingStatus === guards_dist_xstateGuards.ProcessingStatus.Stopped) {
|
|
50
50
|
return;
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
actorRef.start?.();
|
|
54
|
-
} catch (err) {
|
|
55
|
-
actorScope.self.send(guards_dist_xstateGuards.createErrorActorEvent(actorRef.id, err));
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
52
|
+
actorRef.start();
|
|
58
53
|
});
|
|
59
54
|
return actorRef;
|
|
60
55
|
};
|
package/dist/xstate.cjs.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var actors_dist_xstateActors = require('../actors/dist/xstate-actors.cjs.js');
|
|
6
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
7
|
-
var send = require('./send-
|
|
6
|
+
var guards_dist_xstateGuards = require('./raise-8176cd35.cjs.js');
|
|
7
|
+
var send = require('./send-7f3db830.cjs.js');
|
|
8
8
|
require('../dev/dist/xstate-dev.cjs.js');
|
|
9
9
|
|
|
10
10
|
class SimulatedClock {
|
|
@@ -372,7 +372,6 @@ class StateMachine {
|
|
|
372
372
|
*/
|
|
373
373
|
this.version = void 0;
|
|
374
374
|
this.implementations = void 0;
|
|
375
|
-
this.types = void 0;
|
|
376
375
|
this.__xstatenode = true;
|
|
377
376
|
this.idMap = new Map();
|
|
378
377
|
this.root = void 0;
|
|
@@ -389,7 +388,6 @@ class StateMachine {
|
|
|
389
388
|
guards: implementations?.guards ?? {}
|
|
390
389
|
};
|
|
391
390
|
this.version = this.config.version;
|
|
392
|
-
this.types = this.config.types ?? {};
|
|
393
391
|
this.transition = this.transition.bind(this);
|
|
394
392
|
this.getInitialState = this.getInitialState.bind(this);
|
|
395
393
|
this.restoreState = this.restoreState.bind(this);
|
|
@@ -453,24 +451,14 @@ class StateMachine {
|
|
|
453
451
|
}
|
|
454
452
|
|
|
455
453
|
/**
|
|
456
|
-
* Determines the next
|
|
454
|
+
* Determines the next snapshot given the current `snapshot` and received `event`.
|
|
457
455
|
* Calculates a full macrostep from all microsteps.
|
|
458
456
|
*
|
|
459
|
-
* @param
|
|
457
|
+
* @param snapshot The current snapshot
|
|
460
458
|
* @param event The received event
|
|
461
459
|
*/
|
|
462
|
-
transition(
|
|
463
|
-
|
|
464
|
-
if (guards_dist_xstateGuards.isErrorActorEvent(event) && !guards_dist_xstateGuards.getAllOwnEventDescriptors(state).some(nextEvent => nextEvent === event.type)) {
|
|
465
|
-
return guards_dist_xstateGuards.cloneMachineSnapshot(state, {
|
|
466
|
-
status: 'error',
|
|
467
|
-
error: event.data
|
|
468
|
-
});
|
|
469
|
-
}
|
|
470
|
-
const {
|
|
471
|
-
state: nextState
|
|
472
|
-
} = guards_dist_xstateGuards.macrostep(state, event, actorScope);
|
|
473
|
-
return nextState;
|
|
460
|
+
transition(snapshot, event, actorScope) {
|
|
461
|
+
return guards_dist_xstateGuards.macrostep(snapshot, event, actorScope).state;
|
|
474
462
|
}
|
|
475
463
|
|
|
476
464
|
/**
|
|
@@ -483,8 +471,8 @@ class StateMachine {
|
|
|
483
471
|
microstep(state, event, actorScope) {
|
|
484
472
|
return guards_dist_xstateGuards.macrostep(state, event, actorScope).microstates;
|
|
485
473
|
}
|
|
486
|
-
getTransitionData(
|
|
487
|
-
return guards_dist_xstateGuards.transitionNode(this.root,
|
|
474
|
+
getTransitionData(snapshot, event) {
|
|
475
|
+
return guards_dist_xstateGuards.transitionNode(this.root, snapshot.value, snapshot, event) || [];
|
|
488
476
|
}
|
|
489
477
|
|
|
490
478
|
/**
|
|
@@ -679,6 +667,9 @@ function waitFor(actorRef, predicate, options) {
|
|
|
679
667
|
});
|
|
680
668
|
}
|
|
681
669
|
|
|
670
|
+
// this is not 100% accurate since we can't make parallel regions required in the result
|
|
671
|
+
// `TTestValue` doesn't encode this information anyhow for us to be able to do that
|
|
672
|
+
// this is fine for most practical use cases anyway though
|
|
682
673
|
function createMachine(config, implementations) {
|
|
683
674
|
return new StateMachine(config, implementations);
|
|
684
675
|
}
|
|
@@ -3,8 +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 guards_dist_xstateGuards = require('./raise-
|
|
7
|
-
var send = require('./send-
|
|
6
|
+
var guards_dist_xstateGuards = require('./raise-dc9c2c58.development.cjs.js');
|
|
7
|
+
var send = require('./send-df1c8ef2.development.cjs.js');
|
|
8
8
|
require('../dev/dist/xstate-dev.development.cjs.js');
|
|
9
9
|
|
|
10
10
|
class SimulatedClock {
|
|
@@ -372,7 +372,6 @@ class StateMachine {
|
|
|
372
372
|
*/
|
|
373
373
|
this.version = void 0;
|
|
374
374
|
this.implementations = void 0;
|
|
375
|
-
this.types = void 0;
|
|
376
375
|
this.__xstatenode = true;
|
|
377
376
|
this.idMap = new Map();
|
|
378
377
|
this.root = void 0;
|
|
@@ -389,7 +388,6 @@ class StateMachine {
|
|
|
389
388
|
guards: implementations?.guards ?? {}
|
|
390
389
|
};
|
|
391
390
|
this.version = this.config.version;
|
|
392
|
-
this.types = this.config.types ?? {};
|
|
393
391
|
this.transition = this.transition.bind(this);
|
|
394
392
|
this.getInitialState = this.getInitialState.bind(this);
|
|
395
393
|
this.restoreState = this.restoreState.bind(this);
|
|
@@ -456,24 +454,14 @@ class StateMachine {
|
|
|
456
454
|
}
|
|
457
455
|
|
|
458
456
|
/**
|
|
459
|
-
* Determines the next
|
|
457
|
+
* Determines the next snapshot given the current `snapshot` and received `event`.
|
|
460
458
|
* Calculates a full macrostep from all microsteps.
|
|
461
459
|
*
|
|
462
|
-
* @param
|
|
460
|
+
* @param snapshot The current snapshot
|
|
463
461
|
* @param event The received event
|
|
464
462
|
*/
|
|
465
|
-
transition(
|
|
466
|
-
|
|
467
|
-
if (guards_dist_xstateGuards.isErrorActorEvent(event) && !guards_dist_xstateGuards.getAllOwnEventDescriptors(state).some(nextEvent => nextEvent === event.type)) {
|
|
468
|
-
return guards_dist_xstateGuards.cloneMachineSnapshot(state, {
|
|
469
|
-
status: 'error',
|
|
470
|
-
error: event.data
|
|
471
|
-
});
|
|
472
|
-
}
|
|
473
|
-
const {
|
|
474
|
-
state: nextState
|
|
475
|
-
} = guards_dist_xstateGuards.macrostep(state, event, actorScope);
|
|
476
|
-
return nextState;
|
|
463
|
+
transition(snapshot, event, actorScope) {
|
|
464
|
+
return guards_dist_xstateGuards.macrostep(snapshot, event, actorScope).state;
|
|
477
465
|
}
|
|
478
466
|
|
|
479
467
|
/**
|
|
@@ -486,8 +474,8 @@ class StateMachine {
|
|
|
486
474
|
microstep(state, event, actorScope) {
|
|
487
475
|
return guards_dist_xstateGuards.macrostep(state, event, actorScope).microstates;
|
|
488
476
|
}
|
|
489
|
-
getTransitionData(
|
|
490
|
-
return guards_dist_xstateGuards.transitionNode(this.root,
|
|
477
|
+
getTransitionData(snapshot, event) {
|
|
478
|
+
return guards_dist_xstateGuards.transitionNode(this.root, snapshot.value, snapshot, event) || [];
|
|
491
479
|
}
|
|
492
480
|
|
|
493
481
|
/**
|
|
@@ -685,6 +673,9 @@ function waitFor(actorRef, predicate, options) {
|
|
|
685
673
|
});
|
|
686
674
|
}
|
|
687
675
|
|
|
676
|
+
// this is not 100% accurate since we can't make parallel regions required in the result
|
|
677
|
+
// `TTestValue` doesn't encode this information anyhow for us to be able to do that
|
|
678
|
+
// this is fine for most practical use cases anyway though
|
|
688
679
|
function createMachine(config, implementations) {
|
|
689
680
|
return new StateMachine(config, implementations);
|
|
690
681
|
}
|
|
@@ -1,8 +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, 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
|
|
3
|
-
export {
|
|
4
|
-
import { a as assign } from './send-
|
|
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-
|
|
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 macrostep, o as transitionNode, p as resolveActionsAndContext, q as createInitEvent, s as microstep, u as getInitialStateNodes, v as isStateId, w as getStateNodeByPath, x as getPersistedState, y as resolveReferencedActor, z as createActor, $ as $$ACTOR_TYPE } from './raise-6c05c91b.development.esm.js';
|
|
3
|
+
export { A as Actor, G as __unsafe_getAllOwnEventDescriptors, H as and, L as cancel, z as createActor, j as getStateNodes, B as interpret, C as isMachineSnapshot, D as matchesState, I as not, J as or, E as pathToStateValue, M as raise, Q as spawnChild, K as stateIn, O as stop, P as stopChild, F as toObserver } from './raise-6c05c91b.development.esm.js';
|
|
4
|
+
import { a as assign } from './send-2b001f05.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-2b001f05.development.esm.js';
|
|
6
6
|
import '../dev/dist/xstate-dev.development.esm.js';
|
|
7
7
|
|
|
8
8
|
class SimulatedClock {
|
|
@@ -370,7 +370,6 @@ class StateMachine {
|
|
|
370
370
|
*/
|
|
371
371
|
this.version = void 0;
|
|
372
372
|
this.implementations = void 0;
|
|
373
|
-
this.types = void 0;
|
|
374
373
|
this.__xstatenode = true;
|
|
375
374
|
this.idMap = new Map();
|
|
376
375
|
this.root = void 0;
|
|
@@ -387,7 +386,6 @@ class StateMachine {
|
|
|
387
386
|
guards: implementations?.guards ?? {}
|
|
388
387
|
};
|
|
389
388
|
this.version = this.config.version;
|
|
390
|
-
this.types = this.config.types ?? {};
|
|
391
389
|
this.transition = this.transition.bind(this);
|
|
392
390
|
this.getInitialState = this.getInitialState.bind(this);
|
|
393
391
|
this.restoreState = this.restoreState.bind(this);
|
|
@@ -454,24 +452,14 @@ class StateMachine {
|
|
|
454
452
|
}
|
|
455
453
|
|
|
456
454
|
/**
|
|
457
|
-
* Determines the next
|
|
455
|
+
* Determines the next snapshot given the current `snapshot` and received `event`.
|
|
458
456
|
* Calculates a full macrostep from all microsteps.
|
|
459
457
|
*
|
|
460
|
-
* @param
|
|
458
|
+
* @param snapshot The current snapshot
|
|
461
459
|
* @param event The received event
|
|
462
460
|
*/
|
|
463
|
-
transition(
|
|
464
|
-
|
|
465
|
-
if (isErrorActorEvent(event) && !getAllOwnEventDescriptors(state).some(nextEvent => nextEvent === event.type)) {
|
|
466
|
-
return cloneMachineSnapshot(state, {
|
|
467
|
-
status: 'error',
|
|
468
|
-
error: event.data
|
|
469
|
-
});
|
|
470
|
-
}
|
|
471
|
-
const {
|
|
472
|
-
state: nextState
|
|
473
|
-
} = macrostep(state, event, actorScope);
|
|
474
|
-
return nextState;
|
|
461
|
+
transition(snapshot, event, actorScope) {
|
|
462
|
+
return macrostep(snapshot, event, actorScope).state;
|
|
475
463
|
}
|
|
476
464
|
|
|
477
465
|
/**
|
|
@@ -484,8 +472,8 @@ class StateMachine {
|
|
|
484
472
|
microstep(state, event, actorScope) {
|
|
485
473
|
return macrostep(state, event, actorScope).microstates;
|
|
486
474
|
}
|
|
487
|
-
getTransitionData(
|
|
488
|
-
return transitionNode(this.root,
|
|
475
|
+
getTransitionData(snapshot, event) {
|
|
476
|
+
return transitionNode(this.root, snapshot.value, snapshot, event) || [];
|
|
489
477
|
}
|
|
490
478
|
|
|
491
479
|
/**
|
|
@@ -683,6 +671,9 @@ function waitFor(actorRef, predicate, options) {
|
|
|
683
671
|
});
|
|
684
672
|
}
|
|
685
673
|
|
|
674
|
+
// this is not 100% accurate since we can't make parallel regions required in the result
|
|
675
|
+
// `TTestValue` doesn't encode this information anyhow for us to be able to do that
|
|
676
|
+
// this is fine for most practical use cases anyway though
|
|
686
677
|
function createMachine(config, implementations) {
|
|
687
678
|
return new StateMachine(config, implementations);
|
|
688
679
|
}
|
package/dist/xstate.esm.js
CHANGED
|
@@ -1,8 +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, 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
|
|
3
|
-
export {
|
|
4
|
-
import { a as assign } from './send-
|
|
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-
|
|
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 macrostep, o as transitionNode, p as resolveActionsAndContext, q as createInitEvent, s as microstep, u as getInitialStateNodes, v as isStateId, w as getStateNodeByPath, x as getPersistedState, y as resolveReferencedActor, z as createActor, $ as $$ACTOR_TYPE } from './raise-32ec7226.esm.js';
|
|
3
|
+
export { A as Actor, G as __unsafe_getAllOwnEventDescriptors, H as and, L as cancel, z as createActor, j as getStateNodes, B as interpret, C as isMachineSnapshot, D as matchesState, I as not, J as or, E as pathToStateValue, M as raise, Q as spawnChild, K as stateIn, O as stop, P as stopChild, F as toObserver } from './raise-32ec7226.esm.js';
|
|
4
|
+
import { a as assign } from './send-88351a33.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-88351a33.esm.js';
|
|
6
6
|
import '../dev/dist/xstate-dev.esm.js';
|
|
7
7
|
|
|
8
8
|
class SimulatedClock {
|
|
@@ -370,7 +370,6 @@ class StateMachine {
|
|
|
370
370
|
*/
|
|
371
371
|
this.version = void 0;
|
|
372
372
|
this.implementations = void 0;
|
|
373
|
-
this.types = void 0;
|
|
374
373
|
this.__xstatenode = true;
|
|
375
374
|
this.idMap = new Map();
|
|
376
375
|
this.root = void 0;
|
|
@@ -387,7 +386,6 @@ class StateMachine {
|
|
|
387
386
|
guards: implementations?.guards ?? {}
|
|
388
387
|
};
|
|
389
388
|
this.version = this.config.version;
|
|
390
|
-
this.types = this.config.types ?? {};
|
|
391
389
|
this.transition = this.transition.bind(this);
|
|
392
390
|
this.getInitialState = this.getInitialState.bind(this);
|
|
393
391
|
this.restoreState = this.restoreState.bind(this);
|
|
@@ -451,24 +449,14 @@ class StateMachine {
|
|
|
451
449
|
}
|
|
452
450
|
|
|
453
451
|
/**
|
|
454
|
-
* Determines the next
|
|
452
|
+
* Determines the next snapshot given the current `snapshot` and received `event`.
|
|
455
453
|
* Calculates a full macrostep from all microsteps.
|
|
456
454
|
*
|
|
457
|
-
* @param
|
|
455
|
+
* @param snapshot The current snapshot
|
|
458
456
|
* @param event The received event
|
|
459
457
|
*/
|
|
460
|
-
transition(
|
|
461
|
-
|
|
462
|
-
if (isErrorActorEvent(event) && !getAllOwnEventDescriptors(state).some(nextEvent => nextEvent === event.type)) {
|
|
463
|
-
return cloneMachineSnapshot(state, {
|
|
464
|
-
status: 'error',
|
|
465
|
-
error: event.data
|
|
466
|
-
});
|
|
467
|
-
}
|
|
468
|
-
const {
|
|
469
|
-
state: nextState
|
|
470
|
-
} = macrostep(state, event, actorScope);
|
|
471
|
-
return nextState;
|
|
458
|
+
transition(snapshot, event, actorScope) {
|
|
459
|
+
return macrostep(snapshot, event, actorScope).state;
|
|
472
460
|
}
|
|
473
461
|
|
|
474
462
|
/**
|
|
@@ -481,8 +469,8 @@ class StateMachine {
|
|
|
481
469
|
microstep(state, event, actorScope) {
|
|
482
470
|
return macrostep(state, event, actorScope).microstates;
|
|
483
471
|
}
|
|
484
|
-
getTransitionData(
|
|
485
|
-
return transitionNode(this.root,
|
|
472
|
+
getTransitionData(snapshot, event) {
|
|
473
|
+
return transitionNode(this.root, snapshot.value, snapshot, event) || [];
|
|
486
474
|
}
|
|
487
475
|
|
|
488
476
|
/**
|
|
@@ -677,6 +665,9 @@ function waitFor(actorRef, predicate, options) {
|
|
|
677
665
|
});
|
|
678
666
|
}
|
|
679
667
|
|
|
668
|
+
// this is not 100% accurate since we can't make parallel regions required in the result
|
|
669
|
+
// `TTestValue` doesn't encode this information anyhow for us to be able to do that
|
|
670
|
+
// this is fine for most practical use cases anyway though
|
|
680
671
|
function createMachine(config, implementations) {
|
|
681
672
|
return new StateMachine(config, implementations);
|
|
682
673
|
}
|