xstate 6.0.0-alpha.6 → 6.0.0-alpha.8
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 +4 -2
- package/dist/{StateMachine-4deb4090.development.esm.js → StateMachine-0aa98f54.development.esm.js} +15 -15
- package/dist/{StateMachine-445a8480.cjs.js → StateMachine-aef700df.cjs.js} +14 -14
- package/dist/{StateMachine-f310bc72.esm.js → StateMachine-d4931336.esm.js} +14 -14
- package/dist/{StateMachine-f83f01f9.development.cjs.js → StateMachine-da872dde.development.cjs.js} +15 -15
- package/dist/declarations/src/StateMachine.d.ts +4 -4
- package/dist/declarations/src/createActor.d.ts +1 -1
- package/dist/declarations/src/createMachine.d.ts +4 -4
- package/dist/declarations/src/createMachineFromConfig.d.ts +4 -3
- package/dist/declarations/src/index.d.ts +1 -1
- package/dist/declarations/src/serialize.d.ts +2 -1
- package/dist/declarations/src/setup.d.ts +109 -36
- 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/types.d.ts +68 -51
- package/dist/declarations/src/types.v6.d.ts +30 -28
- package/dist/declarations/src/utils.d.ts +2 -1
- package/dist/{index-ebaf6fd8.development.cjs.js → index-219cb621.development.cjs.js} +86 -46
- package/dist/{index-ccbe7c0b.development.esm.js → index-2f2fbd9b.development.esm.js} +86 -46
- package/dist/{index-918ab496.cjs.js → index-559ceab3.cjs.js} +86 -46
- package/dist/{index-9cce3480.esm.js → index-8828376f.esm.js} +86 -46
- 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 +70 -17
- package/dist/xstate.cjs.mjs +1 -0
- package/dist/xstate.development.cjs.js +70 -17
- package/dist/xstate.development.cjs.mjs +1 -0
- package/dist/xstate.development.esm.js +72 -20
- package/dist/xstate.esm.js +72 -20
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/package.json +1 -1
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
|
}
|
package/dist/{StateMachine-4deb4090.development.esm.js → StateMachine-0aa98f54.development.esm.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
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-
|
|
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.`);
|
|
@@ -469,15 +469,15 @@ class StateMachine {
|
|
|
469
469
|
/**
|
|
470
470
|
* Clones this state machine with the provided implementations.
|
|
471
471
|
*
|
|
472
|
-
* @param implementations Options (`actions`, `guards`, `
|
|
473
|
-
* recursively merge with the existing options.
|
|
472
|
+
* @param implementations Options (`actions`, `guards`, `actorSources`,
|
|
473
|
+
* `delays`) to recursively merge with the existing options.
|
|
474
474
|
* @returns A new `StateMachine` instance with the provided implementations.
|
|
475
475
|
*/
|
|
476
476
|
provide(implementations) {
|
|
477
477
|
const {
|
|
478
478
|
actions,
|
|
479
479
|
guards,
|
|
480
|
-
|
|
480
|
+
actorSources,
|
|
481
481
|
delays
|
|
482
482
|
} = this.implementations;
|
|
483
483
|
const provided = new StateMachine(this.config, {
|
|
@@ -489,9 +489,9 @@ class StateMachine {
|
|
|
489
489
|
...guards,
|
|
490
490
|
...implementations.guards
|
|
491
491
|
},
|
|
492
|
-
|
|
493
|
-
...
|
|
494
|
-
...implementations.
|
|
492
|
+
actorSources: {
|
|
493
|
+
...actorSources,
|
|
494
|
+
...implementations.actorSources
|
|
495
495
|
},
|
|
496
496
|
delays: {
|
|
497
497
|
...delays,
|
|
@@ -585,7 +585,7 @@ class StateMachine {
|
|
|
585
585
|
spawn,
|
|
586
586
|
input: initEvent.input,
|
|
587
587
|
self: actorScope.self,
|
|
588
|
-
|
|
588
|
+
actorSources: this.implementations.actorSources
|
|
589
589
|
});
|
|
590
590
|
const [nextState] = resolveActionsWithContext(preInitial, initEvent, actorScope, []);
|
|
591
591
|
if (resolvedContext) {
|
|
@@ -672,7 +672,7 @@ class StateMachine {
|
|
|
672
672
|
syncSnapshot: actorData.syncSnapshot,
|
|
673
673
|
snapshot: childState,
|
|
674
674
|
src,
|
|
675
|
-
|
|
675
|
+
registryKey: actorData.registryKey
|
|
676
676
|
});
|
|
677
677
|
// Mark so `start()` knows to start this child (freshly invoked/spawned
|
|
678
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 ?? {},
|
|
@@ -457,15 +457,15 @@ class StateMachine {
|
|
|
457
457
|
/**
|
|
458
458
|
* Clones this state machine with the provided implementations.
|
|
459
459
|
*
|
|
460
|
-
* @param implementations Options (`actions`, `guards`, `
|
|
461
|
-
* recursively merge with the existing options.
|
|
460
|
+
* @param implementations Options (`actions`, `guards`, `actorSources`,
|
|
461
|
+
* `delays`) to recursively merge with the existing options.
|
|
462
462
|
* @returns A new `StateMachine` instance with the provided implementations.
|
|
463
463
|
*/
|
|
464
464
|
provide(implementations) {
|
|
465
465
|
const {
|
|
466
466
|
actions,
|
|
467
467
|
guards,
|
|
468
|
-
|
|
468
|
+
actorSources,
|
|
469
469
|
delays
|
|
470
470
|
} = this.implementations;
|
|
471
471
|
const provided = new StateMachine(this.config, {
|
|
@@ -477,9 +477,9 @@ class StateMachine {
|
|
|
477
477
|
...guards,
|
|
478
478
|
...implementations.guards
|
|
479
479
|
},
|
|
480
|
-
|
|
481
|
-
...
|
|
482
|
-
...implementations.
|
|
480
|
+
actorSources: {
|
|
481
|
+
...actorSources,
|
|
482
|
+
...implementations.actorSources
|
|
483
483
|
},
|
|
484
484
|
delays: {
|
|
485
485
|
...delays,
|
|
@@ -573,7 +573,7 @@ class StateMachine {
|
|
|
573
573
|
spawn,
|
|
574
574
|
input: initEvent.input,
|
|
575
575
|
self: actorScope.self,
|
|
576
|
-
|
|
576
|
+
actorSources: this.implementations.actorSources
|
|
577
577
|
});
|
|
578
578
|
const [nextState] = dist_xstateActors.resolveActionsWithContext(preInitial, initEvent, actorScope, []);
|
|
579
579
|
if (resolvedContext) {
|
|
@@ -660,7 +660,7 @@ class StateMachine {
|
|
|
660
660
|
syncSnapshot: actorData.syncSnapshot,
|
|
661
661
|
snapshot: childState,
|
|
662
662
|
src,
|
|
663
|
-
|
|
663
|
+
registryKey: actorData.registryKey
|
|
664
664
|
});
|
|
665
665
|
// Mark so `start()` knows to start this child (freshly invoked/spawned
|
|
666
666
|
// children are started via deferred `@xstate.start` actions instead).
|
|
@@ -1,4 +1,4 @@
|
|
|
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-
|
|
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 ?? {},
|
|
@@ -455,15 +455,15 @@ class StateMachine {
|
|
|
455
455
|
/**
|
|
456
456
|
* Clones this state machine with the provided implementations.
|
|
457
457
|
*
|
|
458
|
-
* @param implementations Options (`actions`, `guards`, `
|
|
459
|
-
* recursively merge with the existing options.
|
|
458
|
+
* @param implementations Options (`actions`, `guards`, `actorSources`,
|
|
459
|
+
* `delays`) to recursively merge with the existing options.
|
|
460
460
|
* @returns A new `StateMachine` instance with the provided implementations.
|
|
461
461
|
*/
|
|
462
462
|
provide(implementations) {
|
|
463
463
|
const {
|
|
464
464
|
actions,
|
|
465
465
|
guards,
|
|
466
|
-
|
|
466
|
+
actorSources,
|
|
467
467
|
delays
|
|
468
468
|
} = this.implementations;
|
|
469
469
|
const provided = new StateMachine(this.config, {
|
|
@@ -475,9 +475,9 @@ class StateMachine {
|
|
|
475
475
|
...guards,
|
|
476
476
|
...implementations.guards
|
|
477
477
|
},
|
|
478
|
-
|
|
479
|
-
...
|
|
480
|
-
...implementations.
|
|
478
|
+
actorSources: {
|
|
479
|
+
...actorSources,
|
|
480
|
+
...implementations.actorSources
|
|
481
481
|
},
|
|
482
482
|
delays: {
|
|
483
483
|
...delays,
|
|
@@ -571,7 +571,7 @@ class StateMachine {
|
|
|
571
571
|
spawn,
|
|
572
572
|
input: initEvent.input,
|
|
573
573
|
self: actorScope.self,
|
|
574
|
-
|
|
574
|
+
actorSources: this.implementations.actorSources
|
|
575
575
|
});
|
|
576
576
|
const [nextState] = resolveActionsWithContext(preInitial, initEvent, actorScope, []);
|
|
577
577
|
if (resolvedContext) {
|
|
@@ -658,7 +658,7 @@ class StateMachine {
|
|
|
658
658
|
syncSnapshot: actorData.syncSnapshot,
|
|
659
659
|
snapshot: childState,
|
|
660
660
|
src,
|
|
661
|
-
|
|
661
|
+
registryKey: actorData.registryKey
|
|
662
662
|
});
|
|
663
663
|
// Mark so `start()` knows to start this child (freshly invoked/spawned
|
|
664
664
|
// children are started via deferred `@xstate.start` actions instead).
|
package/dist/{StateMachine-f83f01f9.development.cjs.js → StateMachine-da872dde.development.cjs.js}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var dist_xstateActors = require('./index-
|
|
3
|
+
var dist_xstateActors = require('./index-219cb621.development.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 ?? {},
|
|
@@ -433,7 +433,7 @@ class StateMachine {
|
|
|
433
433
|
{
|
|
434
434
|
// The `@xstate.` prefix is reserved for built-in serialized action and
|
|
435
435
|
// guard descriptors — user implementation names must not collide.
|
|
436
|
-
for (const kind of ['actions', 'guards', '
|
|
436
|
+
for (const kind of ['actions', 'guards', 'actorSources', 'delays']) {
|
|
437
437
|
for (const key of Object.keys(this.implementations[kind])) {
|
|
438
438
|
if (key.startsWith('@xstate.')) {
|
|
439
439
|
throw new Error(`Invalid ${kind} name '${key}': the '@xstate.' prefix is reserved for built-in descriptors.`);
|
|
@@ -471,15 +471,15 @@ class StateMachine {
|
|
|
471
471
|
/**
|
|
472
472
|
* Clones this state machine with the provided implementations.
|
|
473
473
|
*
|
|
474
|
-
* @param implementations Options (`actions`, `guards`, `
|
|
475
|
-
* recursively merge with the existing options.
|
|
474
|
+
* @param implementations Options (`actions`, `guards`, `actorSources`,
|
|
475
|
+
* `delays`) to recursively merge with the existing options.
|
|
476
476
|
* @returns A new `StateMachine` instance with the provided implementations.
|
|
477
477
|
*/
|
|
478
478
|
provide(implementations) {
|
|
479
479
|
const {
|
|
480
480
|
actions,
|
|
481
481
|
guards,
|
|
482
|
-
|
|
482
|
+
actorSources,
|
|
483
483
|
delays
|
|
484
484
|
} = this.implementations;
|
|
485
485
|
const provided = new StateMachine(this.config, {
|
|
@@ -491,9 +491,9 @@ class StateMachine {
|
|
|
491
491
|
...guards,
|
|
492
492
|
...implementations.guards
|
|
493
493
|
},
|
|
494
|
-
|
|
495
|
-
...
|
|
496
|
-
...implementations.
|
|
494
|
+
actorSources: {
|
|
495
|
+
...actorSources,
|
|
496
|
+
...implementations.actorSources
|
|
497
497
|
},
|
|
498
498
|
delays: {
|
|
499
499
|
...delays,
|
|
@@ -587,7 +587,7 @@ class StateMachine {
|
|
|
587
587
|
spawn,
|
|
588
588
|
input: initEvent.input,
|
|
589
589
|
self: actorScope.self,
|
|
590
|
-
|
|
590
|
+
actorSources: this.implementations.actorSources
|
|
591
591
|
});
|
|
592
592
|
const [nextState] = dist_xstateActors.resolveActionsWithContext(preInitial, initEvent, actorScope, []);
|
|
593
593
|
if (resolvedContext) {
|
|
@@ -674,7 +674,7 @@ class StateMachine {
|
|
|
674
674
|
syncSnapshot: actorData.syncSnapshot,
|
|
675
675
|
snapshot: childState,
|
|
676
676
|
src,
|
|
677
|
-
|
|
677
|
+
registryKey: actorData.registryKey
|
|
678
678
|
});
|
|
679
679
|
// Mark so `start()` knows to start this child (freshly invoked/spawned
|
|
680
680
|
// children are started via deferred `@xstate.start` actions instead).
|
|
@@ -3,7 +3,7 @@ import { StateNode } from "./StateNode.js";
|
|
|
3
3
|
import { AnyActorSystem } from "./system.js";
|
|
4
4
|
import type { ActorLogic, ActorLogicTransitionResult, ActorScope, AnyActor, AnyActorRef, AnyActorScope, AnyTransitionDefinition, Equals, EventDescriptor, EventObject, ExecutableActionObjectFromLogic, HistoryValue, MachineContext, MetaObject, Snapshot, StateValue, StateSchema, SnapshotStatus } from "./types.js";
|
|
5
5
|
import { AnyMachineSchemas, Implementations, Next_MachineConfig, MachineOptions } from "./types.v6.js";
|
|
6
|
-
export declare class StateMachine<TContext extends MachineContext, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TStateValue extends StateValue, TTag extends string, TInput, TOutput, TEmitted extends EventObject, TMeta extends MetaObject, TConfig extends StateSchema, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
6
|
+
export declare class StateMachine<TContext extends MachineContext, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TStateValue extends StateValue, TTag extends string, TInput, TOutput, TEmitted extends EventObject, TMeta extends MetaObject, TConfig extends StateSchema, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> implements ActorLogic<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>, TEvent, TInput, AnyActorSystem, TEmitted> {
|
|
7
7
|
/** The raw config used to create the machine. */
|
|
8
8
|
config: Next_MachineConfig<any, any, any, any, any, any, any, any, any, any, any> & {
|
|
9
9
|
schemas?: AnyMachineSchemas;
|
|
@@ -29,13 +29,13 @@ export declare class StateMachine<TContext extends MachineContext, TEvent extend
|
|
|
29
29
|
/**
|
|
30
30
|
* Clones this state machine with the provided implementations.
|
|
31
31
|
*
|
|
32
|
-
* @param implementations Options (`actions`, `guards`, `
|
|
33
|
-
* recursively merge with the existing options.
|
|
32
|
+
* @param implementations Options (`actions`, `guards`, `actorSources`,
|
|
33
|
+
* `delays`) to recursively merge with the existing options.
|
|
34
34
|
* @returns A new `StateMachine` instance with the provided implementations.
|
|
35
35
|
*/
|
|
36
36
|
provide(implementations: {
|
|
37
37
|
actions?: Partial<TActionMap>;
|
|
38
|
-
|
|
38
|
+
actorSources?: Partial<TActorMap>;
|
|
39
39
|
guards?: Partial<TGuardMap>;
|
|
40
40
|
delays?: Partial<TDelayMap>;
|
|
41
41
|
}): StateMachine<TContext, TEvent, TChildren, TStateValue, TTag, TInput, TOutput, TEmitted, TMeta, TConfig, TActionMap, TActorMap, TGuardMap, TDelayMap>;
|
|
@@ -40,7 +40,7 @@ export declare class Actor<TLogic extends AnyActorLogic> implements ActorInstanc
|
|
|
40
40
|
ref: ActorRef<SnapshotFrom<TLogic>, EventFromLogic<TLogic>, EmittedFrom<TLogic>, SendableEventFromLogic<TLogic>>;
|
|
41
41
|
private _actorScope;
|
|
42
42
|
private _initialEffects;
|
|
43
|
-
|
|
43
|
+
registryKey: string | undefined;
|
|
44
44
|
/** The globally unique process ID for this invocation. */
|
|
45
45
|
sessionId: string;
|
|
46
46
|
/** The system to which this actor belongs. */
|
|
@@ -45,7 +45,7 @@ type MergeChildren<TChildren extends Record<string, AnyActorRef | undefined>, TA
|
|
|
45
45
|
* @param options DEPRECATED: use `setup({ ... })` or `machine.provide({ ... })`
|
|
46
46
|
* to provide machine implementations instead.
|
|
47
47
|
*/
|
|
48
|
-
export declare function createMachine<TContextSchema extends StandardSchemaV1, const TEventSchemaMap extends Record<string, StandardSchemaV1>, TEmittedSchemaMap extends Record<string, StandardSchemaV1>, TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TTagSchema extends StandardSchemaV1, const TChildrenSchemaMap extends Record<string, StandardSchemaV1>, _TEvent extends EventObject, TActor extends ProvidedActor, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
48
|
+
export declare function createMachine<TContextSchema extends StandardSchemaV1, const TEventSchemaMap extends Record<string, StandardSchemaV1>, TEmittedSchemaMap extends Record<string, StandardSchemaV1>, TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TTagSchema extends StandardSchemaV1, const TChildrenSchemaMap extends Record<string, StandardSchemaV1>, _TEvent extends EventObject, TActor extends ProvidedActor, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TDelays extends string, TTag extends StandardSchemaV1.InferOutput<TTagSchema> & string, TInput, const TSS extends StateSchema>(config: TSS & ValidateDelayReferences<TSS> & Next_MachineConfig<TContextSchema, TEventSchemaMap, TEmittedSchemaMap, TInputSchema, TOutputSchema, TMetaSchema, TTagSchema, TChildrenSchemaMap, InferOutput<TContextSchema, MachineContext>, InferEvents<TEventSchemaMap>, Cast<MergeChildren<InferChildren<TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>, TDelays, TTag, TActionMap, TActorMap, TGuardMap, TDelayMap> & {
|
|
49
49
|
schemas: {
|
|
50
50
|
context: TContextSchema;
|
|
51
51
|
children?: TChildrenSchemaMap;
|
|
@@ -58,13 +58,13 @@ TSS, // TStateSchema
|
|
|
58
58
|
TActionMap, TActorMap, TGuardMap, DelayMapFromNames<TDelays, TDelayMap>> & {
|
|
59
59
|
states: TSS;
|
|
60
60
|
};
|
|
61
|
-
export declare function createMachine<TContext extends MachineContext = never, const TEventSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, TEmittedSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, TInputSchema extends StandardSchemaV1 = StandardSchemaV1, TOutputSchema extends StandardSchemaV1 = StandardSchemaV1, TMetaSchema extends StandardSchemaV1 = StandardSchemaV1, TTagSchema extends StandardSchemaV1 = StandardSchemaV1, const TChildrenSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, _TEvent extends EventObject = EventObject, TActor extends ProvidedActor = ProvidedActor, TActionMap extends Implementations['actions'] = Implementations['actions'], TActorMap extends Implementations['
|
|
61
|
+
export declare function createMachine<TContext extends MachineContext = never, const TEventSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, TEmittedSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, TInputSchema extends StandardSchemaV1 = StandardSchemaV1, TOutputSchema extends StandardSchemaV1 = StandardSchemaV1, TMetaSchema extends StandardSchemaV1 = StandardSchemaV1, TTagSchema extends StandardSchemaV1 = StandardSchemaV1, const TChildrenSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, _TEvent extends EventObject = EventObject, TActor extends ProvidedActor = ProvidedActor, TActionMap extends Implementations['actions'] = Implementations['actions'], TActorMap extends Implementations['actorSources'] = Implementations['actorSources'], TGuardMap extends Implementations['guards'] = Implementations['guards'], TDelayMap extends Implementations['delays'] = Implementations['delays'], TDelays extends string = string, TTag extends StandardSchemaV1.InferOutput<TTagSchema> & string = StandardSchemaV1.InferOutput<TTagSchema> & string, TInput = unknown, const TSS extends StateSchema = StateSchema>(config: TSS & ValidateDelayReferences<TSS> & Next_MachineConfig<StandardSchemaV1, TEventSchemaMap, TEmittedSchemaMap, TInputSchema, TOutputSchema, TMetaSchema, TTagSchema, TChildrenSchemaMap, WidenLiterals<TContext>, InferEvents<TEventSchemaMap>, Cast<MergeChildren<InferChildren<TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>, TDelays, TTag, TActionMap, TActorMap, TGuardMap, TDelayMap, false> & {
|
|
62
62
|
schemas?: {
|
|
63
63
|
context?: never;
|
|
64
64
|
};
|
|
65
65
|
context?: TContext | ((_: {
|
|
66
66
|
spawn: any;
|
|
67
|
-
|
|
67
|
+
actorSources: TActorMap;
|
|
68
68
|
input: InferOutput<TInputSchema, unknown>;
|
|
69
69
|
self: any;
|
|
70
70
|
}) => TContext);
|
|
@@ -77,5 +77,5 @@ TActionMap, TActorMap, TGuardMap, DelayMapFromNames<TDelays, TDelayMap>> & {
|
|
|
77
77
|
states: TSS;
|
|
78
78
|
};
|
|
79
79
|
export declare function createStateConfig<TContextSchema extends StandardSchemaV1, TEventSchema extends StandardSchemaV1, TEmittedSchema extends StandardSchemaV1, _TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TTagSchema extends StandardSchemaV1, _TEvent extends StandardSchemaV1.InferOutput<TEventSchema> & EventObject, // TODO: consider using a stricter `EventObject` here
|
|
80
|
-
_TActor extends ProvidedActor, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
80
|
+
_TActor extends ProvidedActor, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TDelays extends string, _TTag extends StandardSchemaV1.InferOutput<TTagSchema> & string, _TInput, const TSS extends StateSchema>(config: TSS & Next_StateNodeConfig<InferOutput<TContextSchema, MachineContext>, DoNotInfer<StandardSchemaV1.InferOutput<TEventSchema> & EventObject>, DoNotInfer<TDelays>, DoNotInfer<StandardSchemaV1.InferOutput<TTagSchema> & string>, DoNotInfer<StandardSchemaV1.InferOutput<TOutputSchema>>, DoNotInfer<StandardSchemaV1.InferOutput<TEmittedSchema> & EventObject>, DoNotInfer<InferOutput<TMetaSchema, MetaObject>>, DoNotInfer<Record<string, AnyActorRef | undefined>>, DoNotInfer<TActionMap>, DoNotInfer<TActorMap>, DoNotInfer<TGuardMap>, DoNotInfer<TDelayMap>>): typeof config;
|
|
81
81
|
export {};
|
|
@@ -99,7 +99,7 @@ export interface GuardJSON {
|
|
|
99
99
|
}
|
|
100
100
|
export interface InvokeJSON {
|
|
101
101
|
id?: string;
|
|
102
|
-
|
|
102
|
+
registryKey?: string;
|
|
103
103
|
src: string | UnserializableMarker;
|
|
104
104
|
input?: unknown;
|
|
105
105
|
onDone?: TransitionJSON | TransitionJSON[];
|
|
@@ -110,6 +110,7 @@ export interface InvokeJSON {
|
|
|
110
110
|
}
|
|
111
111
|
export interface TransitionJSON {
|
|
112
112
|
target?: string | string[];
|
|
113
|
+
context?: MachineContext;
|
|
113
114
|
actions?: ActionJSON[];
|
|
114
115
|
guard?: GuardJSON;
|
|
115
116
|
description?: string;
|
|
@@ -158,7 +159,7 @@ export interface MachineJSON extends StateNodeJSON {
|
|
|
158
159
|
version?: string;
|
|
159
160
|
actions?: Record<string, unknown>;
|
|
160
161
|
guards?: Record<string, unknown>;
|
|
161
|
-
|
|
162
|
+
actorSources?: Record<string, unknown>;
|
|
162
163
|
delays?: Record<string, unknown>;
|
|
163
164
|
schemas?: Record<string, unknown>;
|
|
164
165
|
}
|
|
@@ -169,7 +170,7 @@ interface UnserializableMarker {
|
|
|
169
170
|
interface MachineImplementations {
|
|
170
171
|
actions?: Record<string, (...args: any[]) => unknown>;
|
|
171
172
|
guards?: Record<string, (...args: any[]) => boolean>;
|
|
172
|
-
|
|
173
|
+
actorSources?: Record<string, AnyActorLogic>;
|
|
173
174
|
delays?: Record<string, number | ((...args: any[]) => number)>;
|
|
174
175
|
}
|
|
175
176
|
export declare function createMachineFromConfig(json: MachineJSON, implementations?: MachineImplementations): AnyStateMachine;
|
|
@@ -7,7 +7,7 @@ export type { ActionJSON, GuardJSON, InvokeJSON, MachineJSON, StateNodeJSON, Tra
|
|
|
7
7
|
export { machineConfigToJSON, serializeMachine, type CodeExpression, type UnserializableMarker } from "./serialize.js";
|
|
8
8
|
export { mapState } from "./mapState.js";
|
|
9
9
|
export { types, isTypeSchema, type StandardSchemaV1, type TypeSchema } from "./schema.types.js";
|
|
10
|
-
export { setup } from "./setup.js";
|
|
10
|
+
export { createSystem, setup } from "./setup.js";
|
|
11
11
|
export { getInitialSnapshot, getNextSnapshot } from "./getNextSnapshot.js";
|
|
12
12
|
export type { InspectionEvent, ActorInspectionEvent, TransitionInspectionEvent, ActionRecord, SentRecord } from "./inspection.js";
|
|
13
13
|
export { SimulatedClock } from "./SimulatedClock.js";
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
* A machine definition is fully portable iff its JSON contains no
|
|
12
12
|
* `$unserializable` markers; reviving a definition that has markers requires
|
|
13
13
|
* re-providing those implementations (e.g. via `machine.provide(...)` or the
|
|
14
|
-
* `actions`/`guards`/`
|
|
14
|
+
* `actions`/`guards`/`actorSources` maps on `createMachineFromConfig`
|
|
15
|
+
* revival).
|
|
15
16
|
*/
|
|
16
17
|
import type { AnyStateMachine } from "./types.js";
|
|
17
18
|
export interface UnserializableMarker {
|