xstate 5.18.0 → 5.18.2
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.d.mts +1 -1
- package/actions/dist/xstate-actions.cjs.d.ts +1 -1
- 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.d.mts +1 -1
- package/actors/dist/xstate-actors.cjs.d.ts +1 -1
- package/actors/dist/xstate-actors.cjs.js +1 -1
- package/actors/dist/xstate-actors.development.cjs.js +1 -1
- package/actors/dist/xstate-actors.development.esm.js +1 -1
- package/actors/dist/xstate-actors.esm.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dev/dist/xstate-dev.cjs.d.mts +1 -1
- package/dev/dist/xstate-dev.cjs.d.ts +1 -1
- package/dist/declarations/src/State.d.ts +1 -1
- package/dist/declarations/src/createActor.d.ts +3 -4
- package/dist/declarations/src/index.d.ts +5 -5
- package/dist/declarations/src/inspection.d.ts +2 -2
- package/dist/{log-54d038f7.esm.js → log-15d0f775.esm.js} +9 -2
- package/dist/{log-4f8360d3.development.esm.js → log-38475d87.development.esm.js} +9 -2
- package/dist/{log-f7dcaa97.cjs.js → log-98fcce74.cjs.js} +9 -2
- package/dist/{log-40d606d3.development.cjs.js → log-b7ed1b61.development.cjs.js} +9 -2
- package/dist/{State-cdbc7940.esm.js → raise-0f7cf128.esm.js} +191 -192
- package/dist/{State-34039d2a.development.esm.js → raise-5ea71f04.development.esm.js} +206 -207
- package/dist/{State-30c95050.cjs.js → raise-b1e0b9a9.cjs.js} +190 -191
- package/dist/{State-a2464a1e.development.cjs.js → raise-e919c5d4.development.cjs.js} +205 -206
- package/dist/xstate.cjs.d.mts +1 -1
- package/dist/xstate.cjs.d.ts +1 -1
- package/dist/xstate.cjs.js +106 -104
- package/dist/xstate.development.cjs.js +106 -104
- package/dist/xstate.development.esm.js +102 -100
- package/dist/xstate.esm.js +102 -100
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.d.mts +1 -1
- package/guards/dist/xstate-guards.cjs.d.ts +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 +7 -7
- package/actions/dist/xstate-actions.cjs.d.mts.map +0 -1
- package/actions/dist/xstate-actions.cjs.d.ts.map +0 -1
- package/actors/dist/xstate-actors.cjs.d.mts.map +0 -1
- package/actors/dist/xstate-actors.cjs.d.ts.map +0 -1
- package/dev/dist/xstate-dev.cjs.d.mts.map +0 -1
- package/dev/dist/xstate-dev.cjs.d.ts.map +0 -1
- package/dist/xstate.cjs.d.mts.map +0 -1
- package/dist/xstate.cjs.d.ts.map +0 -1
- package/guards/dist/xstate-guards.cjs.d.mts.map +0 -1
- package/guards/dist/xstate-guards.cjs.d.ts.map +0 -1
package/dist/xstate.cjs.js
CHANGED
|
@@ -2,74 +2,39 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var guards_dist_xstateGuards = require('./State-30c95050.cjs.js');
|
|
6
|
-
var log = require('./log-f7dcaa97.cjs.js');
|
|
7
5
|
var actors_dist_xstateActors = require('../actors/dist/xstate-actors.cjs.js');
|
|
6
|
+
var guards_dist_xstateGuards = require('./raise-b1e0b9a9.cjs.js');
|
|
7
|
+
var log = require('./log-98fcce74.cjs.js');
|
|
8
8
|
require('../dev/dist/xstate-dev.cjs.js');
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
set(time) {
|
|
39
|
-
if (this._now > time) {
|
|
40
|
-
throw new Error('Unable to travel back in time');
|
|
41
|
-
}
|
|
42
|
-
this._now = time;
|
|
43
|
-
this.flushTimeouts();
|
|
44
|
-
}
|
|
45
|
-
flushTimeouts() {
|
|
46
|
-
if (this._flushing) {
|
|
47
|
-
this._flushingInvalidated = true;
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
this._flushing = true;
|
|
51
|
-
const sorted = [...this.timeouts].sort(([_idA, timeoutA], [_idB, timeoutB]) => {
|
|
52
|
-
const endA = timeoutA.start + timeoutA.timeout;
|
|
53
|
-
const endB = timeoutB.start + timeoutB.timeout;
|
|
54
|
-
return endB > endA ? -1 : 1;
|
|
55
|
-
});
|
|
56
|
-
for (const [id, timeout] of sorted) {
|
|
57
|
-
if (this._flushingInvalidated) {
|
|
58
|
-
this._flushingInvalidated = false;
|
|
59
|
-
this._flushing = false;
|
|
60
|
-
this.flushTimeouts();
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
if (this.now() - timeout.start >= timeout.timeout) {
|
|
64
|
-
this.timeouts.delete(id);
|
|
65
|
-
timeout.fn.call(null);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
this._flushing = false;
|
|
69
|
-
}
|
|
70
|
-
increment(ms) {
|
|
71
|
-
this._now += ms;
|
|
72
|
-
this.flushTimeouts();
|
|
10
|
+
/**
|
|
11
|
+
* Asserts that the given event object is of the specified type or types. Throws
|
|
12
|
+
* an error if the event object is not of the specified types.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* // ...
|
|
18
|
+
* entry: ({ event }) => {
|
|
19
|
+
* assertEvent(event, 'doNothing');
|
|
20
|
+
* // event is { type: 'doNothing' }
|
|
21
|
+
* },
|
|
22
|
+
* // ...
|
|
23
|
+
* exit: ({ event }) => {
|
|
24
|
+
* assertEvent(event, 'greet');
|
|
25
|
+
* // event is { type: 'greet'; message: string }
|
|
26
|
+
*
|
|
27
|
+
* assertEvent(event, ['greet', 'notify']);
|
|
28
|
+
* // event is { type: 'greet'; message: string }
|
|
29
|
+
* // or { type: 'notify'; message: string; level: 'info' | 'error' }
|
|
30
|
+
* },
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
function assertEvent(event, type) {
|
|
34
|
+
const types = guards_dist_xstateGuards.toArray(type);
|
|
35
|
+
if (!types.includes(event.type)) {
|
|
36
|
+
const typesText = types.length === 1 ? `type "${types[0]}"` : `one of types "${types.join('", "')}"`;
|
|
37
|
+
throw new Error(`Expected event ${JSON.stringify(event)} to have ${typesText}`);
|
|
73
38
|
}
|
|
74
39
|
}
|
|
75
40
|
|
|
@@ -107,7 +72,7 @@ const toSerializableAction = action => {
|
|
|
107
72
|
return action;
|
|
108
73
|
};
|
|
109
74
|
class StateNode {
|
|
110
|
-
constructor(
|
|
75
|
+
constructor(/** The raw config used to create the machine. */
|
|
111
76
|
config, options) {
|
|
112
77
|
this.config = config;
|
|
113
78
|
/**
|
|
@@ -363,7 +328,7 @@ class StateNode {
|
|
|
363
328
|
|
|
364
329
|
const STATE_IDENTIFIER = '#';
|
|
365
330
|
class StateMachine {
|
|
366
|
-
constructor(
|
|
331
|
+
constructor(/** The raw config used to create the machine. */
|
|
367
332
|
config, implementations) {
|
|
368
333
|
this.config = config;
|
|
369
334
|
/** The machine's own version. */
|
|
@@ -598,40 +563,10 @@ class StateMachine {
|
|
|
598
563
|
}
|
|
599
564
|
}
|
|
600
565
|
|
|
601
|
-
/**
|
|
602
|
-
* Asserts that the given event object is of the specified type or types. Throws
|
|
603
|
-
* an error if the event object is not of the specified types.
|
|
604
|
-
*
|
|
605
|
-
* @example
|
|
606
|
-
*
|
|
607
|
-
* ```ts
|
|
608
|
-
* // ...
|
|
609
|
-
* entry: ({ event }) => {
|
|
610
|
-
* assertEvent(event, 'doNothing');
|
|
611
|
-
* // event is { type: 'doNothing' }
|
|
612
|
-
* },
|
|
613
|
-
* // ...
|
|
614
|
-
* exit: ({ event }) => {
|
|
615
|
-
* assertEvent(event, 'greet');
|
|
616
|
-
* // event is { type: 'greet'; message: string }
|
|
617
|
-
*
|
|
618
|
-
* assertEvent(event, ['greet', 'notify']);
|
|
619
|
-
* // event is { type: 'greet'; message: string }
|
|
620
|
-
* // or { type: 'notify'; message: string; level: 'info' | 'error' }
|
|
621
|
-
* },
|
|
622
|
-
* ```
|
|
623
|
-
*/
|
|
624
|
-
function assertEvent(event, type) {
|
|
625
|
-
const types = guards_dist_xstateGuards.toArray(type);
|
|
626
|
-
if (!types.includes(event.type)) {
|
|
627
|
-
const typesText = types.length === 1 ? `type "${types[0]}"` : `one of types "${types.join('", "')}"`;
|
|
628
|
-
throw new Error(`Expected event ${JSON.stringify(event)} to have ${typesText}`);
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
|
|
632
566
|
// this is not 100% accurate since we can't make parallel regions required in the result
|
|
633
567
|
// `TTestValue` doesn't encode this information anyhow for us to be able to do that
|
|
634
568
|
// this is fine for most practical use cases anyway though
|
|
569
|
+
|
|
635
570
|
/**
|
|
636
571
|
* Creates a state machine (statechart) with the given configuration.
|
|
637
572
|
*
|
|
@@ -738,6 +673,7 @@ function getNextSnapshot(actorLogic, snapshot, event) {
|
|
|
738
673
|
|
|
739
674
|
// at the moment we allow extra actors - ones that are not specified by `children`
|
|
740
675
|
// this could be reconsidered in the future
|
|
676
|
+
|
|
741
677
|
function setup({
|
|
742
678
|
schemas,
|
|
743
679
|
actors,
|
|
@@ -758,6 +694,72 @@ function setup({
|
|
|
758
694
|
};
|
|
759
695
|
}
|
|
760
696
|
|
|
697
|
+
class SimulatedClock {
|
|
698
|
+
constructor() {
|
|
699
|
+
this.timeouts = new Map();
|
|
700
|
+
this._now = 0;
|
|
701
|
+
this._id = 0;
|
|
702
|
+
this._flushing = false;
|
|
703
|
+
this._flushingInvalidated = false;
|
|
704
|
+
}
|
|
705
|
+
now() {
|
|
706
|
+
return this._now;
|
|
707
|
+
}
|
|
708
|
+
getId() {
|
|
709
|
+
return this._id++;
|
|
710
|
+
}
|
|
711
|
+
setTimeout(fn, timeout) {
|
|
712
|
+
this._flushingInvalidated = this._flushing;
|
|
713
|
+
const id = this.getId();
|
|
714
|
+
this.timeouts.set(id, {
|
|
715
|
+
start: this.now(),
|
|
716
|
+
timeout,
|
|
717
|
+
fn
|
|
718
|
+
});
|
|
719
|
+
return id;
|
|
720
|
+
}
|
|
721
|
+
clearTimeout(id) {
|
|
722
|
+
this._flushingInvalidated = this._flushing;
|
|
723
|
+
this.timeouts.delete(id);
|
|
724
|
+
}
|
|
725
|
+
set(time) {
|
|
726
|
+
if (this._now > time) {
|
|
727
|
+
throw new Error('Unable to travel back in time');
|
|
728
|
+
}
|
|
729
|
+
this._now = time;
|
|
730
|
+
this.flushTimeouts();
|
|
731
|
+
}
|
|
732
|
+
flushTimeouts() {
|
|
733
|
+
if (this._flushing) {
|
|
734
|
+
this._flushingInvalidated = true;
|
|
735
|
+
return;
|
|
736
|
+
}
|
|
737
|
+
this._flushing = true;
|
|
738
|
+
const sorted = [...this.timeouts].sort(([_idA, timeoutA], [_idB, timeoutB]) => {
|
|
739
|
+
const endA = timeoutA.start + timeoutA.timeout;
|
|
740
|
+
const endB = timeoutB.start + timeoutB.timeout;
|
|
741
|
+
return endB > endA ? -1 : 1;
|
|
742
|
+
});
|
|
743
|
+
for (const [id, timeout] of sorted) {
|
|
744
|
+
if (this._flushingInvalidated) {
|
|
745
|
+
this._flushingInvalidated = false;
|
|
746
|
+
this._flushing = false;
|
|
747
|
+
this.flushTimeouts();
|
|
748
|
+
return;
|
|
749
|
+
}
|
|
750
|
+
if (this.now() - timeout.start >= timeout.timeout) {
|
|
751
|
+
this.timeouts.delete(id);
|
|
752
|
+
timeout.fn.call(null);
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
this._flushing = false;
|
|
756
|
+
}
|
|
757
|
+
increment(ms) {
|
|
758
|
+
this._now += ms;
|
|
759
|
+
this.flushTimeouts();
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
|
|
761
763
|
/**
|
|
762
764
|
* Returns a promise that resolves to the `output` of the actor when it is done.
|
|
763
765
|
*
|
|
@@ -889,6 +891,12 @@ function waitFor(actorRef, predicate, options) {
|
|
|
889
891
|
});
|
|
890
892
|
}
|
|
891
893
|
|
|
894
|
+
exports.createEmptyActor = actors_dist_xstateActors.createEmptyActor;
|
|
895
|
+
exports.fromCallback = actors_dist_xstateActors.fromCallback;
|
|
896
|
+
exports.fromEventObservable = actors_dist_xstateActors.fromEventObservable;
|
|
897
|
+
exports.fromObservable = actors_dist_xstateActors.fromObservable;
|
|
898
|
+
exports.fromPromise = actors_dist_xstateActors.fromPromise;
|
|
899
|
+
exports.fromTransition = actors_dist_xstateActors.fromTransition;
|
|
892
900
|
exports.Actor = guards_dist_xstateGuards.Actor;
|
|
893
901
|
exports.__unsafe_getAllOwnEventDescriptors = guards_dist_xstateGuards.getAllOwnEventDescriptors;
|
|
894
902
|
exports.and = guards_dist_xstateGuards.and;
|
|
@@ -915,12 +923,6 @@ exports.forwardTo = log.forwardTo;
|
|
|
915
923
|
exports.log = log.log;
|
|
916
924
|
exports.sendParent = log.sendParent;
|
|
917
925
|
exports.sendTo = log.sendTo;
|
|
918
|
-
exports.createEmptyActor = actors_dist_xstateActors.createEmptyActor;
|
|
919
|
-
exports.fromCallback = actors_dist_xstateActors.fromCallback;
|
|
920
|
-
exports.fromEventObservable = actors_dist_xstateActors.fromEventObservable;
|
|
921
|
-
exports.fromObservable = actors_dist_xstateActors.fromObservable;
|
|
922
|
-
exports.fromPromise = actors_dist_xstateActors.fromPromise;
|
|
923
|
-
exports.fromTransition = actors_dist_xstateActors.fromTransition;
|
|
924
926
|
exports.SimulatedClock = SimulatedClock;
|
|
925
927
|
exports.StateMachine = StateMachine;
|
|
926
928
|
exports.StateNode = StateNode;
|
|
@@ -2,74 +2,39 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var guards_dist_xstateGuards = require('./State-a2464a1e.development.cjs.js');
|
|
6
|
-
var log = require('./log-40d606d3.development.cjs.js');
|
|
7
5
|
var actors_dist_xstateActors = require('../actors/dist/xstate-actors.development.cjs.js');
|
|
6
|
+
var guards_dist_xstateGuards = require('./raise-e919c5d4.development.cjs.js');
|
|
7
|
+
var log = require('./log-b7ed1b61.development.cjs.js');
|
|
8
8
|
require('../dev/dist/xstate-dev.development.cjs.js');
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
set(time) {
|
|
39
|
-
if (this._now > time) {
|
|
40
|
-
throw new Error('Unable to travel back in time');
|
|
41
|
-
}
|
|
42
|
-
this._now = time;
|
|
43
|
-
this.flushTimeouts();
|
|
44
|
-
}
|
|
45
|
-
flushTimeouts() {
|
|
46
|
-
if (this._flushing) {
|
|
47
|
-
this._flushingInvalidated = true;
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
this._flushing = true;
|
|
51
|
-
const sorted = [...this.timeouts].sort(([_idA, timeoutA], [_idB, timeoutB]) => {
|
|
52
|
-
const endA = timeoutA.start + timeoutA.timeout;
|
|
53
|
-
const endB = timeoutB.start + timeoutB.timeout;
|
|
54
|
-
return endB > endA ? -1 : 1;
|
|
55
|
-
});
|
|
56
|
-
for (const [id, timeout] of sorted) {
|
|
57
|
-
if (this._flushingInvalidated) {
|
|
58
|
-
this._flushingInvalidated = false;
|
|
59
|
-
this._flushing = false;
|
|
60
|
-
this.flushTimeouts();
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
if (this.now() - timeout.start >= timeout.timeout) {
|
|
64
|
-
this.timeouts.delete(id);
|
|
65
|
-
timeout.fn.call(null);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
this._flushing = false;
|
|
69
|
-
}
|
|
70
|
-
increment(ms) {
|
|
71
|
-
this._now += ms;
|
|
72
|
-
this.flushTimeouts();
|
|
10
|
+
/**
|
|
11
|
+
* Asserts that the given event object is of the specified type or types. Throws
|
|
12
|
+
* an error if the event object is not of the specified types.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* // ...
|
|
18
|
+
* entry: ({ event }) => {
|
|
19
|
+
* assertEvent(event, 'doNothing');
|
|
20
|
+
* // event is { type: 'doNothing' }
|
|
21
|
+
* },
|
|
22
|
+
* // ...
|
|
23
|
+
* exit: ({ event }) => {
|
|
24
|
+
* assertEvent(event, 'greet');
|
|
25
|
+
* // event is { type: 'greet'; message: string }
|
|
26
|
+
*
|
|
27
|
+
* assertEvent(event, ['greet', 'notify']);
|
|
28
|
+
* // event is { type: 'greet'; message: string }
|
|
29
|
+
* // or { type: 'notify'; message: string; level: 'info' | 'error' }
|
|
30
|
+
* },
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
function assertEvent(event, type) {
|
|
34
|
+
const types = guards_dist_xstateGuards.toArray(type);
|
|
35
|
+
if (!types.includes(event.type)) {
|
|
36
|
+
const typesText = types.length === 1 ? `type "${types[0]}"` : `one of types "${types.join('", "')}"`;
|
|
37
|
+
throw new Error(`Expected event ${JSON.stringify(event)} to have ${typesText}`);
|
|
73
38
|
}
|
|
74
39
|
}
|
|
75
40
|
|
|
@@ -107,7 +72,7 @@ const toSerializableAction = action => {
|
|
|
107
72
|
return action;
|
|
108
73
|
};
|
|
109
74
|
class StateNode {
|
|
110
|
-
constructor(
|
|
75
|
+
constructor(/** The raw config used to create the machine. */
|
|
111
76
|
config, options) {
|
|
112
77
|
this.config = config;
|
|
113
78
|
/**
|
|
@@ -363,7 +328,7 @@ class StateNode {
|
|
|
363
328
|
|
|
364
329
|
const STATE_IDENTIFIER = '#';
|
|
365
330
|
class StateMachine {
|
|
366
|
-
constructor(
|
|
331
|
+
constructor(/** The raw config used to create the machine. */
|
|
367
332
|
config, implementations) {
|
|
368
333
|
this.config = config;
|
|
369
334
|
/** The machine's own version. */
|
|
@@ -601,40 +566,10 @@ class StateMachine {
|
|
|
601
566
|
}
|
|
602
567
|
}
|
|
603
568
|
|
|
604
|
-
/**
|
|
605
|
-
* Asserts that the given event object is of the specified type or types. Throws
|
|
606
|
-
* an error if the event object is not of the specified types.
|
|
607
|
-
*
|
|
608
|
-
* @example
|
|
609
|
-
*
|
|
610
|
-
* ```ts
|
|
611
|
-
* // ...
|
|
612
|
-
* entry: ({ event }) => {
|
|
613
|
-
* assertEvent(event, 'doNothing');
|
|
614
|
-
* // event is { type: 'doNothing' }
|
|
615
|
-
* },
|
|
616
|
-
* // ...
|
|
617
|
-
* exit: ({ event }) => {
|
|
618
|
-
* assertEvent(event, 'greet');
|
|
619
|
-
* // event is { type: 'greet'; message: string }
|
|
620
|
-
*
|
|
621
|
-
* assertEvent(event, ['greet', 'notify']);
|
|
622
|
-
* // event is { type: 'greet'; message: string }
|
|
623
|
-
* // or { type: 'notify'; message: string; level: 'info' | 'error' }
|
|
624
|
-
* },
|
|
625
|
-
* ```
|
|
626
|
-
*/
|
|
627
|
-
function assertEvent(event, type) {
|
|
628
|
-
const types = guards_dist_xstateGuards.toArray(type);
|
|
629
|
-
if (!types.includes(event.type)) {
|
|
630
|
-
const typesText = types.length === 1 ? `type "${types[0]}"` : `one of types "${types.join('", "')}"`;
|
|
631
|
-
throw new Error(`Expected event ${JSON.stringify(event)} to have ${typesText}`);
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
|
|
635
569
|
// this is not 100% accurate since we can't make parallel regions required in the result
|
|
636
570
|
// `TTestValue` doesn't encode this information anyhow for us to be able to do that
|
|
637
571
|
// this is fine for most practical use cases anyway though
|
|
572
|
+
|
|
638
573
|
/**
|
|
639
574
|
* Creates a state machine (statechart) with the given configuration.
|
|
640
575
|
*
|
|
@@ -741,6 +676,7 @@ function getNextSnapshot(actorLogic, snapshot, event) {
|
|
|
741
676
|
|
|
742
677
|
// at the moment we allow extra actors - ones that are not specified by `children`
|
|
743
678
|
// this could be reconsidered in the future
|
|
679
|
+
|
|
744
680
|
function setup({
|
|
745
681
|
schemas,
|
|
746
682
|
actors,
|
|
@@ -761,6 +697,72 @@ function setup({
|
|
|
761
697
|
};
|
|
762
698
|
}
|
|
763
699
|
|
|
700
|
+
class SimulatedClock {
|
|
701
|
+
constructor() {
|
|
702
|
+
this.timeouts = new Map();
|
|
703
|
+
this._now = 0;
|
|
704
|
+
this._id = 0;
|
|
705
|
+
this._flushing = false;
|
|
706
|
+
this._flushingInvalidated = false;
|
|
707
|
+
}
|
|
708
|
+
now() {
|
|
709
|
+
return this._now;
|
|
710
|
+
}
|
|
711
|
+
getId() {
|
|
712
|
+
return this._id++;
|
|
713
|
+
}
|
|
714
|
+
setTimeout(fn, timeout) {
|
|
715
|
+
this._flushingInvalidated = this._flushing;
|
|
716
|
+
const id = this.getId();
|
|
717
|
+
this.timeouts.set(id, {
|
|
718
|
+
start: this.now(),
|
|
719
|
+
timeout,
|
|
720
|
+
fn
|
|
721
|
+
});
|
|
722
|
+
return id;
|
|
723
|
+
}
|
|
724
|
+
clearTimeout(id) {
|
|
725
|
+
this._flushingInvalidated = this._flushing;
|
|
726
|
+
this.timeouts.delete(id);
|
|
727
|
+
}
|
|
728
|
+
set(time) {
|
|
729
|
+
if (this._now > time) {
|
|
730
|
+
throw new Error('Unable to travel back in time');
|
|
731
|
+
}
|
|
732
|
+
this._now = time;
|
|
733
|
+
this.flushTimeouts();
|
|
734
|
+
}
|
|
735
|
+
flushTimeouts() {
|
|
736
|
+
if (this._flushing) {
|
|
737
|
+
this._flushingInvalidated = true;
|
|
738
|
+
return;
|
|
739
|
+
}
|
|
740
|
+
this._flushing = true;
|
|
741
|
+
const sorted = [...this.timeouts].sort(([_idA, timeoutA], [_idB, timeoutB]) => {
|
|
742
|
+
const endA = timeoutA.start + timeoutA.timeout;
|
|
743
|
+
const endB = timeoutB.start + timeoutB.timeout;
|
|
744
|
+
return endB > endA ? -1 : 1;
|
|
745
|
+
});
|
|
746
|
+
for (const [id, timeout] of sorted) {
|
|
747
|
+
if (this._flushingInvalidated) {
|
|
748
|
+
this._flushingInvalidated = false;
|
|
749
|
+
this._flushing = false;
|
|
750
|
+
this.flushTimeouts();
|
|
751
|
+
return;
|
|
752
|
+
}
|
|
753
|
+
if (this.now() - timeout.start >= timeout.timeout) {
|
|
754
|
+
this.timeouts.delete(id);
|
|
755
|
+
timeout.fn.call(null);
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
this._flushing = false;
|
|
759
|
+
}
|
|
760
|
+
increment(ms) {
|
|
761
|
+
this._now += ms;
|
|
762
|
+
this.flushTimeouts();
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
|
|
764
766
|
/**
|
|
765
767
|
* Returns a promise that resolves to the `output` of the actor when it is done.
|
|
766
768
|
*
|
|
@@ -895,6 +897,12 @@ function waitFor(actorRef, predicate, options) {
|
|
|
895
897
|
});
|
|
896
898
|
}
|
|
897
899
|
|
|
900
|
+
exports.createEmptyActor = actors_dist_xstateActors.createEmptyActor;
|
|
901
|
+
exports.fromCallback = actors_dist_xstateActors.fromCallback;
|
|
902
|
+
exports.fromEventObservable = actors_dist_xstateActors.fromEventObservable;
|
|
903
|
+
exports.fromObservable = actors_dist_xstateActors.fromObservable;
|
|
904
|
+
exports.fromPromise = actors_dist_xstateActors.fromPromise;
|
|
905
|
+
exports.fromTransition = actors_dist_xstateActors.fromTransition;
|
|
898
906
|
exports.Actor = guards_dist_xstateGuards.Actor;
|
|
899
907
|
exports.__unsafe_getAllOwnEventDescriptors = guards_dist_xstateGuards.getAllOwnEventDescriptors;
|
|
900
908
|
exports.and = guards_dist_xstateGuards.and;
|
|
@@ -921,12 +929,6 @@ exports.forwardTo = log.forwardTo;
|
|
|
921
929
|
exports.log = log.log;
|
|
922
930
|
exports.sendParent = log.sendParent;
|
|
923
931
|
exports.sendTo = log.sendTo;
|
|
924
|
-
exports.createEmptyActor = actors_dist_xstateActors.createEmptyActor;
|
|
925
|
-
exports.fromCallback = actors_dist_xstateActors.fromCallback;
|
|
926
|
-
exports.fromEventObservable = actors_dist_xstateActors.fromEventObservable;
|
|
927
|
-
exports.fromObservable = actors_dist_xstateActors.fromObservable;
|
|
928
|
-
exports.fromPromise = actors_dist_xstateActors.fromPromise;
|
|
929
|
-
exports.fromTransition = actors_dist_xstateActors.fromTransition;
|
|
930
932
|
exports.SimulatedClock = SimulatedClock;
|
|
931
933
|
exports.StateMachine = StateMachine;
|
|
932
934
|
exports.StateNode = StateNode;
|