xstate 6.0.0-alpha.1 → 6.0.0-alpha.11
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/README.md +18 -16
- package/dist/{StateMachine-6ec50e21.development.esm.js → StateMachine-0aa98f54.development.esm.js} +29 -20
- package/dist/{StateMachine-48dcad8f.cjs.js → StateMachine-aef700df.cjs.js} +28 -19
- package/dist/{StateMachine-47e60715.esm.js → StateMachine-d4931336.esm.js} +28 -19
- package/dist/{StateMachine-6e063ac1.development.cjs.js → StateMachine-da872dde.development.cjs.js} +29 -20
- package/dist/declarations/src/StateMachine.d.ts +21 -13
- package/dist/declarations/src/actions.d.ts +1 -1
- package/dist/declarations/src/createActor.d.ts +4 -3
- package/dist/declarations/src/createMachine.d.ts +14 -11
- package/dist/declarations/src/createMachineFromConfig.d.ts +4 -3
- package/dist/declarations/src/graph/graph.d.ts +3 -3
- package/dist/declarations/src/graph/shortestPaths.d.ts +2 -2
- package/dist/declarations/src/graph/simplePaths.d.ts +2 -2
- package/dist/declarations/src/index.d.ts +5 -5
- package/dist/declarations/src/serialize.d.ts +15 -9
- package/dist/declarations/src/setup.d.ts +189 -45
- package/dist/declarations/src/spawn.d.ts +3 -3
- package/dist/declarations/src/stateUtils.d.ts +1 -0
- package/dist/declarations/src/system.d.ts +1 -1
- package/dist/declarations/src/transition.d.ts +8 -5
- package/dist/declarations/src/transitionActions.d.ts +4 -0
- package/dist/declarations/src/types.d.ts +137 -72
- package/dist/declarations/src/types.v6.d.ts +95 -49
- package/dist/declarations/src/utils.d.ts +2 -1
- package/dist/{index-c35824b4.development.cjs.js → index-219cb621.development.cjs.js} +333 -864
- package/dist/{index-39259ea4.development.esm.js → index-2f2fbd9b.development.esm.js} +332 -859
- package/dist/{index-f0d7107d.cjs.js → index-559ceab3.cjs.js} +333 -864
- package/dist/{index-688701ed.esm.js → index-8828376f.esm.js} +332 -859
- package/dist/xstate-actors.cjs.js +1 -1
- package/dist/xstate-actors.development.cjs.js +1 -1
- package/dist/xstate-actors.development.esm.js +1 -1
- package/dist/xstate-actors.esm.js +1 -1
- package/dist/xstate-actors.umd.min.js +1 -1
- package/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/xstate-graph.cjs.js +2 -2
- package/dist/xstate-graph.development.cjs.js +2 -2
- package/dist/xstate-graph.development.esm.js +2 -2
- package/dist/xstate-graph.esm.js +2 -2
- package/dist/xstate-graph.umd.min.js +1 -1
- package/dist/xstate-graph.umd.min.js.map +1 -1
- package/dist/xstate.cjs.js +214 -63
- package/dist/xstate.cjs.mjs +2 -5
- package/dist/xstate.development.cjs.js +214 -63
- package/dist/xstate.development.cjs.mjs +2 -5
- package/dist/xstate.development.esm.js +215 -61
- package/dist/xstate.esm.js +215 -61
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/dist/declarations/src/atom.d.ts +0 -81
package/README.md
CHANGED
|
@@ -119,7 +119,7 @@ npm install xstate
|
|
|
119
119
|
```
|
|
120
120
|
|
|
121
121
|
```ts
|
|
122
|
-
import { createMachine, createActor
|
|
122
|
+
import { createMachine, createActor } from 'xstate';
|
|
123
123
|
|
|
124
124
|
// State machine
|
|
125
125
|
const toggleMachine = createMachine({
|
|
@@ -135,7 +135,9 @@ const toggleMachine = createMachine({
|
|
|
135
135
|
}
|
|
136
136
|
},
|
|
137
137
|
active: {
|
|
138
|
-
entry:
|
|
138
|
+
entry: ({ context }) => ({
|
|
139
|
+
context: { count: context.count + 1 }
|
|
140
|
+
}),
|
|
139
141
|
on: {
|
|
140
142
|
TOGGLE: { target: 'inactive' }
|
|
141
143
|
}
|
|
@@ -365,10 +367,10 @@ const wordMachine = createMachine({
|
|
|
365
367
|
initial: 'off',
|
|
366
368
|
states: {
|
|
367
369
|
on: {
|
|
368
|
-
on: { TOGGLE_BOLD: 'off' }
|
|
370
|
+
on: { TOGGLE_BOLD: { target: 'off' } }
|
|
369
371
|
},
|
|
370
372
|
off: {
|
|
371
|
-
on: { TOGGLE_BOLD: 'on' }
|
|
373
|
+
on: { TOGGLE_BOLD: { target: 'on' } }
|
|
372
374
|
}
|
|
373
375
|
}
|
|
374
376
|
},
|
|
@@ -376,10 +378,10 @@ const wordMachine = createMachine({
|
|
|
376
378
|
initial: 'off',
|
|
377
379
|
states: {
|
|
378
380
|
on: {
|
|
379
|
-
on: { TOGGLE_UNDERLINE: 'off' }
|
|
381
|
+
on: { TOGGLE_UNDERLINE: { target: 'off' } }
|
|
380
382
|
},
|
|
381
383
|
off: {
|
|
382
|
-
on: { TOGGLE_UNDERLINE: 'on' }
|
|
384
|
+
on: { TOGGLE_UNDERLINE: { target: 'on' } }
|
|
383
385
|
}
|
|
384
386
|
}
|
|
385
387
|
},
|
|
@@ -387,10 +389,10 @@ const wordMachine = createMachine({
|
|
|
387
389
|
initial: 'off',
|
|
388
390
|
states: {
|
|
389
391
|
on: {
|
|
390
|
-
on: { TOGGLE_ITALICS: 'off' }
|
|
392
|
+
on: { TOGGLE_ITALICS: { target: 'off' } }
|
|
391
393
|
},
|
|
392
394
|
off: {
|
|
393
|
-
on: { TOGGLE_ITALICS: 'on' }
|
|
395
|
+
on: { TOGGLE_ITALICS: { target: 'on' } }
|
|
394
396
|
}
|
|
395
397
|
}
|
|
396
398
|
},
|
|
@@ -399,20 +401,20 @@ const wordMachine = createMachine({
|
|
|
399
401
|
states: {
|
|
400
402
|
none: {
|
|
401
403
|
on: {
|
|
402
|
-
BULLETS: 'bullets',
|
|
403
|
-
NUMBERS: 'numbers'
|
|
404
|
+
BULLETS: { target: 'bullets' },
|
|
405
|
+
NUMBERS: { target: 'numbers' }
|
|
404
406
|
}
|
|
405
407
|
},
|
|
406
408
|
bullets: {
|
|
407
409
|
on: {
|
|
408
|
-
NONE: 'none',
|
|
409
|
-
NUMBERS: 'numbers'
|
|
410
|
+
NONE: { target: 'none' },
|
|
411
|
+
NUMBERS: { target: 'numbers' }
|
|
410
412
|
}
|
|
411
413
|
},
|
|
412
414
|
numbers: {
|
|
413
415
|
on: {
|
|
414
|
-
BULLETS: 'bullets',
|
|
415
|
-
NONE: 'none'
|
|
416
|
+
BULLETS: { target: 'bullets' },
|
|
417
|
+
NONE: { target: 'none' }
|
|
416
418
|
}
|
|
417
419
|
}
|
|
418
420
|
}
|
|
@@ -493,10 +495,10 @@ const paymentMachine = createMachine({
|
|
|
493
495
|
},
|
|
494
496
|
hist: { type: 'history' }
|
|
495
497
|
},
|
|
496
|
-
on: { NEXT: 'review' }
|
|
498
|
+
on: { NEXT: { target: 'review' } }
|
|
497
499
|
},
|
|
498
500
|
review: {
|
|
499
|
-
on: { PREVIOUS: 'method.hist' }
|
|
501
|
+
on: { PREVIOUS: { target: 'method.hist' } }
|
|
500
502
|
}
|
|
501
503
|
}
|
|
502
504
|
});
|
package/dist/{StateMachine-6ec50e21.development.esm.js → StateMachine-0aa98f54.development.esm.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { P as ProcessingStatus,
|
|
1
|
+
import { P as ProcessingStatus, C as resolveReferencedActor, c as createActor, S as STATE_DELIMITER, D as mapValues, t as toArray, E as createInvokeId, F as getDelayedTransitions, G as evaluateCandidate, H as formatTransition, N as NULL_EVENT, I as toTransitionConfigArray, J as createInvokeTimeoutEvent, K as getCandidates, L as formatRouteTransitions, M as resolveStateValue, O as getAllStateNodes, f as getStateNodes, Q as createMachineSnapshot, R as isInFinalState, a as macrostep, U as transitionNode, m as matchesEventDescriptor, V as resolveActionsWithContext, b as createInitEvent, d as initialMicrostep, W as toStatePath, X as isStateId, Y as getStateNodeByPath, Z as getPersistedSnapshot, $ as $$ACTOR_TYPE } from './index-2f2fbd9b.development.esm.js';
|
|
2
2
|
|
|
3
3
|
function createSpawner(actorScope, {
|
|
4
4
|
machine,
|
|
@@ -20,7 +20,7 @@ function createSpawner(actorScope, {
|
|
|
20
20
|
self: actorScope.self
|
|
21
21
|
}) : options?.input,
|
|
22
22
|
src,
|
|
23
|
-
|
|
23
|
+
registryKey: options?.registryKey
|
|
24
24
|
});
|
|
25
25
|
spawnedChildren[actor.id] = actor;
|
|
26
26
|
return actor;
|
|
@@ -31,7 +31,7 @@ function createSpawner(actorScope, {
|
|
|
31
31
|
syncSnapshot: options?.syncSnapshot,
|
|
32
32
|
input: options?.input,
|
|
33
33
|
src,
|
|
34
|
-
|
|
34
|
+
registryKey: options?.registryKey
|
|
35
35
|
});
|
|
36
36
|
return actor;
|
|
37
37
|
}
|
|
@@ -171,7 +171,7 @@ class StateNode {
|
|
|
171
171
|
this.invoke = toArray(this.config.invoke).map((invokeConfig, i) => {
|
|
172
172
|
const {
|
|
173
173
|
src,
|
|
174
|
-
|
|
174
|
+
registryKey
|
|
175
175
|
} = invokeConfig;
|
|
176
176
|
const invokeId = createInvokeId(this.id, i);
|
|
177
177
|
const resolvedId = invokeConfig.id ?? invokeId;
|
|
@@ -184,7 +184,7 @@ class StateNode {
|
|
|
184
184
|
src: sourceName,
|
|
185
185
|
logic: src,
|
|
186
186
|
id: resolvedId,
|
|
187
|
-
|
|
187
|
+
registryKey
|
|
188
188
|
};
|
|
189
189
|
});
|
|
190
190
|
}
|
|
@@ -422,7 +422,7 @@ class StateMachine {
|
|
|
422
422
|
this._json = void 0;
|
|
423
423
|
this.id = config.id || '(machine)';
|
|
424
424
|
this.implementations = {
|
|
425
|
-
|
|
425
|
+
actorSources: config.actorSources ?? {},
|
|
426
426
|
actions: config.actions ?? {},
|
|
427
427
|
delays: config.delays ?? {},
|
|
428
428
|
guards: config.guards ?? {},
|
|
@@ -431,7 +431,7 @@ class StateMachine {
|
|
|
431
431
|
{
|
|
432
432
|
// The `@xstate.` prefix is reserved for built-in serialized action and
|
|
433
433
|
// guard descriptors — user implementation names must not collide.
|
|
434
|
-
for (const kind of ['actions', 'guards', '
|
|
434
|
+
for (const kind of ['actions', 'guards', 'actorSources', 'delays']) {
|
|
435
435
|
for (const key of Object.keys(this.implementations[kind])) {
|
|
436
436
|
if (key.startsWith('@xstate.')) {
|
|
437
437
|
throw new Error(`Invalid ${kind} name '${key}': the '@xstate.' prefix is reserved for built-in descriptors.`);
|
|
@@ -447,6 +447,7 @@ class StateMachine {
|
|
|
447
447
|
...this.config.options
|
|
448
448
|
};
|
|
449
449
|
this.transition = this.transition.bind(this);
|
|
450
|
+
this.initialTransition = this.initialTransition.bind(this);
|
|
450
451
|
this.getInitialSnapshot = this.getInitialSnapshot.bind(this);
|
|
451
452
|
this.getPersistedSnapshot = this.getPersistedSnapshot.bind(this);
|
|
452
453
|
this.restoreSnapshot = this.restoreSnapshot.bind(this);
|
|
@@ -468,15 +469,15 @@ class StateMachine {
|
|
|
468
469
|
/**
|
|
469
470
|
* Clones this state machine with the provided implementations.
|
|
470
471
|
*
|
|
471
|
-
* @param implementations Options (`actions`, `guards`, `
|
|
472
|
-
* recursively merge with the existing options.
|
|
472
|
+
* @param implementations Options (`actions`, `guards`, `actorSources`,
|
|
473
|
+
* `delays`) to recursively merge with the existing options.
|
|
473
474
|
* @returns A new `StateMachine` instance with the provided implementations.
|
|
474
475
|
*/
|
|
475
476
|
provide(implementations) {
|
|
476
477
|
const {
|
|
477
478
|
actions,
|
|
478
479
|
guards,
|
|
479
|
-
|
|
480
|
+
actorSources,
|
|
480
481
|
delays
|
|
481
482
|
} = this.implementations;
|
|
482
483
|
const provided = new StateMachine(this.config, {
|
|
@@ -488,9 +489,9 @@ class StateMachine {
|
|
|
488
489
|
...guards,
|
|
489
490
|
...implementations.guards
|
|
490
491
|
},
|
|
491
|
-
|
|
492
|
-
...
|
|
493
|
-
...implementations.
|
|
492
|
+
actorSources: {
|
|
493
|
+
...actorSources,
|
|
494
|
+
...implementations.actorSources
|
|
494
495
|
},
|
|
495
496
|
delays: {
|
|
496
497
|
...delays,
|
|
@@ -525,7 +526,11 @@ class StateMachine {
|
|
|
525
526
|
* @param event The received event
|
|
526
527
|
*/
|
|
527
528
|
transition(snapshot, event, actorScope) {
|
|
528
|
-
|
|
529
|
+
const {
|
|
530
|
+
snapshot: nextSnapshot,
|
|
531
|
+
microsteps
|
|
532
|
+
} = macrostep(snapshot, event, actorScope, []);
|
|
533
|
+
return [nextSnapshot, microsteps.flatMap(([, actions]) => actions)];
|
|
529
534
|
}
|
|
530
535
|
|
|
531
536
|
/**
|
|
@@ -580,9 +585,9 @@ class StateMachine {
|
|
|
580
585
|
spawn,
|
|
581
586
|
input: initEvent.input,
|
|
582
587
|
self: actorScope.self,
|
|
583
|
-
|
|
588
|
+
actorSources: this.implementations.actorSources
|
|
584
589
|
});
|
|
585
|
-
const nextState =
|
|
590
|
+
const [nextState] = resolveActionsWithContext(preInitial, initEvent, actorScope, []);
|
|
586
591
|
if (resolvedContext) {
|
|
587
592
|
nextState.context = resolvedContext;
|
|
588
593
|
}
|
|
@@ -602,14 +607,18 @@ class StateMachine {
|
|
|
602
607
|
* `ActorRef`.
|
|
603
608
|
*/
|
|
604
609
|
getInitialSnapshot(actorScope, input) {
|
|
610
|
+
return this.initialTransition(input, actorScope)[0];
|
|
611
|
+
}
|
|
612
|
+
initialTransition(input, actorScope) {
|
|
605
613
|
const initEvent = createInitEvent(input); // TODO: fix;
|
|
606
614
|
const internalQueue = [];
|
|
607
615
|
const preInitialState = this._getPreInitialState(actorScope, initEvent);
|
|
608
|
-
const [nextState] = initialMicrostep(this.root, preInitialState, actorScope, initEvent, internalQueue);
|
|
616
|
+
const [nextState, initialActions] = initialMicrostep(this.root, preInitialState, actorScope, initEvent, internalQueue);
|
|
609
617
|
const {
|
|
610
|
-
snapshot: macroState
|
|
618
|
+
snapshot: macroState,
|
|
619
|
+
microsteps
|
|
611
620
|
} = macrostep(nextState, initEvent, actorScope, internalQueue);
|
|
612
|
-
return macroState;
|
|
621
|
+
return [macroState, [...initialActions, ...microsteps.flatMap(([, actions]) => actions)]];
|
|
613
622
|
}
|
|
614
623
|
start(snapshot) {
|
|
615
624
|
// Start rehydrated children that were active when persisted. Freshly
|
|
@@ -663,7 +672,7 @@ class StateMachine {
|
|
|
663
672
|
syncSnapshot: actorData.syncSnapshot,
|
|
664
673
|
snapshot: childState,
|
|
665
674
|
src,
|
|
666
|
-
|
|
675
|
+
registryKey: actorData.registryKey
|
|
667
676
|
});
|
|
668
677
|
// Mark so `start()` knows to start this child (freshly invoked/spawned
|
|
669
678
|
// children are started via deferred `@xstate.start` actions instead).
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var dist_xstateActors = require('./index-
|
|
3
|
+
var dist_xstateActors = require('./index-559ceab3.cjs.js');
|
|
4
4
|
|
|
5
5
|
function createSpawner(actorScope, {
|
|
6
6
|
machine,
|
|
@@ -22,7 +22,7 @@ function createSpawner(actorScope, {
|
|
|
22
22
|
self: actorScope.self
|
|
23
23
|
}) : options?.input,
|
|
24
24
|
src,
|
|
25
|
-
|
|
25
|
+
registryKey: options?.registryKey
|
|
26
26
|
});
|
|
27
27
|
spawnedChildren[actor.id] = actor;
|
|
28
28
|
return actor;
|
|
@@ -33,7 +33,7 @@ function createSpawner(actorScope, {
|
|
|
33
33
|
syncSnapshot: options?.syncSnapshot,
|
|
34
34
|
input: options?.input,
|
|
35
35
|
src,
|
|
36
|
-
|
|
36
|
+
registryKey: options?.registryKey
|
|
37
37
|
});
|
|
38
38
|
return actor;
|
|
39
39
|
}
|
|
@@ -173,7 +173,7 @@ class StateNode {
|
|
|
173
173
|
this.invoke = dist_xstateActors.toArray(this.config.invoke).map((invokeConfig, i) => {
|
|
174
174
|
const {
|
|
175
175
|
src,
|
|
176
|
-
|
|
176
|
+
registryKey
|
|
177
177
|
} = invokeConfig;
|
|
178
178
|
const invokeId = dist_xstateActors.createInvokeId(this.id, i);
|
|
179
179
|
const resolvedId = invokeConfig.id ?? invokeId;
|
|
@@ -186,7 +186,7 @@ class StateNode {
|
|
|
186
186
|
src: sourceName,
|
|
187
187
|
logic: src,
|
|
188
188
|
id: resolvedId,
|
|
189
|
-
|
|
189
|
+
registryKey
|
|
190
190
|
};
|
|
191
191
|
});
|
|
192
192
|
}
|
|
@@ -424,7 +424,7 @@ class StateMachine {
|
|
|
424
424
|
this._json = void 0;
|
|
425
425
|
this.id = config.id || '(machine)';
|
|
426
426
|
this.implementations = {
|
|
427
|
-
|
|
427
|
+
actorSources: config.actorSources ?? {},
|
|
428
428
|
actions: config.actions ?? {},
|
|
429
429
|
delays: config.delays ?? {},
|
|
430
430
|
guards: config.guards ?? {},
|
|
@@ -438,6 +438,7 @@ class StateMachine {
|
|
|
438
438
|
...this.config.options
|
|
439
439
|
};
|
|
440
440
|
this.transition = this.transition.bind(this);
|
|
441
|
+
this.initialTransition = this.initialTransition.bind(this);
|
|
441
442
|
this.getInitialSnapshot = this.getInitialSnapshot.bind(this);
|
|
442
443
|
this.getPersistedSnapshot = this.getPersistedSnapshot.bind(this);
|
|
443
444
|
this.restoreSnapshot = this.restoreSnapshot.bind(this);
|
|
@@ -456,15 +457,15 @@ class StateMachine {
|
|
|
456
457
|
/**
|
|
457
458
|
* Clones this state machine with the provided implementations.
|
|
458
459
|
*
|
|
459
|
-
* @param implementations Options (`actions`, `guards`, `
|
|
460
|
-
* recursively merge with the existing options.
|
|
460
|
+
* @param implementations Options (`actions`, `guards`, `actorSources`,
|
|
461
|
+
* `delays`) to recursively merge with the existing options.
|
|
461
462
|
* @returns A new `StateMachine` instance with the provided implementations.
|
|
462
463
|
*/
|
|
463
464
|
provide(implementations) {
|
|
464
465
|
const {
|
|
465
466
|
actions,
|
|
466
467
|
guards,
|
|
467
|
-
|
|
468
|
+
actorSources,
|
|
468
469
|
delays
|
|
469
470
|
} = this.implementations;
|
|
470
471
|
const provided = new StateMachine(this.config, {
|
|
@@ -476,9 +477,9 @@ class StateMachine {
|
|
|
476
477
|
...guards,
|
|
477
478
|
...implementations.guards
|
|
478
479
|
},
|
|
479
|
-
|
|
480
|
-
...
|
|
481
|
-
...implementations.
|
|
480
|
+
actorSources: {
|
|
481
|
+
...actorSources,
|
|
482
|
+
...implementations.actorSources
|
|
482
483
|
},
|
|
483
484
|
delays: {
|
|
484
485
|
...delays,
|
|
@@ -513,7 +514,11 @@ class StateMachine {
|
|
|
513
514
|
* @param event The received event
|
|
514
515
|
*/
|
|
515
516
|
transition(snapshot, event, actorScope) {
|
|
516
|
-
|
|
517
|
+
const {
|
|
518
|
+
snapshot: nextSnapshot,
|
|
519
|
+
microsteps
|
|
520
|
+
} = dist_xstateActors.macrostep(snapshot, event, actorScope, []);
|
|
521
|
+
return [nextSnapshot, microsteps.flatMap(([, actions]) => actions)];
|
|
517
522
|
}
|
|
518
523
|
|
|
519
524
|
/**
|
|
@@ -568,9 +573,9 @@ class StateMachine {
|
|
|
568
573
|
spawn,
|
|
569
574
|
input: initEvent.input,
|
|
570
575
|
self: actorScope.self,
|
|
571
|
-
|
|
576
|
+
actorSources: this.implementations.actorSources
|
|
572
577
|
});
|
|
573
|
-
const nextState = dist_xstateActors.
|
|
578
|
+
const [nextState] = dist_xstateActors.resolveActionsWithContext(preInitial, initEvent, actorScope, []);
|
|
574
579
|
if (resolvedContext) {
|
|
575
580
|
nextState.context = resolvedContext;
|
|
576
581
|
}
|
|
@@ -590,14 +595,18 @@ class StateMachine {
|
|
|
590
595
|
* `ActorRef`.
|
|
591
596
|
*/
|
|
592
597
|
getInitialSnapshot(actorScope, input) {
|
|
598
|
+
return this.initialTransition(input, actorScope)[0];
|
|
599
|
+
}
|
|
600
|
+
initialTransition(input, actorScope) {
|
|
593
601
|
const initEvent = dist_xstateActors.createInitEvent(input); // TODO: fix;
|
|
594
602
|
const internalQueue = [];
|
|
595
603
|
const preInitialState = this._getPreInitialState(actorScope, initEvent);
|
|
596
|
-
const [nextState] = dist_xstateActors.initialMicrostep(this.root, preInitialState, actorScope, initEvent, internalQueue);
|
|
604
|
+
const [nextState, initialActions] = dist_xstateActors.initialMicrostep(this.root, preInitialState, actorScope, initEvent, internalQueue);
|
|
597
605
|
const {
|
|
598
|
-
snapshot: macroState
|
|
606
|
+
snapshot: macroState,
|
|
607
|
+
microsteps
|
|
599
608
|
} = dist_xstateActors.macrostep(nextState, initEvent, actorScope, internalQueue);
|
|
600
|
-
return macroState;
|
|
609
|
+
return [macroState, [...initialActions, ...microsteps.flatMap(([, actions]) => actions)]];
|
|
601
610
|
}
|
|
602
611
|
start(snapshot) {
|
|
603
612
|
// Start rehydrated children that were active when persisted. Freshly
|
|
@@ -651,7 +660,7 @@ class StateMachine {
|
|
|
651
660
|
syncSnapshot: actorData.syncSnapshot,
|
|
652
661
|
snapshot: childState,
|
|
653
662
|
src,
|
|
654
|
-
|
|
663
|
+
registryKey: actorData.registryKey
|
|
655
664
|
});
|
|
656
665
|
// Mark so `start()` knows to start this child (freshly invoked/spawned
|
|
657
666
|
// children are started via deferred `@xstate.start` actions instead).
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { P as ProcessingStatus,
|
|
1
|
+
import { P as ProcessingStatus, C as resolveReferencedActor, c as createActor, S as STATE_DELIMITER, D as mapValues, t as toArray, E as createInvokeId, F as getDelayedTransitions, G as evaluateCandidate, H as formatTransition, N as NULL_EVENT, I as toTransitionConfigArray, J as createInvokeTimeoutEvent, K as getCandidates, L as formatRouteTransitions, M as resolveStateValue, O as getAllStateNodes, f as getStateNodes, Q as createMachineSnapshot, R as isInFinalState, a as macrostep, U as transitionNode, m as matchesEventDescriptor, V as resolveActionsWithContext, b as createInitEvent, d as initialMicrostep, W as toStatePath, X as isStateId, Y as getStateNodeByPath, Z as getPersistedSnapshot, $ as $$ACTOR_TYPE } from './index-8828376f.esm.js';
|
|
2
2
|
|
|
3
3
|
function createSpawner(actorScope, {
|
|
4
4
|
machine,
|
|
@@ -20,7 +20,7 @@ function createSpawner(actorScope, {
|
|
|
20
20
|
self: actorScope.self
|
|
21
21
|
}) : options?.input,
|
|
22
22
|
src,
|
|
23
|
-
|
|
23
|
+
registryKey: options?.registryKey
|
|
24
24
|
});
|
|
25
25
|
spawnedChildren[actor.id] = actor;
|
|
26
26
|
return actor;
|
|
@@ -31,7 +31,7 @@ function createSpawner(actorScope, {
|
|
|
31
31
|
syncSnapshot: options?.syncSnapshot,
|
|
32
32
|
input: options?.input,
|
|
33
33
|
src,
|
|
34
|
-
|
|
34
|
+
registryKey: options?.registryKey
|
|
35
35
|
});
|
|
36
36
|
return actor;
|
|
37
37
|
}
|
|
@@ -171,7 +171,7 @@ class StateNode {
|
|
|
171
171
|
this.invoke = toArray(this.config.invoke).map((invokeConfig, i) => {
|
|
172
172
|
const {
|
|
173
173
|
src,
|
|
174
|
-
|
|
174
|
+
registryKey
|
|
175
175
|
} = invokeConfig;
|
|
176
176
|
const invokeId = createInvokeId(this.id, i);
|
|
177
177
|
const resolvedId = invokeConfig.id ?? invokeId;
|
|
@@ -184,7 +184,7 @@ class StateNode {
|
|
|
184
184
|
src: sourceName,
|
|
185
185
|
logic: src,
|
|
186
186
|
id: resolvedId,
|
|
187
|
-
|
|
187
|
+
registryKey
|
|
188
188
|
};
|
|
189
189
|
});
|
|
190
190
|
}
|
|
@@ -422,7 +422,7 @@ class StateMachine {
|
|
|
422
422
|
this._json = void 0;
|
|
423
423
|
this.id = config.id || '(machine)';
|
|
424
424
|
this.implementations = {
|
|
425
|
-
|
|
425
|
+
actorSources: config.actorSources ?? {},
|
|
426
426
|
actions: config.actions ?? {},
|
|
427
427
|
delays: config.delays ?? {},
|
|
428
428
|
guards: config.guards ?? {},
|
|
@@ -436,6 +436,7 @@ class StateMachine {
|
|
|
436
436
|
...this.config.options
|
|
437
437
|
};
|
|
438
438
|
this.transition = this.transition.bind(this);
|
|
439
|
+
this.initialTransition = this.initialTransition.bind(this);
|
|
439
440
|
this.getInitialSnapshot = this.getInitialSnapshot.bind(this);
|
|
440
441
|
this.getPersistedSnapshot = this.getPersistedSnapshot.bind(this);
|
|
441
442
|
this.restoreSnapshot = this.restoreSnapshot.bind(this);
|
|
@@ -454,15 +455,15 @@ class StateMachine {
|
|
|
454
455
|
/**
|
|
455
456
|
* Clones this state machine with the provided implementations.
|
|
456
457
|
*
|
|
457
|
-
* @param implementations Options (`actions`, `guards`, `
|
|
458
|
-
* recursively merge with the existing options.
|
|
458
|
+
* @param implementations Options (`actions`, `guards`, `actorSources`,
|
|
459
|
+
* `delays`) to recursively merge with the existing options.
|
|
459
460
|
* @returns A new `StateMachine` instance with the provided implementations.
|
|
460
461
|
*/
|
|
461
462
|
provide(implementations) {
|
|
462
463
|
const {
|
|
463
464
|
actions,
|
|
464
465
|
guards,
|
|
465
|
-
|
|
466
|
+
actorSources,
|
|
466
467
|
delays
|
|
467
468
|
} = this.implementations;
|
|
468
469
|
const provided = new StateMachine(this.config, {
|
|
@@ -474,9 +475,9 @@ class StateMachine {
|
|
|
474
475
|
...guards,
|
|
475
476
|
...implementations.guards
|
|
476
477
|
},
|
|
477
|
-
|
|
478
|
-
...
|
|
479
|
-
...implementations.
|
|
478
|
+
actorSources: {
|
|
479
|
+
...actorSources,
|
|
480
|
+
...implementations.actorSources
|
|
480
481
|
},
|
|
481
482
|
delays: {
|
|
482
483
|
...delays,
|
|
@@ -511,7 +512,11 @@ class StateMachine {
|
|
|
511
512
|
* @param event The received event
|
|
512
513
|
*/
|
|
513
514
|
transition(snapshot, event, actorScope) {
|
|
514
|
-
|
|
515
|
+
const {
|
|
516
|
+
snapshot: nextSnapshot,
|
|
517
|
+
microsteps
|
|
518
|
+
} = macrostep(snapshot, event, actorScope, []);
|
|
519
|
+
return [nextSnapshot, microsteps.flatMap(([, actions]) => actions)];
|
|
515
520
|
}
|
|
516
521
|
|
|
517
522
|
/**
|
|
@@ -566,9 +571,9 @@ class StateMachine {
|
|
|
566
571
|
spawn,
|
|
567
572
|
input: initEvent.input,
|
|
568
573
|
self: actorScope.self,
|
|
569
|
-
|
|
574
|
+
actorSources: this.implementations.actorSources
|
|
570
575
|
});
|
|
571
|
-
const nextState =
|
|
576
|
+
const [nextState] = resolveActionsWithContext(preInitial, initEvent, actorScope, []);
|
|
572
577
|
if (resolvedContext) {
|
|
573
578
|
nextState.context = resolvedContext;
|
|
574
579
|
}
|
|
@@ -588,14 +593,18 @@ class StateMachine {
|
|
|
588
593
|
* `ActorRef`.
|
|
589
594
|
*/
|
|
590
595
|
getInitialSnapshot(actorScope, input) {
|
|
596
|
+
return this.initialTransition(input, actorScope)[0];
|
|
597
|
+
}
|
|
598
|
+
initialTransition(input, actorScope) {
|
|
591
599
|
const initEvent = createInitEvent(input); // TODO: fix;
|
|
592
600
|
const internalQueue = [];
|
|
593
601
|
const preInitialState = this._getPreInitialState(actorScope, initEvent);
|
|
594
|
-
const [nextState] = initialMicrostep(this.root, preInitialState, actorScope, initEvent, internalQueue);
|
|
602
|
+
const [nextState, initialActions] = initialMicrostep(this.root, preInitialState, actorScope, initEvent, internalQueue);
|
|
595
603
|
const {
|
|
596
|
-
snapshot: macroState
|
|
604
|
+
snapshot: macroState,
|
|
605
|
+
microsteps
|
|
597
606
|
} = macrostep(nextState, initEvent, actorScope, internalQueue);
|
|
598
|
-
return macroState;
|
|
607
|
+
return [macroState, [...initialActions, ...microsteps.flatMap(([, actions]) => actions)]];
|
|
599
608
|
}
|
|
600
609
|
start(snapshot) {
|
|
601
610
|
// Start rehydrated children that were active when persisted. Freshly
|
|
@@ -649,7 +658,7 @@ class StateMachine {
|
|
|
649
658
|
syncSnapshot: actorData.syncSnapshot,
|
|
650
659
|
snapshot: childState,
|
|
651
660
|
src,
|
|
652
|
-
|
|
661
|
+
registryKey: actorData.registryKey
|
|
653
662
|
});
|
|
654
663
|
// Mark so `start()` knows to start this child (freshly invoked/spawned
|
|
655
664
|
// children are started via deferred `@xstate.start` actions instead).
|