xstate 5.13.2 → 5.15.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/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 +289 -79
- package/actors/dist/xstate-actors.development.cjs.js +289 -79
- package/actors/dist/xstate-actors.development.esm.js +289 -79
- package/actors/dist/xstate-actors.esm.js +289 -79
- 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 +21 -25
- package/dist/declarations/src/StateMachine.d.ts +18 -30
- package/dist/declarations/src/StateNode.d.ts +29 -51
- package/dist/declarations/src/actions/assign.d.ts +29 -27
- package/dist/declarations/src/actions/cancel.d.ts +28 -22
- package/dist/declarations/src/actions/emit.d.ts +33 -33
- package/dist/declarations/src/actions/enqueueActions.d.ts +18 -16
- package/dist/declarations/src/actions/log.d.ts +5 -4
- package/dist/declarations/src/actions/send.d.ts +5 -3
- package/dist/declarations/src/actors/callback.d.ts +69 -29
- package/dist/declarations/src/actors/index.d.ts +4 -4
- package/dist/declarations/src/actors/observable.d.ts +74 -29
- package/dist/declarations/src/actors/promise.d.ts +91 -13
- package/dist/declarations/src/actors/transition.d.ts +90 -16
- package/dist/declarations/src/assert.d.ts +21 -20
- package/dist/declarations/src/createActor.d.ts +51 -42
- package/dist/declarations/src/createMachine.d.ts +40 -54
- package/dist/declarations/src/getNextSnapshot.d.ts +27 -24
- package/dist/declarations/src/guards.d.ts +67 -66
- package/dist/declarations/src/index.d.ts +0 -1
- package/dist/declarations/src/inspection.d.ts +1 -0
- package/dist/declarations/src/setup.d.ts +1 -2
- package/dist/declarations/src/spawn.d.ts +2 -5
- package/dist/declarations/src/stateUtils.d.ts +5 -10
- package/dist/declarations/src/system.d.ts +2 -2
- package/dist/declarations/src/toPromise.d.ts +1 -0
- package/dist/declarations/src/types.d.ts +169 -192
- package/dist/declarations/src/waitFor.d.ts +9 -9
- package/dist/{log-c447a931.esm.js → log-63de2429.esm.js} +112 -117
- package/dist/{log-5b14d850.cjs.js → log-b8c93ee3.cjs.js} +112 -117
- package/dist/{log-d06dd00b.development.cjs.js → log-d2c282d6.development.cjs.js} +112 -117
- package/dist/{log-b3b03961.development.esm.js → log-e9953143.development.esm.js} +112 -117
- package/dist/{raise-f406edbd.esm.js → raise-2cfe6b8f.esm.js} +302 -284
- package/dist/{raise-150d5679.development.esm.js → raise-7d030497.development.esm.js} +302 -284
- package/dist/{raise-ff8990f7.cjs.js → raise-a6298350.cjs.js} +302 -284
- package/dist/{raise-bf7a8462.development.cjs.js → raise-bad6a97b.development.cjs.js} +302 -284
- package/dist/xstate.cjs.js +134 -157
- package/dist/xstate.development.cjs.js +134 -157
- package/dist/xstate.development.esm.js +136 -159
- package/dist/xstate.esm.js +136 -159
- 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
- package/dist/declarations/src/typegenTypes.d.ts +0 -168
|
@@ -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 macrostep, o as transitionNode, p as resolveActionsAndContext, q as createInitEvent, s as microstep, u as getInitialStateNodes, v as toStatePath, w as isStateId, x as getStateNodeByPath, y as getPersistedSnapshot, z as resolveReferencedActor, A as createActor, $ as $$ACTOR_TYPE } from './raise-
|
|
3
|
-
export { B as Actor, I as __unsafe_getAllOwnEventDescriptors, E as and, M as cancel, A as createActor, j as getStateNodes, C as interpret, D as isMachineSnapshot, J as matchesState, F as not, G as or, K as pathToStateValue, O as raise, P as spawnChild, H as stateIn, Q as stop, R as stopChild, L as toObserver } from './raise-
|
|
4
|
-
import { a as assign } from './log-
|
|
5
|
-
export { S as SpecialTargets, a as assign, e as emit, b as enqueueActions, f as forwardTo, l as log, s as sendParent, c as sendTo } from './log-
|
|
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 toStatePath, w as isStateId, x as getStateNodeByPath, y as getPersistedSnapshot, z as resolveReferencedActor, A as createActor, $ as $$ACTOR_TYPE } from './raise-7d030497.development.esm.js';
|
|
3
|
+
export { B as Actor, I as __unsafe_getAllOwnEventDescriptors, E as and, M as cancel, A as createActor, j as getStateNodes, C as interpret, D as isMachineSnapshot, J as matchesState, F as not, G as or, K as pathToStateValue, O as raise, P as spawnChild, H as stateIn, Q as stop, R as stopChild, L as toObserver } from './raise-7d030497.development.esm.js';
|
|
4
|
+
import { a as assign } from './log-e9953143.development.esm.js';
|
|
5
|
+
export { S as SpecialTargets, a as assign, e as emit, b as enqueueActions, f as forwardTo, l as log, s as sendParent, c as sendTo } from './log-e9953143.development.esm.js';
|
|
6
6
|
import '../dev/dist/xstate-dev.development.esm.js';
|
|
7
7
|
|
|
8
8
|
class SimulatedClock {
|
|
@@ -105,71 +105,58 @@ const toSerializableAction = action => {
|
|
|
105
105
|
return action;
|
|
106
106
|
};
|
|
107
107
|
class StateNode {
|
|
108
|
-
constructor(
|
|
109
|
-
/**
|
|
110
|
-
* The raw config used to create the machine.
|
|
111
|
-
*/
|
|
108
|
+
constructor( /** The raw config used to create the machine. */
|
|
112
109
|
config, options) {
|
|
113
110
|
this.config = config;
|
|
114
111
|
/**
|
|
115
|
-
* The relative key of the state node, which represents its location in the
|
|
112
|
+
* The relative key of the state node, which represents its location in the
|
|
113
|
+
* overall state value.
|
|
116
114
|
*/
|
|
117
115
|
this.key = void 0;
|
|
118
|
-
/**
|
|
119
|
-
* The unique ID of the state node.
|
|
120
|
-
*/
|
|
116
|
+
/** The unique ID of the state node. */
|
|
121
117
|
this.id = void 0;
|
|
122
118
|
/**
|
|
123
119
|
* The type of this state node:
|
|
124
120
|
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
121
|
+
* - `'atomic'` - no child state nodes
|
|
122
|
+
* - `'compound'` - nested child state nodes (XOR)
|
|
123
|
+
* - `'parallel'` - orthogonal nested child state nodes (AND)
|
|
124
|
+
* - `'history'` - history state node
|
|
125
|
+
* - `'final'` - final state node
|
|
130
126
|
*/
|
|
131
127
|
this.type = void 0;
|
|
132
|
-
/**
|
|
133
|
-
* The string path from the root machine node to this node.
|
|
134
|
-
*/
|
|
128
|
+
/** The string path from the root machine node to this node. */
|
|
135
129
|
this.path = void 0;
|
|
136
|
-
/**
|
|
137
|
-
* The child state nodes.
|
|
138
|
-
*/
|
|
130
|
+
/** The child state nodes. */
|
|
139
131
|
this.states = void 0;
|
|
140
132
|
/**
|
|
141
133
|
* The type of history on this state node. Can be:
|
|
142
134
|
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
135
|
+
* - `'shallow'` - recalls only top-level historical state value
|
|
136
|
+
* - `'deep'` - recalls historical state value at all levels
|
|
145
137
|
*/
|
|
146
138
|
this.history = void 0;
|
|
147
|
-
/**
|
|
148
|
-
* The action(s) to be executed upon entering the state node.
|
|
149
|
-
*/
|
|
139
|
+
/** The action(s) to be executed upon entering the state node. */
|
|
150
140
|
this.entry = void 0;
|
|
151
|
-
/**
|
|
152
|
-
* The action(s) to be executed upon exiting the state node.
|
|
153
|
-
*/
|
|
141
|
+
/** The action(s) to be executed upon exiting the state node. */
|
|
154
142
|
this.exit = void 0;
|
|
155
|
-
/**
|
|
156
|
-
* The parent state node.
|
|
157
|
-
*/
|
|
143
|
+
/** The parent state node. */
|
|
158
144
|
this.parent = void 0;
|
|
159
|
-
/**
|
|
160
|
-
* The root machine node.
|
|
161
|
-
*/
|
|
145
|
+
/** The root machine node. */
|
|
162
146
|
this.machine = void 0;
|
|
163
147
|
/**
|
|
164
|
-
* The meta data associated with this state node, which will be returned in
|
|
148
|
+
* The meta data associated with this state node, which will be returned in
|
|
149
|
+
* State instances.
|
|
165
150
|
*/
|
|
166
151
|
this.meta = void 0;
|
|
167
152
|
/**
|
|
168
|
-
* The output data sent with the "xstate.done.state._id_" event if this is a
|
|
153
|
+
* The output data sent with the "xstate.done.state._id_" event if this is a
|
|
154
|
+
* final state node.
|
|
169
155
|
*/
|
|
170
156
|
this.output = void 0;
|
|
171
157
|
/**
|
|
172
|
-
* The order this state node appears. Corresponds to the implicit document
|
|
158
|
+
* The order this state node appears. Corresponds to the implicit document
|
|
159
|
+
* order.
|
|
173
160
|
*/
|
|
174
161
|
this.order = -1;
|
|
175
162
|
this.description = void 0;
|
|
@@ -217,9 +204,7 @@ class StateNode {
|
|
|
217
204
|
});
|
|
218
205
|
}
|
|
219
206
|
|
|
220
|
-
/**
|
|
221
|
-
* The well-structured state node definition.
|
|
222
|
-
*/
|
|
207
|
+
/** The well-structured state node definition. */
|
|
223
208
|
get definition() {
|
|
224
209
|
return {
|
|
225
210
|
id: this.id,
|
|
@@ -264,9 +249,7 @@ class StateNode {
|
|
|
264
249
|
return this.definition;
|
|
265
250
|
}
|
|
266
251
|
|
|
267
|
-
/**
|
|
268
|
-
* The logic invoked as actors by this state node.
|
|
269
|
-
*/
|
|
252
|
+
/** The logic invoked as actors by this state node. */
|
|
270
253
|
get invoke() {
|
|
271
254
|
return memo(this, 'invoke', () => toArray(this.config.invoke).map((invokeConfig, i) => {
|
|
272
255
|
const {
|
|
@@ -297,9 +280,7 @@ class StateNode {
|
|
|
297
280
|
}));
|
|
298
281
|
}
|
|
299
282
|
|
|
300
|
-
/**
|
|
301
|
-
* The mapping of events to transitions.
|
|
302
|
-
*/
|
|
283
|
+
/** The mapping of events to transitions. */
|
|
303
284
|
get on() {
|
|
304
285
|
return memo(this, 'on', () => {
|
|
305
286
|
const transitions = this.transitions;
|
|
@@ -344,9 +325,7 @@ class StateNode {
|
|
|
344
325
|
return selectedTransition ? [selectedTransition] : undefined;
|
|
345
326
|
}
|
|
346
327
|
|
|
347
|
-
/**
|
|
348
|
-
* All the event types accepted by this state node and its descendants.
|
|
349
|
-
*/
|
|
328
|
+
/** All the event types accepted by this state node and its descendants. */
|
|
350
329
|
get events() {
|
|
351
330
|
return memo(this, 'events', () => {
|
|
352
331
|
const {
|
|
@@ -382,15 +361,10 @@ class StateNode {
|
|
|
382
361
|
|
|
383
362
|
const STATE_IDENTIFIER = '#';
|
|
384
363
|
class StateMachine {
|
|
385
|
-
constructor(
|
|
386
|
-
/**
|
|
387
|
-
* The raw config used to create the machine.
|
|
388
|
-
*/
|
|
364
|
+
constructor( /** The raw config used to create the machine. */
|
|
389
365
|
config, implementations) {
|
|
390
366
|
this.config = config;
|
|
391
|
-
/**
|
|
392
|
-
* The machine's own version.
|
|
393
|
-
*/
|
|
367
|
+
/** The machine's own version. */
|
|
394
368
|
this.version = void 0;
|
|
395
369
|
this.schemas = void 0;
|
|
396
370
|
this.implementations = void 0;
|
|
@@ -402,10 +376,6 @@ class StateMachine {
|
|
|
402
376
|
this.id = void 0;
|
|
403
377
|
this.states = void 0;
|
|
404
378
|
this.events = void 0;
|
|
405
|
-
/**
|
|
406
|
-
* @deprecated an internal property that was acting as a "phantom" type, it's not used by anything right now but it's kept around for compatibility reasons
|
|
407
|
-
**/
|
|
408
|
-
this.__TResolvedTypesMeta = void 0;
|
|
409
379
|
this.id = config.id || '(machine)';
|
|
410
380
|
this.implementations = {
|
|
411
381
|
actors: implementations?.actors ?? {},
|
|
@@ -433,12 +403,11 @@ class StateMachine {
|
|
|
433
403
|
}
|
|
434
404
|
|
|
435
405
|
/**
|
|
436
|
-
* Clones this state machine with the provided implementations
|
|
437
|
-
*
|
|
438
|
-
*
|
|
439
|
-
* @param implementations Options (`actions`, `guards`, `actors`, `delays`, `context`)
|
|
440
|
-
* to recursively merge with the existing options.
|
|
406
|
+
* Clones this state machine with the provided implementations and merges the
|
|
407
|
+
* `context` (if provided).
|
|
441
408
|
*
|
|
409
|
+
* @param implementations Options (`actions`, `guards`, `actors`, `delays`,
|
|
410
|
+
* `context`) to recursively merge with the existing options.
|
|
442
411
|
* @returns A new `StateMachine` instance with the provided implementations.
|
|
443
412
|
*/
|
|
444
413
|
provide(implementations) {
|
|
@@ -482,8 +451,8 @@ class StateMachine {
|
|
|
482
451
|
}
|
|
483
452
|
|
|
484
453
|
/**
|
|
485
|
-
* Determines the next snapshot given the current `snapshot` and received
|
|
486
|
-
* Calculates a full macrostep from all microsteps.
|
|
454
|
+
* Determines the next snapshot given the current `snapshot` and received
|
|
455
|
+
* `event`. Calculates a full macrostep from all microsteps.
|
|
487
456
|
*
|
|
488
457
|
* @param snapshot The current snapshot
|
|
489
458
|
* @param event The received event
|
|
@@ -493,8 +462,8 @@ class StateMachine {
|
|
|
493
462
|
}
|
|
494
463
|
|
|
495
464
|
/**
|
|
496
|
-
* Determines the next state given the current `state` and `event`.
|
|
497
|
-
*
|
|
465
|
+
* Determines the next state given the current `state` and `event`. Calculates
|
|
466
|
+
* a microstep.
|
|
498
467
|
*
|
|
499
468
|
* @param state The current state
|
|
500
469
|
* @param event The received event
|
|
@@ -507,8 +476,8 @@ class StateMachine {
|
|
|
507
476
|
}
|
|
508
477
|
|
|
509
478
|
/**
|
|
510
|
-
* The initial state _before_ evaluating any microsteps.
|
|
511
|
-
*
|
|
479
|
+
* The initial state _before_ evaluating any microsteps. This "pre-initial"
|
|
480
|
+
* state is provided to initial actions executed in the initial state.
|
|
512
481
|
*/
|
|
513
482
|
getPreInitialState(actorScope, initEvent, internalQueue) {
|
|
514
483
|
const {
|
|
@@ -536,7 +505,8 @@ class StateMachine {
|
|
|
536
505
|
}
|
|
537
506
|
|
|
538
507
|
/**
|
|
539
|
-
* Returns the initial `State` instance, with reference to `self` as an
|
|
508
|
+
* Returns the initial `State` instance, with reference to `self` as an
|
|
509
|
+
* `ActorRef`.
|
|
540
510
|
*/
|
|
541
511
|
getInitialSnapshot(actorScope, input) {
|
|
542
512
|
const initEvent = createInitEvent(input); // TODO: fix;
|
|
@@ -634,14 +604,14 @@ const defaultWaitForOptions = {
|
|
|
634
604
|
};
|
|
635
605
|
|
|
636
606
|
/**
|
|
637
|
-
* Subscribes to an actor ref and waits for its emitted value to satisfy
|
|
638
|
-
*
|
|
639
|
-
*
|
|
640
|
-
* (defaults to Infinity).
|
|
607
|
+
* Subscribes to an actor ref and waits for its emitted value to satisfy a
|
|
608
|
+
* predicate, and then resolves with that value. Will throw if the desired state
|
|
609
|
+
* is not reached after an optional timeout. (defaults to Infinity).
|
|
641
610
|
*
|
|
642
611
|
* @example
|
|
612
|
+
*
|
|
643
613
|
* ```js
|
|
644
|
-
* const state = await waitFor(someService, state => {
|
|
614
|
+
* const state = await waitFor(someService, (state) => {
|
|
645
615
|
* return state.hasTag('loaded');
|
|
646
616
|
* });
|
|
647
617
|
*
|
|
@@ -651,8 +621,8 @@ const defaultWaitForOptions = {
|
|
|
651
621
|
* @param actorRef The actor ref to subscribe to
|
|
652
622
|
* @param predicate Determines if a value matches the condition to wait for
|
|
653
623
|
* @param options
|
|
654
|
-
* @returns A promise that eventually resolves to the emitted value
|
|
655
|
-
*
|
|
624
|
+
* @returns A promise that eventually resolves to the emitted value that matches
|
|
625
|
+
* the condition
|
|
656
626
|
*/
|
|
657
627
|
function waitFor(actorRef, predicate, options) {
|
|
658
628
|
const resolvedOptions = {
|
|
@@ -711,40 +681,42 @@ function waitFor(actorRef, predicate, options) {
|
|
|
711
681
|
*
|
|
712
682
|
* The state machine represents the pure logic of a state machine actor.
|
|
713
683
|
*
|
|
714
|
-
* @param config The state machine configuration.
|
|
715
|
-
* @param options DEPRECATED: use `setup({ ... })` or `machine.provide({ ... })` to provide machine implementations instead.
|
|
716
|
-
*
|
|
717
684
|
* @example
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
685
|
+
*
|
|
686
|
+
* ```ts
|
|
687
|
+
* import { createMachine } from 'xstate';
|
|
688
|
+
*
|
|
689
|
+
* const lightMachine = createMachine({
|
|
690
|
+
* id: 'light',
|
|
691
|
+
* initial: 'green',
|
|
692
|
+
* states: {
|
|
693
|
+
* green: {
|
|
694
|
+
* on: {
|
|
695
|
+
* TIMER: { target: 'yellow' }
|
|
696
|
+
* }
|
|
697
|
+
* },
|
|
698
|
+
* yellow: {
|
|
699
|
+
* on: {
|
|
700
|
+
* TIMER: { target: 'red' }
|
|
701
|
+
* }
|
|
702
|
+
* },
|
|
703
|
+
* red: {
|
|
704
|
+
* on: {
|
|
705
|
+
* TIMER: { target: 'green' }
|
|
706
|
+
* }
|
|
707
|
+
* }
|
|
708
|
+
* }
|
|
709
|
+
* });
|
|
710
|
+
*
|
|
711
|
+
* const lightActor = createActor(lightMachine);
|
|
712
|
+
* lightActor.start();
|
|
713
|
+
*
|
|
714
|
+
* lightActor.send({ type: 'TIMER' });
|
|
715
|
+
* ```
|
|
716
|
+
*
|
|
717
|
+
* @param config The state machine configuration.
|
|
718
|
+
* @param options DEPRECATED: use `setup({ ... })` or `machine.provide({ ... })`
|
|
719
|
+
* to provide machine implementations instead.
|
|
748
720
|
*/
|
|
749
721
|
function createMachine(config, implementations) {
|
|
750
722
|
return new StateMachine(config, implementations);
|
|
@@ -771,33 +743,36 @@ function getInitialSnapshot(actorLogic, ...[input]) {
|
|
|
771
743
|
}
|
|
772
744
|
|
|
773
745
|
/**
|
|
774
|
-
* Determines the next snapshot for the given `actorLogic` based on
|
|
775
|
-
*
|
|
746
|
+
* Determines the next snapshot for the given `actorLogic` based on the given
|
|
747
|
+
* `snapshot` and `event`.
|
|
776
748
|
*
|
|
777
|
-
* If the `snapshot` is `undefined`, the initial snapshot of the
|
|
778
|
-
*
|
|
749
|
+
* If the `snapshot` is `undefined`, the initial snapshot of the `actorLogic` is
|
|
750
|
+
* used.
|
|
779
751
|
*
|
|
780
752
|
* @example
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
753
|
+
*
|
|
754
|
+
* ```ts
|
|
755
|
+
* import { getNextSnapshot } from 'xstate';
|
|
756
|
+
* import { trafficLightMachine } from './trafficLightMachine.ts';
|
|
757
|
+
*
|
|
758
|
+
* const nextSnapshot = getNextSnapshot(
|
|
759
|
+
* trafficLightMachine, // actor logic
|
|
760
|
+
* undefined, // snapshot (or initial state if undefined)
|
|
761
|
+
* { type: 'TIMER' }
|
|
762
|
+
* ); // event object
|
|
763
|
+
*
|
|
764
|
+
* console.log(nextSnapshot.value);
|
|
765
|
+
* // => 'yellow'
|
|
766
|
+
*
|
|
767
|
+
* const nextSnapshot2 = getNextSnapshot(
|
|
768
|
+
* trafficLightMachine, // actor logic
|
|
769
|
+
* nextSnapshot, // snapshot
|
|
770
|
+
* { type: 'TIMER' }
|
|
771
|
+
* ); // event object
|
|
772
|
+
*
|
|
773
|
+
* console.log(nextSnapshot2.value);
|
|
774
|
+
* // =>'red'
|
|
775
|
+
* ```
|
|
801
776
|
*/
|
|
802
777
|
function getNextSnapshot(actorLogic, snapshot, event) {
|
|
803
778
|
const inertActorScope = createInertActorScope(actorLogic);
|
|
@@ -831,6 +806,7 @@ function setup({
|
|
|
831
806
|
* Returns a promise that resolves to the `output` of the actor when it is done.
|
|
832
807
|
*
|
|
833
808
|
* @example
|
|
809
|
+
*
|
|
834
810
|
* ```ts
|
|
835
811
|
* const machine = createMachine({
|
|
836
812
|
* // ...
|
|
@@ -861,26 +837,27 @@ function toPromise(actor) {
|
|
|
861
837
|
}
|
|
862
838
|
|
|
863
839
|
/**
|
|
864
|
-
* Asserts that the given event object is of the specified type or types.
|
|
865
|
-
*
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
840
|
+
* Asserts that the given event object is of the specified type or types. Throws
|
|
841
|
+
* an error if the event object is not of the specified types.
|
|
842
|
+
*
|
|
843
|
+
* @example
|
|
844
|
+
*
|
|
845
|
+
* ```ts
|
|
846
|
+
* // ...
|
|
847
|
+
* entry: ({ event }) => {
|
|
848
|
+
* assertEvent(event, 'doNothing');
|
|
849
|
+
* // event is { type: 'doNothing' }
|
|
850
|
+
* },
|
|
851
|
+
* // ...
|
|
852
|
+
* exit: ({ event }) => {
|
|
853
|
+
* assertEvent(event, 'greet');
|
|
854
|
+
* // event is { type: 'greet'; message: string }
|
|
855
|
+
*
|
|
856
|
+
* assertEvent(event, ['greet', 'notify']);
|
|
857
|
+
* // event is { type: 'greet'; message: string }
|
|
858
|
+
* // or { type: 'notify'; message: string; level: 'info' | 'error' }
|
|
859
|
+
* },
|
|
860
|
+
* ```
|
|
884
861
|
*/
|
|
885
862
|
function assertEvent(event, type) {
|
|
886
863
|
const types = toArray(type);
|