xstate 5.0.0-beta.13 → 5.0.0-beta.14
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 +1 -1
- package/actions/dist/xstate-actions.development.cjs.js +1 -1
- package/actions/dist/xstate-actions.development.esm.js +1 -1
- package/actions/dist/xstate-actions.esm.js +1 -1
- 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 +1 -1
- package/actors/dist/xstate-actors.development.cjs.js +1 -1
- package/actors/dist/xstate-actors.development.esm.js +1 -1
- package/actors/dist/xstate-actors.esm.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/{actions-e4c704f3.cjs.js → actions-17c3bcfa.cjs.js} +803 -853
- package/dist/{actions-b34f6ce7.esm.js → actions-444a17c3.esm.js} +804 -854
- package/dist/{actions-c8b9504d.development.esm.js → actions-60622c0c.development.esm.js} +829 -879
- package/dist/{actions-d9c19f35.development.cjs.js → actions-73b8d456.development.cjs.js} +828 -878
- package/dist/declarations/src/State.d.ts +2 -8
- package/dist/declarations/src/StateMachine.d.ts +5 -10
- package/dist/declarations/src/StateNode.d.ts +1 -1
- package/dist/declarations/src/actors/callback.d.ts +2 -2
- package/dist/declarations/src/actors/index.d.ts +1 -1
- package/dist/declarations/src/actors/observable.d.ts +8 -6
- package/dist/declarations/src/actors/promise.d.ts +4 -3
- package/dist/declarations/src/actors/transition.d.ts +4 -4
- package/dist/declarations/src/interpreter.d.ts +15 -15
- package/dist/declarations/src/stateUtils.d.ts +4 -6
- package/dist/declarations/src/types.d.ts +23 -33
- package/dist/declarations/src/utils.d.ts +7 -7
- package/dist/xstate.cjs.js +13 -37
- package/dist/xstate.development.cjs.js +13 -37
- package/dist/xstate.development.esm.js +14 -38
- package/dist/xstate.esm.js +14 -38
- 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/xstate.cjs.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var actors_dist_xstateActors = require('./actions-
|
|
5
|
+
var actors_dist_xstateActors = require('./actions-17c3bcfa.cjs.js');
|
|
6
6
|
require('../dev/dist/xstate-dev.cjs.js');
|
|
7
7
|
|
|
8
8
|
const EMPTY_OBJECT = {};
|
|
@@ -173,15 +173,15 @@ class StateNode {
|
|
|
173
173
|
}
|
|
174
174
|
|
|
175
175
|
/**
|
|
176
|
-
* The
|
|
176
|
+
* The logic invoked as actors by this state node.
|
|
177
177
|
*/
|
|
178
178
|
get invoke() {
|
|
179
179
|
return actors_dist_xstateActors.memo(this, 'invoke', () => actors_dist_xstateActors.toArray(this.config.invoke).map((invocable, i) => {
|
|
180
180
|
const generatedId = actors_dist_xstateActors.createInvokeId(this.id, i);
|
|
181
181
|
const invokeConfig = actors_dist_xstateActors.toInvokeConfig(invocable, generatedId);
|
|
182
182
|
const resolvedId = invokeConfig.id || generatedId;
|
|
183
|
+
const src = invokeConfig.src;
|
|
183
184
|
const {
|
|
184
|
-
src,
|
|
185
185
|
systemId
|
|
186
186
|
} = invokeConfig;
|
|
187
187
|
const resolvedSrc = actors_dist_xstateActors.isString(src) ? src : !('type' in src) ? resolvedId : src;
|
|
@@ -451,15 +451,14 @@ class StateMachine {
|
|
|
451
451
|
* @param state The current State instance or state value
|
|
452
452
|
* @param event The received event
|
|
453
453
|
*/
|
|
454
|
-
transition(state
|
|
455
|
-
const currentState = state instanceof actors_dist_xstateActors.State ? state : this.resolveStateValue(state);
|
|
454
|
+
transition(state, event, actorCtx) {
|
|
456
455
|
// TODO: handle error events in a better way
|
|
457
|
-
if (actors_dist_xstateActors.isErrorEvent(event) && !
|
|
456
|
+
if (actors_dist_xstateActors.isErrorEvent(event) && !state.nextEvents.some(nextEvent => nextEvent === event.type)) {
|
|
458
457
|
throw event.data;
|
|
459
458
|
}
|
|
460
459
|
const {
|
|
461
460
|
state: nextState
|
|
462
|
-
} = actors_dist_xstateActors.macrostep(
|
|
461
|
+
} = actors_dist_xstateActors.macrostep(state, event, actorCtx);
|
|
463
462
|
return nextState;
|
|
464
463
|
}
|
|
465
464
|
|
|
@@ -470,7 +469,7 @@ class StateMachine {
|
|
|
470
469
|
* @param state The current state
|
|
471
470
|
* @param event The received event
|
|
472
471
|
*/
|
|
473
|
-
microstep(state
|
|
472
|
+
microstep(state, event, actorCtx) {
|
|
474
473
|
return actors_dist_xstateActors.macrostep(state, event, actorCtx).microstates;
|
|
475
474
|
}
|
|
476
475
|
getTransitionData(state, event) {
|
|
@@ -488,33 +487,19 @@ class StateMachine {
|
|
|
488
487
|
value: {},
|
|
489
488
|
// TODO: this is computed in state constructor
|
|
490
489
|
context,
|
|
491
|
-
event: actors_dist_xstateActors.createInitEvent({}),
|
|
492
|
-
actions: [],
|
|
493
490
|
meta: undefined,
|
|
494
491
|
configuration: config,
|
|
495
492
|
transitions: [],
|
|
496
493
|
children: {}
|
|
497
494
|
}));
|
|
498
495
|
preInitial._initial = true;
|
|
499
|
-
preInitial.actions.unshift(...actions);
|
|
500
496
|
if (actorCtx) {
|
|
501
|
-
const
|
|
502
|
-
nextState
|
|
503
|
-
} = actors_dist_xstateActors.resolveActionsAndContext(actions, actors_dist_xstateActors.initEvent, preInitial, actorCtx);
|
|
497
|
+
const [nextState] = actors_dist_xstateActors.resolveActionsAndContext(actions, actors_dist_xstateActors.initEvent, preInitial, actorCtx);
|
|
504
498
|
preInitial.children = nextState.children;
|
|
505
|
-
preInitial.actions = nextState.actions;
|
|
506
499
|
}
|
|
507
500
|
return preInitial;
|
|
508
501
|
}
|
|
509
502
|
|
|
510
|
-
/**
|
|
511
|
-
* The initial State instance, which includes all actions to be executed from
|
|
512
|
-
* entering the initial state.
|
|
513
|
-
*/
|
|
514
|
-
get initialState() {
|
|
515
|
-
return this.getInitialState();
|
|
516
|
-
}
|
|
517
|
-
|
|
518
503
|
/**
|
|
519
504
|
* Returns the initial `State` instance, with reference to `self` as an `ActorRef`.
|
|
520
505
|
*/
|
|
@@ -523,16 +508,12 @@ class StateMachine {
|
|
|
523
508
|
|
|
524
509
|
const preInitialState = this.getPreInitialState(actorCtx, input);
|
|
525
510
|
const nextState = actors_dist_xstateActors.microstep([], preInitialState, actorCtx, initEvent);
|
|
526
|
-
nextState.actions.unshift(...preInitialState.actions);
|
|
527
511
|
const {
|
|
528
512
|
state: macroState
|
|
529
513
|
} = actors_dist_xstateActors.macrostep(nextState, initEvent, actorCtx);
|
|
530
514
|
return macroState;
|
|
531
515
|
}
|
|
532
516
|
start(state, actorCtx) {
|
|
533
|
-
state.actions.forEach(action => {
|
|
534
|
-
action.execute?.(actorCtx);
|
|
535
|
-
});
|
|
536
517
|
Object.values(state.children).forEach(child => {
|
|
537
518
|
if (child.status === 0) {
|
|
538
519
|
try {
|
|
@@ -567,11 +548,7 @@ class StateMachine {
|
|
|
567
548
|
return actors_dist_xstateActors.getPersistedState(state);
|
|
568
549
|
}
|
|
569
550
|
createState(stateConfig) {
|
|
570
|
-
|
|
571
|
-
const {
|
|
572
|
-
nextState: resolvedState
|
|
573
|
-
} = actors_dist_xstateActors.resolveActionsAndContext(state.actions, state.event, state, undefined);
|
|
574
|
-
return resolvedState;
|
|
551
|
+
return stateConfig instanceof actors_dist_xstateActors.State ? stateConfig : new actors_dist_xstateActors.State(stateConfig, this);
|
|
575
552
|
}
|
|
576
553
|
getStatus(state) {
|
|
577
554
|
return state.done ? {
|
|
@@ -587,12 +564,12 @@ class StateMachine {
|
|
|
587
564
|
const actorData = state.children[actorId];
|
|
588
565
|
const childState = actorData.state;
|
|
589
566
|
const src = actorData.src;
|
|
590
|
-
const
|
|
591
|
-
if (!
|
|
567
|
+
const logic = src ? actors_dist_xstateActors.resolveReferencedActor(this.options.actors[src])?.src : undefined;
|
|
568
|
+
if (!logic) {
|
|
592
569
|
return;
|
|
593
570
|
}
|
|
594
|
-
const actorState =
|
|
595
|
-
const actorRef = actors_dist_xstateActors.interpret(
|
|
571
|
+
const actorState = logic.restoreState?.(childState, _actorCtx);
|
|
572
|
+
const actorRef = actors_dist_xstateActors.interpret(logic, {
|
|
596
573
|
id: actorId,
|
|
597
574
|
state: actorState
|
|
598
575
|
});
|
|
@@ -626,7 +603,6 @@ class StateMachine {
|
|
|
626
603
|
});
|
|
627
604
|
}
|
|
628
605
|
});
|
|
629
|
-
restoredState.actions = [];
|
|
630
606
|
return restoredState;
|
|
631
607
|
}
|
|
632
608
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var actors_dist_xstateActors = require('./actions-
|
|
5
|
+
var actors_dist_xstateActors = require('./actions-73b8d456.development.cjs.js');
|
|
6
6
|
require('../dev/dist/xstate-dev.development.cjs.js');
|
|
7
7
|
|
|
8
8
|
const EMPTY_OBJECT = {};
|
|
@@ -173,15 +173,15 @@ class StateNode {
|
|
|
173
173
|
}
|
|
174
174
|
|
|
175
175
|
/**
|
|
176
|
-
* The
|
|
176
|
+
* The logic invoked as actors by this state node.
|
|
177
177
|
*/
|
|
178
178
|
get invoke() {
|
|
179
179
|
return actors_dist_xstateActors.memo(this, 'invoke', () => actors_dist_xstateActors.toArray(this.config.invoke).map((invocable, i) => {
|
|
180
180
|
const generatedId = actors_dist_xstateActors.createInvokeId(this.id, i);
|
|
181
181
|
const invokeConfig = actors_dist_xstateActors.toInvokeConfig(invocable, generatedId);
|
|
182
182
|
const resolvedId = invokeConfig.id || generatedId;
|
|
183
|
+
const src = invokeConfig.src;
|
|
183
184
|
const {
|
|
184
|
-
src,
|
|
185
185
|
systemId
|
|
186
186
|
} = invokeConfig;
|
|
187
187
|
const resolvedSrc = actors_dist_xstateActors.isString(src) ? src : !('type' in src) ? resolvedId : src;
|
|
@@ -451,15 +451,14 @@ class StateMachine {
|
|
|
451
451
|
* @param state The current State instance or state value
|
|
452
452
|
* @param event The received event
|
|
453
453
|
*/
|
|
454
|
-
transition(state
|
|
455
|
-
const currentState = state instanceof actors_dist_xstateActors.State ? state : this.resolveStateValue(state);
|
|
454
|
+
transition(state, event, actorCtx) {
|
|
456
455
|
// TODO: handle error events in a better way
|
|
457
|
-
if (actors_dist_xstateActors.isErrorEvent(event) && !
|
|
456
|
+
if (actors_dist_xstateActors.isErrorEvent(event) && !state.nextEvents.some(nextEvent => nextEvent === event.type)) {
|
|
458
457
|
throw event.data;
|
|
459
458
|
}
|
|
460
459
|
const {
|
|
461
460
|
state: nextState
|
|
462
|
-
} = actors_dist_xstateActors.macrostep(
|
|
461
|
+
} = actors_dist_xstateActors.macrostep(state, event, actorCtx);
|
|
463
462
|
return nextState;
|
|
464
463
|
}
|
|
465
464
|
|
|
@@ -470,7 +469,7 @@ class StateMachine {
|
|
|
470
469
|
* @param state The current state
|
|
471
470
|
* @param event The received event
|
|
472
471
|
*/
|
|
473
|
-
microstep(state
|
|
472
|
+
microstep(state, event, actorCtx) {
|
|
474
473
|
return actors_dist_xstateActors.macrostep(state, event, actorCtx).microstates;
|
|
475
474
|
}
|
|
476
475
|
getTransitionData(state, event) {
|
|
@@ -488,33 +487,19 @@ class StateMachine {
|
|
|
488
487
|
value: {},
|
|
489
488
|
// TODO: this is computed in state constructor
|
|
490
489
|
context,
|
|
491
|
-
event: actors_dist_xstateActors.createInitEvent({}),
|
|
492
|
-
actions: [],
|
|
493
490
|
meta: undefined,
|
|
494
491
|
configuration: config,
|
|
495
492
|
transitions: [],
|
|
496
493
|
children: {}
|
|
497
494
|
}));
|
|
498
495
|
preInitial._initial = true;
|
|
499
|
-
preInitial.actions.unshift(...actions);
|
|
500
496
|
if (actorCtx) {
|
|
501
|
-
const
|
|
502
|
-
nextState
|
|
503
|
-
} = actors_dist_xstateActors.resolveActionsAndContext(actions, actors_dist_xstateActors.initEvent, preInitial, actorCtx);
|
|
497
|
+
const [nextState] = actors_dist_xstateActors.resolveActionsAndContext(actions, actors_dist_xstateActors.initEvent, preInitial, actorCtx);
|
|
504
498
|
preInitial.children = nextState.children;
|
|
505
|
-
preInitial.actions = nextState.actions;
|
|
506
499
|
}
|
|
507
500
|
return preInitial;
|
|
508
501
|
}
|
|
509
502
|
|
|
510
|
-
/**
|
|
511
|
-
* The initial State instance, which includes all actions to be executed from
|
|
512
|
-
* entering the initial state.
|
|
513
|
-
*/
|
|
514
|
-
get initialState() {
|
|
515
|
-
return this.getInitialState();
|
|
516
|
-
}
|
|
517
|
-
|
|
518
503
|
/**
|
|
519
504
|
* Returns the initial `State` instance, with reference to `self` as an `ActorRef`.
|
|
520
505
|
*/
|
|
@@ -523,16 +508,12 @@ class StateMachine {
|
|
|
523
508
|
|
|
524
509
|
const preInitialState = this.getPreInitialState(actorCtx, input);
|
|
525
510
|
const nextState = actors_dist_xstateActors.microstep([], preInitialState, actorCtx, initEvent);
|
|
526
|
-
nextState.actions.unshift(...preInitialState.actions);
|
|
527
511
|
const {
|
|
528
512
|
state: macroState
|
|
529
513
|
} = actors_dist_xstateActors.macrostep(nextState, initEvent, actorCtx);
|
|
530
514
|
return macroState;
|
|
531
515
|
}
|
|
532
516
|
start(state, actorCtx) {
|
|
533
|
-
state.actions.forEach(action => {
|
|
534
|
-
action.execute?.(actorCtx);
|
|
535
|
-
});
|
|
536
517
|
Object.values(state.children).forEach(child => {
|
|
537
518
|
if (child.status === 0) {
|
|
538
519
|
try {
|
|
@@ -567,11 +548,7 @@ class StateMachine {
|
|
|
567
548
|
return actors_dist_xstateActors.getPersistedState(state);
|
|
568
549
|
}
|
|
569
550
|
createState(stateConfig) {
|
|
570
|
-
|
|
571
|
-
const {
|
|
572
|
-
nextState: resolvedState
|
|
573
|
-
} = actors_dist_xstateActors.resolveActionsAndContext(state.actions, state.event, state, undefined);
|
|
574
|
-
return resolvedState;
|
|
551
|
+
return stateConfig instanceof actors_dist_xstateActors.State ? stateConfig : new actors_dist_xstateActors.State(stateConfig, this);
|
|
575
552
|
}
|
|
576
553
|
getStatus(state) {
|
|
577
554
|
return state.done ? {
|
|
@@ -587,12 +564,12 @@ class StateMachine {
|
|
|
587
564
|
const actorData = state.children[actorId];
|
|
588
565
|
const childState = actorData.state;
|
|
589
566
|
const src = actorData.src;
|
|
590
|
-
const
|
|
591
|
-
if (!
|
|
567
|
+
const logic = src ? actors_dist_xstateActors.resolveReferencedActor(this.options.actors[src])?.src : undefined;
|
|
568
|
+
if (!logic) {
|
|
592
569
|
return;
|
|
593
570
|
}
|
|
594
|
-
const actorState =
|
|
595
|
-
const actorRef = actors_dist_xstateActors.interpret(
|
|
571
|
+
const actorState = logic.restoreState?.(childState, _actorCtx);
|
|
572
|
+
const actorRef = actors_dist_xstateActors.interpret(logic, {
|
|
596
573
|
id: actorId,
|
|
597
574
|
state: actorState
|
|
598
575
|
});
|
|
@@ -626,7 +603,6 @@ class StateMachine {
|
|
|
626
603
|
});
|
|
627
604
|
}
|
|
628
605
|
});
|
|
629
|
-
restoredState.actions = [];
|
|
630
606
|
return restoredState;
|
|
631
607
|
}
|
|
632
608
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { m as mapValues, t as toActionObjects, a as toArray, f as formatTransitions, b as toTransitionConfigArray, N as NULL_EVENT, c as formatTransition, d as memo, e as evaluateGuard, g as flatten, h as createInvokeId, i as isString, j as invoke, k as getDelayedTransitions, l as formatInitialTransition, n as getCandidates, o as toInvokeConfig, p as createSpawner, S as STATE_DELIMITER, q as getConfiguration, r as getStateNodes, s as resolveStateValue, u as isInFinalState, v as State, w as isErrorEvent, x as macrostep, y as transitionNode, z as getInitialConfiguration, A as
|
|
2
|
-
export { a9 as ActionTypes, P as Interpreter, Q as InterpreterStatus, aa as SpecialTargets, v as State, a7 as and, T as assign, U as cancel, V as choose, R as doneInvoke, O as forwardTo, a2 as fromCallback, a3 as fromEventObservable, a1 as fromObservable, a0 as fromPromise, a4 as fromTransition, r as getStateNodes,
|
|
1
|
+
import { m as mapValues, t as toActionObjects, a as toArray, f as formatTransitions, b as toTransitionConfigArray, N as NULL_EVENT, c as formatTransition, d as memo, e as evaluateGuard, g as flatten, h as createInvokeId, i as isString, j as invoke, k as getDelayedTransitions, l as formatInitialTransition, n as getCandidates, o as toInvokeConfig, p as createSpawner, S as STATE_DELIMITER, q as getConfiguration, r as getStateNodes, s as resolveStateValue, u as isInFinalState, v as State, w as isErrorEvent, x as macrostep, y as transitionNode, z as getInitialConfiguration, A as resolveActionsAndContext, B as microstep, C as error, D as isStateId, E as getStateNodeByPath, F as getPersistedState, G as resolveReferencedActor, H as interpret, I as createInitEvent, J as initEvent, K as matchesState } from './actions-60622c0c.development.esm.js';
|
|
2
|
+
export { a9 as ActionTypes, P as Interpreter, Q as InterpreterStatus, aa as SpecialTargets, v as State, a7 as and, T as assign, U as cancel, V as choose, R as doneInvoke, O as forwardTo, a2 as fromCallback, a3 as fromEventObservable, a1 as fromObservable, a0 as fromPromise, a4 as fromTransition, r as getStateNodes, H as interpret, W as log, K as matchesState, a6 as not, a8 as or, _ as pathToStateValue, X as pure, Y as raise, M as sendParent, L as sendTo, a5 as stateIn, Z as stop, $ as toObserver } from './actions-60622c0c.development.esm.js';
|
|
3
3
|
import '../dev/dist/xstate-dev.development.esm.js';
|
|
4
4
|
|
|
5
5
|
const EMPTY_OBJECT = {};
|
|
@@ -170,15 +170,15 @@ class StateNode {
|
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
/**
|
|
173
|
-
* The
|
|
173
|
+
* The logic invoked as actors by this state node.
|
|
174
174
|
*/
|
|
175
175
|
get invoke() {
|
|
176
176
|
return memo(this, 'invoke', () => toArray(this.config.invoke).map((invocable, i) => {
|
|
177
177
|
const generatedId = createInvokeId(this.id, i);
|
|
178
178
|
const invokeConfig = toInvokeConfig(invocable, generatedId);
|
|
179
179
|
const resolvedId = invokeConfig.id || generatedId;
|
|
180
|
+
const src = invokeConfig.src;
|
|
180
181
|
const {
|
|
181
|
-
src,
|
|
182
182
|
systemId
|
|
183
183
|
} = invokeConfig;
|
|
184
184
|
const resolvedSrc = isString(src) ? src : !('type' in src) ? resolvedId : src;
|
|
@@ -448,15 +448,14 @@ class StateMachine {
|
|
|
448
448
|
* @param state The current State instance or state value
|
|
449
449
|
* @param event The received event
|
|
450
450
|
*/
|
|
451
|
-
transition(state
|
|
452
|
-
const currentState = state instanceof State ? state : this.resolveStateValue(state);
|
|
451
|
+
transition(state, event, actorCtx) {
|
|
453
452
|
// TODO: handle error events in a better way
|
|
454
|
-
if (isErrorEvent(event) && !
|
|
453
|
+
if (isErrorEvent(event) && !state.nextEvents.some(nextEvent => nextEvent === event.type)) {
|
|
455
454
|
throw event.data;
|
|
456
455
|
}
|
|
457
456
|
const {
|
|
458
457
|
state: nextState
|
|
459
|
-
} = macrostep(
|
|
458
|
+
} = macrostep(state, event, actorCtx);
|
|
460
459
|
return nextState;
|
|
461
460
|
}
|
|
462
461
|
|
|
@@ -467,7 +466,7 @@ class StateMachine {
|
|
|
467
466
|
* @param state The current state
|
|
468
467
|
* @param event The received event
|
|
469
468
|
*/
|
|
470
|
-
microstep(state
|
|
469
|
+
microstep(state, event, actorCtx) {
|
|
471
470
|
return macrostep(state, event, actorCtx).microstates;
|
|
472
471
|
}
|
|
473
472
|
getTransitionData(state, event) {
|
|
@@ -485,33 +484,19 @@ class StateMachine {
|
|
|
485
484
|
value: {},
|
|
486
485
|
// TODO: this is computed in state constructor
|
|
487
486
|
context,
|
|
488
|
-
event: createInitEvent({}),
|
|
489
|
-
actions: [],
|
|
490
487
|
meta: undefined,
|
|
491
488
|
configuration: config,
|
|
492
489
|
transitions: [],
|
|
493
490
|
children: {}
|
|
494
491
|
}));
|
|
495
492
|
preInitial._initial = true;
|
|
496
|
-
preInitial.actions.unshift(...actions);
|
|
497
493
|
if (actorCtx) {
|
|
498
|
-
const
|
|
499
|
-
nextState
|
|
500
|
-
} = resolveActionsAndContext(actions, initEvent, preInitial, actorCtx);
|
|
494
|
+
const [nextState] = resolveActionsAndContext(actions, initEvent, preInitial, actorCtx);
|
|
501
495
|
preInitial.children = nextState.children;
|
|
502
|
-
preInitial.actions = nextState.actions;
|
|
503
496
|
}
|
|
504
497
|
return preInitial;
|
|
505
498
|
}
|
|
506
499
|
|
|
507
|
-
/**
|
|
508
|
-
* The initial State instance, which includes all actions to be executed from
|
|
509
|
-
* entering the initial state.
|
|
510
|
-
*/
|
|
511
|
-
get initialState() {
|
|
512
|
-
return this.getInitialState();
|
|
513
|
-
}
|
|
514
|
-
|
|
515
500
|
/**
|
|
516
501
|
* Returns the initial `State` instance, with reference to `self` as an `ActorRef`.
|
|
517
502
|
*/
|
|
@@ -520,16 +505,12 @@ class StateMachine {
|
|
|
520
505
|
|
|
521
506
|
const preInitialState = this.getPreInitialState(actorCtx, input);
|
|
522
507
|
const nextState = microstep([], preInitialState, actorCtx, initEvent);
|
|
523
|
-
nextState.actions.unshift(...preInitialState.actions);
|
|
524
508
|
const {
|
|
525
509
|
state: macroState
|
|
526
510
|
} = macrostep(nextState, initEvent, actorCtx);
|
|
527
511
|
return macroState;
|
|
528
512
|
}
|
|
529
513
|
start(state, actorCtx) {
|
|
530
|
-
state.actions.forEach(action => {
|
|
531
|
-
action.execute?.(actorCtx);
|
|
532
|
-
});
|
|
533
514
|
Object.values(state.children).forEach(child => {
|
|
534
515
|
if (child.status === 0) {
|
|
535
516
|
try {
|
|
@@ -564,11 +545,7 @@ class StateMachine {
|
|
|
564
545
|
return getPersistedState(state);
|
|
565
546
|
}
|
|
566
547
|
createState(stateConfig) {
|
|
567
|
-
|
|
568
|
-
const {
|
|
569
|
-
nextState: resolvedState
|
|
570
|
-
} = resolveActionsAndContext(state.actions, state.event, state, undefined);
|
|
571
|
-
return resolvedState;
|
|
548
|
+
return stateConfig instanceof State ? stateConfig : new State(stateConfig, this);
|
|
572
549
|
}
|
|
573
550
|
getStatus(state) {
|
|
574
551
|
return state.done ? {
|
|
@@ -584,12 +561,12 @@ class StateMachine {
|
|
|
584
561
|
const actorData = state.children[actorId];
|
|
585
562
|
const childState = actorData.state;
|
|
586
563
|
const src = actorData.src;
|
|
587
|
-
const
|
|
588
|
-
if (!
|
|
564
|
+
const logic = src ? resolveReferencedActor(this.options.actors[src])?.src : undefined;
|
|
565
|
+
if (!logic) {
|
|
589
566
|
return;
|
|
590
567
|
}
|
|
591
|
-
const actorState =
|
|
592
|
-
const actorRef = interpret(
|
|
568
|
+
const actorState = logic.restoreState?.(childState, _actorCtx);
|
|
569
|
+
const actorRef = interpret(logic, {
|
|
593
570
|
id: actorId,
|
|
594
571
|
state: actorState
|
|
595
572
|
});
|
|
@@ -623,7 +600,6 @@ class StateMachine {
|
|
|
623
600
|
});
|
|
624
601
|
}
|
|
625
602
|
});
|
|
626
|
-
restoredState.actions = [];
|
|
627
603
|
return restoredState;
|
|
628
604
|
}
|
|
629
605
|
|
package/dist/xstate.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { m as mapValues, t as toActionObjects, a as toArray, f as formatTransitions, b as toTransitionConfigArray, N as NULL_EVENT, c as formatTransition, d as memo, e as evaluateGuard, g as flatten, h as createInvokeId, i as isString, j as invoke, k as getDelayedTransitions, l as formatInitialTransition, n as getCandidates, o as toInvokeConfig, p as createSpawner, S as STATE_DELIMITER, q as getConfiguration, r as getStateNodes, s as resolveStateValue, u as isInFinalState, v as State, w as isErrorEvent, x as macrostep, y as transitionNode, z as getInitialConfiguration, A as
|
|
2
|
-
export { a9 as ActionTypes, P as Interpreter, Q as InterpreterStatus, aa as SpecialTargets, v as State, a7 as and, T as assign, U as cancel, V as choose, R as doneInvoke, O as forwardTo, a2 as fromCallback, a3 as fromEventObservable, a1 as fromObservable, a0 as fromPromise, a4 as fromTransition, r as getStateNodes,
|
|
1
|
+
import { m as mapValues, t as toActionObjects, a as toArray, f as formatTransitions, b as toTransitionConfigArray, N as NULL_EVENT, c as formatTransition, d as memo, e as evaluateGuard, g as flatten, h as createInvokeId, i as isString, j as invoke, k as getDelayedTransitions, l as formatInitialTransition, n as getCandidates, o as toInvokeConfig, p as createSpawner, S as STATE_DELIMITER, q as getConfiguration, r as getStateNodes, s as resolveStateValue, u as isInFinalState, v as State, w as isErrorEvent, x as macrostep, y as transitionNode, z as getInitialConfiguration, A as resolveActionsAndContext, B as microstep, C as error, D as isStateId, E as getStateNodeByPath, F as getPersistedState, G as resolveReferencedActor, H as interpret, I as createInitEvent, J as initEvent, K as matchesState } from './actions-444a17c3.esm.js';
|
|
2
|
+
export { a9 as ActionTypes, P as Interpreter, Q as InterpreterStatus, aa as SpecialTargets, v as State, a7 as and, T as assign, U as cancel, V as choose, R as doneInvoke, O as forwardTo, a2 as fromCallback, a3 as fromEventObservable, a1 as fromObservable, a0 as fromPromise, a4 as fromTransition, r as getStateNodes, H as interpret, W as log, K as matchesState, a6 as not, a8 as or, _ as pathToStateValue, X as pure, Y as raise, M as sendParent, L as sendTo, a5 as stateIn, Z as stop, $ as toObserver } from './actions-444a17c3.esm.js';
|
|
3
3
|
import '../dev/dist/xstate-dev.esm.js';
|
|
4
4
|
|
|
5
5
|
const EMPTY_OBJECT = {};
|
|
@@ -170,15 +170,15 @@ class StateNode {
|
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
/**
|
|
173
|
-
* The
|
|
173
|
+
* The logic invoked as actors by this state node.
|
|
174
174
|
*/
|
|
175
175
|
get invoke() {
|
|
176
176
|
return memo(this, 'invoke', () => toArray(this.config.invoke).map((invocable, i) => {
|
|
177
177
|
const generatedId = createInvokeId(this.id, i);
|
|
178
178
|
const invokeConfig = toInvokeConfig(invocable, generatedId);
|
|
179
179
|
const resolvedId = invokeConfig.id || generatedId;
|
|
180
|
+
const src = invokeConfig.src;
|
|
180
181
|
const {
|
|
181
|
-
src,
|
|
182
182
|
systemId
|
|
183
183
|
} = invokeConfig;
|
|
184
184
|
const resolvedSrc = isString(src) ? src : !('type' in src) ? resolvedId : src;
|
|
@@ -448,15 +448,14 @@ class StateMachine {
|
|
|
448
448
|
* @param state The current State instance or state value
|
|
449
449
|
* @param event The received event
|
|
450
450
|
*/
|
|
451
|
-
transition(state
|
|
452
|
-
const currentState = state instanceof State ? state : this.resolveStateValue(state);
|
|
451
|
+
transition(state, event, actorCtx) {
|
|
453
452
|
// TODO: handle error events in a better way
|
|
454
|
-
if (isErrorEvent(event) && !
|
|
453
|
+
if (isErrorEvent(event) && !state.nextEvents.some(nextEvent => nextEvent === event.type)) {
|
|
455
454
|
throw event.data;
|
|
456
455
|
}
|
|
457
456
|
const {
|
|
458
457
|
state: nextState
|
|
459
|
-
} = macrostep(
|
|
458
|
+
} = macrostep(state, event, actorCtx);
|
|
460
459
|
return nextState;
|
|
461
460
|
}
|
|
462
461
|
|
|
@@ -467,7 +466,7 @@ class StateMachine {
|
|
|
467
466
|
* @param state The current state
|
|
468
467
|
* @param event The received event
|
|
469
468
|
*/
|
|
470
|
-
microstep(state
|
|
469
|
+
microstep(state, event, actorCtx) {
|
|
471
470
|
return macrostep(state, event, actorCtx).microstates;
|
|
472
471
|
}
|
|
473
472
|
getTransitionData(state, event) {
|
|
@@ -485,33 +484,19 @@ class StateMachine {
|
|
|
485
484
|
value: {},
|
|
486
485
|
// TODO: this is computed in state constructor
|
|
487
486
|
context,
|
|
488
|
-
event: createInitEvent({}),
|
|
489
|
-
actions: [],
|
|
490
487
|
meta: undefined,
|
|
491
488
|
configuration: config,
|
|
492
489
|
transitions: [],
|
|
493
490
|
children: {}
|
|
494
491
|
}));
|
|
495
492
|
preInitial._initial = true;
|
|
496
|
-
preInitial.actions.unshift(...actions);
|
|
497
493
|
if (actorCtx) {
|
|
498
|
-
const
|
|
499
|
-
nextState
|
|
500
|
-
} = resolveActionsAndContext(actions, initEvent, preInitial, actorCtx);
|
|
494
|
+
const [nextState] = resolveActionsAndContext(actions, initEvent, preInitial, actorCtx);
|
|
501
495
|
preInitial.children = nextState.children;
|
|
502
|
-
preInitial.actions = nextState.actions;
|
|
503
496
|
}
|
|
504
497
|
return preInitial;
|
|
505
498
|
}
|
|
506
499
|
|
|
507
|
-
/**
|
|
508
|
-
* The initial State instance, which includes all actions to be executed from
|
|
509
|
-
* entering the initial state.
|
|
510
|
-
*/
|
|
511
|
-
get initialState() {
|
|
512
|
-
return this.getInitialState();
|
|
513
|
-
}
|
|
514
|
-
|
|
515
500
|
/**
|
|
516
501
|
* Returns the initial `State` instance, with reference to `self` as an `ActorRef`.
|
|
517
502
|
*/
|
|
@@ -520,16 +505,12 @@ class StateMachine {
|
|
|
520
505
|
|
|
521
506
|
const preInitialState = this.getPreInitialState(actorCtx, input);
|
|
522
507
|
const nextState = microstep([], preInitialState, actorCtx, initEvent);
|
|
523
|
-
nextState.actions.unshift(...preInitialState.actions);
|
|
524
508
|
const {
|
|
525
509
|
state: macroState
|
|
526
510
|
} = macrostep(nextState, initEvent, actorCtx);
|
|
527
511
|
return macroState;
|
|
528
512
|
}
|
|
529
513
|
start(state, actorCtx) {
|
|
530
|
-
state.actions.forEach(action => {
|
|
531
|
-
action.execute?.(actorCtx);
|
|
532
|
-
});
|
|
533
514
|
Object.values(state.children).forEach(child => {
|
|
534
515
|
if (child.status === 0) {
|
|
535
516
|
try {
|
|
@@ -564,11 +545,7 @@ class StateMachine {
|
|
|
564
545
|
return getPersistedState(state);
|
|
565
546
|
}
|
|
566
547
|
createState(stateConfig) {
|
|
567
|
-
|
|
568
|
-
const {
|
|
569
|
-
nextState: resolvedState
|
|
570
|
-
} = resolveActionsAndContext(state.actions, state.event, state, undefined);
|
|
571
|
-
return resolvedState;
|
|
548
|
+
return stateConfig instanceof State ? stateConfig : new State(stateConfig, this);
|
|
572
549
|
}
|
|
573
550
|
getStatus(state) {
|
|
574
551
|
return state.done ? {
|
|
@@ -584,12 +561,12 @@ class StateMachine {
|
|
|
584
561
|
const actorData = state.children[actorId];
|
|
585
562
|
const childState = actorData.state;
|
|
586
563
|
const src = actorData.src;
|
|
587
|
-
const
|
|
588
|
-
if (!
|
|
564
|
+
const logic = src ? resolveReferencedActor(this.options.actors[src])?.src : undefined;
|
|
565
|
+
if (!logic) {
|
|
589
566
|
return;
|
|
590
567
|
}
|
|
591
|
-
const actorState =
|
|
592
|
-
const actorRef = interpret(
|
|
568
|
+
const actorState = logic.restoreState?.(childState, _actorCtx);
|
|
569
|
+
const actorRef = interpret(logic, {
|
|
593
570
|
id: actorId,
|
|
594
571
|
state: actorState
|
|
595
572
|
});
|
|
@@ -623,7 +600,6 @@ class StateMachine {
|
|
|
623
600
|
});
|
|
624
601
|
}
|
|
625
602
|
});
|
|
626
|
-
restoredState.actions = [];
|
|
627
603
|
return restoredState;
|
|
628
604
|
}
|
|
629
605
|
|