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
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 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-2cfe6b8f.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-2cfe6b8f.esm.js';
|
|
4
|
+
import { a as assign } from './log-63de2429.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-63de2429.esm.js';
|
|
6
6
|
import '../dev/dist/xstate-dev.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 ?? {},
|
|
@@ -430,12 +400,11 @@ class StateMachine {
|
|
|
430
400
|
}
|
|
431
401
|
|
|
432
402
|
/**
|
|
433
|
-
* Clones this state machine with the provided implementations
|
|
434
|
-
*
|
|
435
|
-
*
|
|
436
|
-
* @param implementations Options (`actions`, `guards`, `actors`, `delays`, `context`)
|
|
437
|
-
* to recursively merge with the existing options.
|
|
403
|
+
* Clones this state machine with the provided implementations and merges the
|
|
404
|
+
* `context` (if provided).
|
|
438
405
|
*
|
|
406
|
+
* @param implementations Options (`actions`, `guards`, `actors`, `delays`,
|
|
407
|
+
* `context`) to recursively merge with the existing options.
|
|
439
408
|
* @returns A new `StateMachine` instance with the provided implementations.
|
|
440
409
|
*/
|
|
441
410
|
provide(implementations) {
|
|
@@ -479,8 +448,8 @@ class StateMachine {
|
|
|
479
448
|
}
|
|
480
449
|
|
|
481
450
|
/**
|
|
482
|
-
* Determines the next snapshot given the current `snapshot` and received
|
|
483
|
-
* Calculates a full macrostep from all microsteps.
|
|
451
|
+
* Determines the next snapshot given the current `snapshot` and received
|
|
452
|
+
* `event`. Calculates a full macrostep from all microsteps.
|
|
484
453
|
*
|
|
485
454
|
* @param snapshot The current snapshot
|
|
486
455
|
* @param event The received event
|
|
@@ -490,8 +459,8 @@ class StateMachine {
|
|
|
490
459
|
}
|
|
491
460
|
|
|
492
461
|
/**
|
|
493
|
-
* Determines the next state given the current `state` and `event`.
|
|
494
|
-
*
|
|
462
|
+
* Determines the next state given the current `state` and `event`. Calculates
|
|
463
|
+
* a microstep.
|
|
495
464
|
*
|
|
496
465
|
* @param state The current state
|
|
497
466
|
* @param event The received event
|
|
@@ -504,8 +473,8 @@ class StateMachine {
|
|
|
504
473
|
}
|
|
505
474
|
|
|
506
475
|
/**
|
|
507
|
-
* The initial state _before_ evaluating any microsteps.
|
|
508
|
-
*
|
|
476
|
+
* The initial state _before_ evaluating any microsteps. This "pre-initial"
|
|
477
|
+
* state is provided to initial actions executed in the initial state.
|
|
509
478
|
*/
|
|
510
479
|
getPreInitialState(actorScope, initEvent, internalQueue) {
|
|
511
480
|
const {
|
|
@@ -533,7 +502,8 @@ class StateMachine {
|
|
|
533
502
|
}
|
|
534
503
|
|
|
535
504
|
/**
|
|
536
|
-
* Returns the initial `State` instance, with reference to `self` as an
|
|
505
|
+
* Returns the initial `State` instance, with reference to `self` as an
|
|
506
|
+
* `ActorRef`.
|
|
537
507
|
*/
|
|
538
508
|
getInitialSnapshot(actorScope, input) {
|
|
539
509
|
const initEvent = createInitEvent(input); // TODO: fix;
|
|
@@ -631,14 +601,14 @@ const defaultWaitForOptions = {
|
|
|
631
601
|
};
|
|
632
602
|
|
|
633
603
|
/**
|
|
634
|
-
* Subscribes to an actor ref and waits for its emitted value to satisfy
|
|
635
|
-
*
|
|
636
|
-
*
|
|
637
|
-
* (defaults to Infinity).
|
|
604
|
+
* Subscribes to an actor ref and waits for its emitted value to satisfy a
|
|
605
|
+
* predicate, and then resolves with that value. Will throw if the desired state
|
|
606
|
+
* is not reached after an optional timeout. (defaults to Infinity).
|
|
638
607
|
*
|
|
639
608
|
* @example
|
|
609
|
+
*
|
|
640
610
|
* ```js
|
|
641
|
-
* const state = await waitFor(someService, state => {
|
|
611
|
+
* const state = await waitFor(someService, (state) => {
|
|
642
612
|
* return state.hasTag('loaded');
|
|
643
613
|
* });
|
|
644
614
|
*
|
|
@@ -648,8 +618,8 @@ const defaultWaitForOptions = {
|
|
|
648
618
|
* @param actorRef The actor ref to subscribe to
|
|
649
619
|
* @param predicate Determines if a value matches the condition to wait for
|
|
650
620
|
* @param options
|
|
651
|
-
* @returns A promise that eventually resolves to the emitted value
|
|
652
|
-
*
|
|
621
|
+
* @returns A promise that eventually resolves to the emitted value that matches
|
|
622
|
+
* the condition
|
|
653
623
|
*/
|
|
654
624
|
function waitFor(actorRef, predicate, options) {
|
|
655
625
|
const resolvedOptions = {
|
|
@@ -705,40 +675,42 @@ function waitFor(actorRef, predicate, options) {
|
|
|
705
675
|
*
|
|
706
676
|
* The state machine represents the pure logic of a state machine actor.
|
|
707
677
|
*
|
|
708
|
-
* @param config The state machine configuration.
|
|
709
|
-
* @param options DEPRECATED: use `setup({ ... })` or `machine.provide({ ... })` to provide machine implementations instead.
|
|
710
|
-
*
|
|
711
678
|
* @example
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
679
|
+
*
|
|
680
|
+
* ```ts
|
|
681
|
+
* import { createMachine } from 'xstate';
|
|
682
|
+
*
|
|
683
|
+
* const lightMachine = createMachine({
|
|
684
|
+
* id: 'light',
|
|
685
|
+
* initial: 'green',
|
|
686
|
+
* states: {
|
|
687
|
+
* green: {
|
|
688
|
+
* on: {
|
|
689
|
+
* TIMER: { target: 'yellow' }
|
|
690
|
+
* }
|
|
691
|
+
* },
|
|
692
|
+
* yellow: {
|
|
693
|
+
* on: {
|
|
694
|
+
* TIMER: { target: 'red' }
|
|
695
|
+
* }
|
|
696
|
+
* },
|
|
697
|
+
* red: {
|
|
698
|
+
* on: {
|
|
699
|
+
* TIMER: { target: 'green' }
|
|
700
|
+
* }
|
|
701
|
+
* }
|
|
702
|
+
* }
|
|
703
|
+
* });
|
|
704
|
+
*
|
|
705
|
+
* const lightActor = createActor(lightMachine);
|
|
706
|
+
* lightActor.start();
|
|
707
|
+
*
|
|
708
|
+
* lightActor.send({ type: 'TIMER' });
|
|
709
|
+
* ```
|
|
710
|
+
*
|
|
711
|
+
* @param config The state machine configuration.
|
|
712
|
+
* @param options DEPRECATED: use `setup({ ... })` or `machine.provide({ ... })`
|
|
713
|
+
* to provide machine implementations instead.
|
|
742
714
|
*/
|
|
743
715
|
function createMachine(config, implementations) {
|
|
744
716
|
return new StateMachine(config, implementations);
|
|
@@ -765,33 +737,36 @@ function getInitialSnapshot(actorLogic, ...[input]) {
|
|
|
765
737
|
}
|
|
766
738
|
|
|
767
739
|
/**
|
|
768
|
-
* Determines the next snapshot for the given `actorLogic` based on
|
|
769
|
-
*
|
|
740
|
+
* Determines the next snapshot for the given `actorLogic` based on the given
|
|
741
|
+
* `snapshot` and `event`.
|
|
770
742
|
*
|
|
771
|
-
* If the `snapshot` is `undefined`, the initial snapshot of the
|
|
772
|
-
*
|
|
743
|
+
* If the `snapshot` is `undefined`, the initial snapshot of the `actorLogic` is
|
|
744
|
+
* used.
|
|
773
745
|
*
|
|
774
746
|
* @example
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
747
|
+
*
|
|
748
|
+
* ```ts
|
|
749
|
+
* import { getNextSnapshot } from 'xstate';
|
|
750
|
+
* import { trafficLightMachine } from './trafficLightMachine.ts';
|
|
751
|
+
*
|
|
752
|
+
* const nextSnapshot = getNextSnapshot(
|
|
753
|
+
* trafficLightMachine, // actor logic
|
|
754
|
+
* undefined, // snapshot (or initial state if undefined)
|
|
755
|
+
* { type: 'TIMER' }
|
|
756
|
+
* ); // event object
|
|
757
|
+
*
|
|
758
|
+
* console.log(nextSnapshot.value);
|
|
759
|
+
* // => 'yellow'
|
|
760
|
+
*
|
|
761
|
+
* const nextSnapshot2 = getNextSnapshot(
|
|
762
|
+
* trafficLightMachine, // actor logic
|
|
763
|
+
* nextSnapshot, // snapshot
|
|
764
|
+
* { type: 'TIMER' }
|
|
765
|
+
* ); // event object
|
|
766
|
+
*
|
|
767
|
+
* console.log(nextSnapshot2.value);
|
|
768
|
+
* // =>'red'
|
|
769
|
+
* ```
|
|
795
770
|
*/
|
|
796
771
|
function getNextSnapshot(actorLogic, snapshot, event) {
|
|
797
772
|
const inertActorScope = createInertActorScope(actorLogic);
|
|
@@ -825,6 +800,7 @@ function setup({
|
|
|
825
800
|
* Returns a promise that resolves to the `output` of the actor when it is done.
|
|
826
801
|
*
|
|
827
802
|
* @example
|
|
803
|
+
*
|
|
828
804
|
* ```ts
|
|
829
805
|
* const machine = createMachine({
|
|
830
806
|
* // ...
|
|
@@ -855,26 +831,27 @@ function toPromise(actor) {
|
|
|
855
831
|
}
|
|
856
832
|
|
|
857
833
|
/**
|
|
858
|
-
* Asserts that the given event object is of the specified type or types.
|
|
859
|
-
*
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
834
|
+
* Asserts that the given event object is of the specified type or types. Throws
|
|
835
|
+
* an error if the event object is not of the specified types.
|
|
836
|
+
*
|
|
837
|
+
* @example
|
|
838
|
+
*
|
|
839
|
+
* ```ts
|
|
840
|
+
* // ...
|
|
841
|
+
* entry: ({ event }) => {
|
|
842
|
+
* assertEvent(event, 'doNothing');
|
|
843
|
+
* // event is { type: 'doNothing' }
|
|
844
|
+
* },
|
|
845
|
+
* // ...
|
|
846
|
+
* exit: ({ event }) => {
|
|
847
|
+
* assertEvent(event, 'greet');
|
|
848
|
+
* // event is { type: 'greet'; message: string }
|
|
849
|
+
*
|
|
850
|
+
* assertEvent(event, ['greet', 'notify']);
|
|
851
|
+
* // event is { type: 'greet'; message: string }
|
|
852
|
+
* // or { type: 'notify'; message: string; level: 'info' | 'error' }
|
|
853
|
+
* },
|
|
854
|
+
* ```
|
|
878
855
|
*/
|
|
879
856
|
function assertEvent(event, type) {
|
|
880
857
|
const types = toArray(type);
|