xstate 5.18.2 → 5.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/actions/dist/xstate-actions.cjs.js +2 -2
- package/actions/dist/xstate-actions.development.cjs.js +2 -2
- package/actions/dist/xstate-actions.development.esm.js +2 -2
- package/actions/dist/xstate-actions.esm.js +2 -2
- package/actions/dist/xstate-actions.umd.min.js +1 -1
- package/actions/dist/xstate-actions.umd.min.js.map +1 -1
- package/actors/dist/xstate-actors.cjs.js +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/dev/dist/xstate-dev.cjs.js +1 -1
- package/dev/dist/xstate-dev.development.cjs.js +1 -1
- package/dev/dist/xstate-dev.development.esm.js +1 -1
- package/dev/dist/xstate-dev.esm.js +1 -1
- package/dev/dist/xstate-dev.umd.min.js.map +1 -1
- package/dist/declarations/src/State.d.ts +1 -1
- package/dist/declarations/src/actions/raise.d.ts +9 -1
- package/dist/declarations/src/actions/send.d.ts +10 -1
- package/dist/declarations/src/createActor.d.ts +2 -1
- package/dist/declarations/src/getNextSnapshot.d.ts +2 -0
- package/dist/declarations/src/index.d.ts +1 -0
- package/dist/declarations/src/inspection.d.ts +1 -1
- package/dist/declarations/src/stateUtils.d.ts +17 -7
- package/dist/declarations/src/transition.d.ts +16 -0
- package/dist/declarations/src/types.d.ts +47 -14
- package/dist/declarations/src/utils.d.ts +1 -1
- package/dist/{log-b7ed1b61.development.cjs.js → log-17337367.development.cjs.js} +22 -19
- package/dist/{log-15d0f775.esm.js → log-2a773d37.esm.js} +21 -15
- package/dist/{log-98fcce74.cjs.js → log-b0ee96de.cjs.js} +21 -15
- package/dist/{log-38475d87.development.esm.js → log-ef30c65f.development.esm.js} +22 -19
- package/dist/{raise-5ea71f04.development.esm.js → raise-1db27a82.development.esm.js} +98 -72
- package/dist/{raise-e919c5d4.development.cjs.js → raise-4acdb210.development.cjs.js} +98 -72
- package/dist/{raise-b1e0b9a9.cjs.js → raise-60cebf03.cjs.js} +94 -70
- package/dist/{raise-0f7cf128.esm.js → raise-c17ec2bc.esm.js} +94 -70
- package/dist/xstate.cjs.js +57 -15
- package/dist/xstate.cjs.mjs +2 -0
- package/dist/xstate.development.cjs.js +57 -15
- package/dist/xstate.development.cjs.mjs +2 -0
- package/dist/xstate.development.esm.js +58 -18
- package/dist/xstate.esm.js +58 -18
- 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 +1 -1
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var actors_dist_xstateActors = require('../actors/dist/xstate-actors.development.cjs.js');
|
|
6
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
7
|
-
var log = require('./log-
|
|
6
|
+
var guards_dist_xstateGuards = require('./raise-4acdb210.development.cjs.js');
|
|
7
|
+
var log = require('./log-17337367.development.cjs.js');
|
|
8
8
|
require('../dev/dist/xstate-dev.development.cjs.js');
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -224,10 +224,10 @@ class StateNode {
|
|
|
224
224
|
systemId
|
|
225
225
|
} = invokeConfig;
|
|
226
226
|
const resolvedId = invokeConfig.id ?? guards_dist_xstateGuards.createInvokeId(this.id, i);
|
|
227
|
-
const
|
|
227
|
+
const sourceName = typeof src === 'string' ? src : `xstate.invoke.${guards_dist_xstateGuards.createInvokeId(this.id, i)}`;
|
|
228
228
|
return {
|
|
229
229
|
...invokeConfig,
|
|
230
|
-
src:
|
|
230
|
+
src: sourceName,
|
|
231
231
|
id: resolvedId,
|
|
232
232
|
systemId: systemId,
|
|
233
233
|
toJSON() {
|
|
@@ -239,7 +239,7 @@ class StateNode {
|
|
|
239
239
|
return {
|
|
240
240
|
...invokeDefValues,
|
|
241
241
|
type: 'xstate.invoke',
|
|
242
|
-
src:
|
|
242
|
+
src: sourceName,
|
|
243
243
|
id: resolvedId
|
|
244
244
|
};
|
|
245
245
|
}
|
|
@@ -425,7 +425,7 @@ class StateMachine {
|
|
|
425
425
|
* @param event The received event
|
|
426
426
|
*/
|
|
427
427
|
transition(snapshot, event, actorScope) {
|
|
428
|
-
return guards_dist_xstateGuards.macrostep(snapshot, event, actorScope).snapshot;
|
|
428
|
+
return guards_dist_xstateGuards.macrostep(snapshot, event, actorScope, []).snapshot;
|
|
429
429
|
}
|
|
430
430
|
|
|
431
431
|
/**
|
|
@@ -436,7 +436,7 @@ class StateMachine {
|
|
|
436
436
|
* @param event The received event
|
|
437
437
|
*/
|
|
438
438
|
microstep(snapshot, event, actorScope) {
|
|
439
|
-
return guards_dist_xstateGuards.macrostep(snapshot, event, actorScope).microstates;
|
|
439
|
+
return guards_dist_xstateGuards.macrostep(snapshot, event, actorScope, []).microstates;
|
|
440
440
|
}
|
|
441
441
|
getTransitionData(snapshot, event) {
|
|
442
442
|
return guards_dist_xstateGuards.transitionNode(this.root, snapshot.value, snapshot, event) || [];
|
|
@@ -466,7 +466,7 @@ class StateMachine {
|
|
|
466
466
|
input: event.input,
|
|
467
467
|
self
|
|
468
468
|
});
|
|
469
|
-
return guards_dist_xstateGuards.resolveActionsAndContext(preInitial, initEvent, actorScope, [log.assign(assignment)], internalQueue);
|
|
469
|
+
return guards_dist_xstateGuards.resolveActionsAndContext(preInitial, initEvent, actorScope, [log.assign(assignment)], internalQueue, undefined);
|
|
470
470
|
}
|
|
471
471
|
return preInitial;
|
|
472
472
|
}
|
|
@@ -544,13 +544,13 @@ class StateMachine {
|
|
|
544
544
|
children,
|
|
545
545
|
_nodes: Array.from(guards_dist_xstateGuards.getAllStateNodes(guards_dist_xstateGuards.getStateNodes(this.root, snapshot.value)))
|
|
546
546
|
}, this);
|
|
547
|
-
|
|
547
|
+
const seen = new Set();
|
|
548
548
|
function reviveContext(contextPart, children) {
|
|
549
549
|
if (seen.has(contextPart)) {
|
|
550
550
|
return;
|
|
551
551
|
}
|
|
552
552
|
seen.add(contextPart);
|
|
553
|
-
for (
|
|
553
|
+
for (const key in contextPart) {
|
|
554
554
|
const value = contextPart[key];
|
|
555
555
|
if (value && typeof value === 'object') {
|
|
556
556
|
if ('xstate$$type' in value && value.xstate$$type === guards_dist_xstateGuards.$$ACTOR_TYPE) {
|
|
@@ -566,10 +566,6 @@ class StateMachine {
|
|
|
566
566
|
}
|
|
567
567
|
}
|
|
568
568
|
|
|
569
|
-
// this is not 100% accurate since we can't make parallel regions required in the result
|
|
570
|
-
// `TTestValue` doesn't encode this information anyhow for us to be able to do that
|
|
571
|
-
// this is fine for most practical use cases anyway though
|
|
572
|
-
|
|
573
569
|
/**
|
|
574
570
|
* Creates a state machine (statechart) with the given configuration.
|
|
575
571
|
*
|
|
@@ -627,10 +623,13 @@ function createInertActorScope(actorLogic) {
|
|
|
627
623
|
sessionId: '',
|
|
628
624
|
stopChild: () => {},
|
|
629
625
|
system: self.system,
|
|
630
|
-
emit: () => {}
|
|
626
|
+
emit: () => {},
|
|
627
|
+
actionExecutor: () => {}
|
|
631
628
|
};
|
|
632
629
|
return inertActorScope;
|
|
633
630
|
}
|
|
631
|
+
|
|
632
|
+
/** @deprecated Use `initialTransition(…)` instead. */
|
|
634
633
|
function getInitialSnapshot(actorLogic, ...[input]) {
|
|
635
634
|
const actorScope = createInertActorScope(actorLogic);
|
|
636
635
|
return actorLogic.getInitialSnapshot(actorScope, input);
|
|
@@ -643,6 +642,7 @@ function getInitialSnapshot(actorLogic, ...[input]) {
|
|
|
643
642
|
* If the `snapshot` is `undefined`, the initial snapshot of the `actorLogic` is
|
|
644
643
|
* used.
|
|
645
644
|
*
|
|
645
|
+
* @deprecated Use `transition(…)` instead.
|
|
646
646
|
* @example
|
|
647
647
|
*
|
|
648
648
|
* ```ts
|
|
@@ -697,6 +697,9 @@ function setup({
|
|
|
697
697
|
};
|
|
698
698
|
}
|
|
699
699
|
|
|
700
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
|
701
|
+
|
|
702
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
|
700
703
|
class SimulatedClock {
|
|
701
704
|
constructor() {
|
|
702
705
|
this.timeouts = new Map();
|
|
@@ -797,6 +800,39 @@ function toPromise(actor) {
|
|
|
797
800
|
});
|
|
798
801
|
}
|
|
799
802
|
|
|
803
|
+
/**
|
|
804
|
+
* Given actor `logic`, a `snapshot`, and an `event`, returns a tuple of the
|
|
805
|
+
* `nextSnapshot` and `actions` to execute.
|
|
806
|
+
*
|
|
807
|
+
* This is a pure function that does not execute `actions`.
|
|
808
|
+
*/
|
|
809
|
+
function transition(logic, snapshot, event) {
|
|
810
|
+
const executableActions = [];
|
|
811
|
+
const actorScope = createInertActorScope(logic);
|
|
812
|
+
actorScope.actionExecutor = action => {
|
|
813
|
+
executableActions.push(action);
|
|
814
|
+
};
|
|
815
|
+
const nextSnapshot = logic.transition(snapshot, event, actorScope);
|
|
816
|
+
return [nextSnapshot, executableActions];
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
/**
|
|
820
|
+
* Given actor `logic` and optional `input`, returns a tuple of the
|
|
821
|
+
* `nextSnapshot` and `actions` to execute from the initial transition (no
|
|
822
|
+
* previous state).
|
|
823
|
+
*
|
|
824
|
+
* This is a pure function that does not execute `actions`.
|
|
825
|
+
*/
|
|
826
|
+
function initialTransition(logic, ...[input]) {
|
|
827
|
+
const executableActions = [];
|
|
828
|
+
const actorScope = createInertActorScope(logic);
|
|
829
|
+
actorScope.actionExecutor = action => {
|
|
830
|
+
executableActions.push(action);
|
|
831
|
+
};
|
|
832
|
+
const nextSnapshot = logic.getInitialSnapshot(actorScope, input);
|
|
833
|
+
return [nextSnapshot, executableActions];
|
|
834
|
+
}
|
|
835
|
+
|
|
800
836
|
const defaultWaitForOptions = {
|
|
801
837
|
timeout: Infinity // much more than 10 seconds
|
|
802
838
|
};
|
|
@@ -832,6 +868,7 @@ function waitFor(actorRef, predicate, options) {
|
|
|
832
868
|
signal
|
|
833
869
|
} = resolvedOptions;
|
|
834
870
|
if (signal?.aborted) {
|
|
871
|
+
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
835
872
|
rej(signal.reason);
|
|
836
873
|
return;
|
|
837
874
|
}
|
|
@@ -863,6 +900,7 @@ function waitFor(actorRef, predicate, options) {
|
|
|
863
900
|
* `abort` event
|
|
864
901
|
*/
|
|
865
902
|
let abortListener;
|
|
903
|
+
// eslint-disable-next-line prefer-const
|
|
866
904
|
let sub; // avoid TDZ when disposing synchronously
|
|
867
905
|
|
|
868
906
|
// See if the current snapshot already matches the predicate
|
|
@@ -876,6 +914,7 @@ function waitFor(actorRef, predicate, options) {
|
|
|
876
914
|
abortListener = () => {
|
|
877
915
|
dispose();
|
|
878
916
|
// XState does not "own" the signal, so we should reject with its reason (if any)
|
|
917
|
+
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
879
918
|
rej(signal.reason);
|
|
880
919
|
};
|
|
881
920
|
signal.addEventListener('abort', abortListener);
|
|
@@ -884,6 +923,7 @@ function waitFor(actorRef, predicate, options) {
|
|
|
884
923
|
next: checkEmitted,
|
|
885
924
|
error: err => {
|
|
886
925
|
dispose();
|
|
926
|
+
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
887
927
|
rej(err);
|
|
888
928
|
},
|
|
889
929
|
complete: () => {
|
|
@@ -936,6 +976,8 @@ exports.assertEvent = assertEvent;
|
|
|
936
976
|
exports.createMachine = createMachine;
|
|
937
977
|
exports.getInitialSnapshot = getInitialSnapshot;
|
|
938
978
|
exports.getNextSnapshot = getNextSnapshot;
|
|
979
|
+
exports.initialTransition = initialTransition;
|
|
939
980
|
exports.setup = setup;
|
|
940
981
|
exports.toPromise = toPromise;
|
|
982
|
+
exports.transition = transition;
|
|
941
983
|
exports.waitFor = waitFor;
|
|
@@ -23,6 +23,7 @@ export {
|
|
|
23
23
|
getInitialSnapshot,
|
|
24
24
|
getNextSnapshot,
|
|
25
25
|
getStateNodes,
|
|
26
|
+
initialTransition,
|
|
26
27
|
interpret,
|
|
27
28
|
isMachineSnapshot,
|
|
28
29
|
log,
|
|
@@ -40,5 +41,6 @@ export {
|
|
|
40
41
|
stopChild,
|
|
41
42
|
toObserver,
|
|
42
43
|
toPromise,
|
|
44
|
+
transition,
|
|
43
45
|
waitFor
|
|
44
46
|
} from "./xstate.development.cjs.js";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { createEmptyActor, fromCallback, fromEventObservable, fromObservable, fromPromise, fromTransition } from '../actors/dist/xstate-actors.development.esm.js';
|
|
2
|
-
import { t as toArray, S as STATE_DELIMITER, m as mapValues, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, e as evaluateGuard, c as createInvokeId, g as getDelayedTransitions, d as formatInitialTransition, h as getCandidates, r as resolveStateValue, i as getAllStateNodes, j as getStateNodes, k as createMachineSnapshot, l as isInFinalState, n as macrostep, o as transitionNode, p as resolveActionsAndContext, q as createInitEvent, s as microstep, u as getInitialStateNodes, v as toStatePath, w as isStateId, x as getStateNodeByPath, y as getPersistedSnapshot, z as resolveReferencedActor, A as createActor, $ as $$ACTOR_TYPE } from './raise-
|
|
3
|
-
export { B as Actor, I as __unsafe_getAllOwnEventDescriptors, D as and, M as cancel, A as createActor, j as getStateNodes, C as interpret, H as isMachineSnapshot, J as matchesState, E as not, F as or, K as pathToStateValue, O as raise, P as spawnChild, G as stateIn, Q as stop, R as stopChild, L as toObserver } from './raise-
|
|
4
|
-
import { a as assign } from './log-
|
|
5
|
-
export { S as SpecialTargets, a as assign, e as emit, b as enqueueActions, f as forwardTo, l as log, s as sendParent, c as sendTo } from './log-
|
|
2
|
+
import { t as toArray, S as STATE_DELIMITER, m as mapValues, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, e as evaluateGuard, c as createInvokeId, g as getDelayedTransitions, d as formatInitialTransition, h as getCandidates, r as resolveStateValue, i as getAllStateNodes, j as getStateNodes, k as createMachineSnapshot, l as isInFinalState, n as macrostep, o as transitionNode, p as resolveActionsAndContext, q as createInitEvent, s as microstep, u as getInitialStateNodes, v as toStatePath, w as isStateId, x as getStateNodeByPath, y as getPersistedSnapshot, z as resolveReferencedActor, A as createActor, $ as $$ACTOR_TYPE } from './raise-1db27a82.development.esm.js';
|
|
3
|
+
export { B as Actor, I as __unsafe_getAllOwnEventDescriptors, D as and, M as cancel, A as createActor, j as getStateNodes, C as interpret, H as isMachineSnapshot, J as matchesState, E as not, F as or, K as pathToStateValue, O as raise, P as spawnChild, G as stateIn, Q as stop, R as stopChild, L as toObserver } from './raise-1db27a82.development.esm.js';
|
|
4
|
+
import { a as assign } from './log-ef30c65f.development.esm.js';
|
|
5
|
+
export { S as SpecialTargets, a as assign, e as emit, b as enqueueActions, f as forwardTo, l as log, s as sendParent, c as sendTo } from './log-ef30c65f.development.esm.js';
|
|
6
6
|
import '../dev/dist/xstate-dev.development.esm.js';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -222,10 +222,10 @@ class StateNode {
|
|
|
222
222
|
systemId
|
|
223
223
|
} = invokeConfig;
|
|
224
224
|
const resolvedId = invokeConfig.id ?? createInvokeId(this.id, i);
|
|
225
|
-
const
|
|
225
|
+
const sourceName = typeof src === 'string' ? src : `xstate.invoke.${createInvokeId(this.id, i)}`;
|
|
226
226
|
return {
|
|
227
227
|
...invokeConfig,
|
|
228
|
-
src:
|
|
228
|
+
src: sourceName,
|
|
229
229
|
id: resolvedId,
|
|
230
230
|
systemId: systemId,
|
|
231
231
|
toJSON() {
|
|
@@ -237,7 +237,7 @@ class StateNode {
|
|
|
237
237
|
return {
|
|
238
238
|
...invokeDefValues,
|
|
239
239
|
type: 'xstate.invoke',
|
|
240
|
-
src:
|
|
240
|
+
src: sourceName,
|
|
241
241
|
id: resolvedId
|
|
242
242
|
};
|
|
243
243
|
}
|
|
@@ -423,7 +423,7 @@ class StateMachine {
|
|
|
423
423
|
* @param event The received event
|
|
424
424
|
*/
|
|
425
425
|
transition(snapshot, event, actorScope) {
|
|
426
|
-
return macrostep(snapshot, event, actorScope).snapshot;
|
|
426
|
+
return macrostep(snapshot, event, actorScope, []).snapshot;
|
|
427
427
|
}
|
|
428
428
|
|
|
429
429
|
/**
|
|
@@ -434,7 +434,7 @@ class StateMachine {
|
|
|
434
434
|
* @param event The received event
|
|
435
435
|
*/
|
|
436
436
|
microstep(snapshot, event, actorScope) {
|
|
437
|
-
return macrostep(snapshot, event, actorScope).microstates;
|
|
437
|
+
return macrostep(snapshot, event, actorScope, []).microstates;
|
|
438
438
|
}
|
|
439
439
|
getTransitionData(snapshot, event) {
|
|
440
440
|
return transitionNode(this.root, snapshot.value, snapshot, event) || [];
|
|
@@ -464,7 +464,7 @@ class StateMachine {
|
|
|
464
464
|
input: event.input,
|
|
465
465
|
self
|
|
466
466
|
});
|
|
467
|
-
return resolveActionsAndContext(preInitial, initEvent, actorScope, [assign(assignment)], internalQueue);
|
|
467
|
+
return resolveActionsAndContext(preInitial, initEvent, actorScope, [assign(assignment)], internalQueue, undefined);
|
|
468
468
|
}
|
|
469
469
|
return preInitial;
|
|
470
470
|
}
|
|
@@ -542,13 +542,13 @@ class StateMachine {
|
|
|
542
542
|
children,
|
|
543
543
|
_nodes: Array.from(getAllStateNodes(getStateNodes(this.root, snapshot.value)))
|
|
544
544
|
}, this);
|
|
545
|
-
|
|
545
|
+
const seen = new Set();
|
|
546
546
|
function reviveContext(contextPart, children) {
|
|
547
547
|
if (seen.has(contextPart)) {
|
|
548
548
|
return;
|
|
549
549
|
}
|
|
550
550
|
seen.add(contextPart);
|
|
551
|
-
for (
|
|
551
|
+
for (const key in contextPart) {
|
|
552
552
|
const value = contextPart[key];
|
|
553
553
|
if (value && typeof value === 'object') {
|
|
554
554
|
if ('xstate$$type' in value && value.xstate$$type === $$ACTOR_TYPE) {
|
|
@@ -564,10 +564,6 @@ class StateMachine {
|
|
|
564
564
|
}
|
|
565
565
|
}
|
|
566
566
|
|
|
567
|
-
// this is not 100% accurate since we can't make parallel regions required in the result
|
|
568
|
-
// `TTestValue` doesn't encode this information anyhow for us to be able to do that
|
|
569
|
-
// this is fine for most practical use cases anyway though
|
|
570
|
-
|
|
571
567
|
/**
|
|
572
568
|
* Creates a state machine (statechart) with the given configuration.
|
|
573
569
|
*
|
|
@@ -625,10 +621,13 @@ function createInertActorScope(actorLogic) {
|
|
|
625
621
|
sessionId: '',
|
|
626
622
|
stopChild: () => {},
|
|
627
623
|
system: self.system,
|
|
628
|
-
emit: () => {}
|
|
624
|
+
emit: () => {},
|
|
625
|
+
actionExecutor: () => {}
|
|
629
626
|
};
|
|
630
627
|
return inertActorScope;
|
|
631
628
|
}
|
|
629
|
+
|
|
630
|
+
/** @deprecated Use `initialTransition(…)` instead. */
|
|
632
631
|
function getInitialSnapshot(actorLogic, ...[input]) {
|
|
633
632
|
const actorScope = createInertActorScope(actorLogic);
|
|
634
633
|
return actorLogic.getInitialSnapshot(actorScope, input);
|
|
@@ -641,6 +640,7 @@ function getInitialSnapshot(actorLogic, ...[input]) {
|
|
|
641
640
|
* If the `snapshot` is `undefined`, the initial snapshot of the `actorLogic` is
|
|
642
641
|
* used.
|
|
643
642
|
*
|
|
643
|
+
* @deprecated Use `transition(…)` instead.
|
|
644
644
|
* @example
|
|
645
645
|
*
|
|
646
646
|
* ```ts
|
|
@@ -695,6 +695,9 @@ function setup({
|
|
|
695
695
|
};
|
|
696
696
|
}
|
|
697
697
|
|
|
698
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
|
699
|
+
|
|
700
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
|
698
701
|
class SimulatedClock {
|
|
699
702
|
constructor() {
|
|
700
703
|
this.timeouts = new Map();
|
|
@@ -795,6 +798,39 @@ function toPromise(actor) {
|
|
|
795
798
|
});
|
|
796
799
|
}
|
|
797
800
|
|
|
801
|
+
/**
|
|
802
|
+
* Given actor `logic`, a `snapshot`, and an `event`, returns a tuple of the
|
|
803
|
+
* `nextSnapshot` and `actions` to execute.
|
|
804
|
+
*
|
|
805
|
+
* This is a pure function that does not execute `actions`.
|
|
806
|
+
*/
|
|
807
|
+
function transition(logic, snapshot, event) {
|
|
808
|
+
const executableActions = [];
|
|
809
|
+
const actorScope = createInertActorScope(logic);
|
|
810
|
+
actorScope.actionExecutor = action => {
|
|
811
|
+
executableActions.push(action);
|
|
812
|
+
};
|
|
813
|
+
const nextSnapshot = logic.transition(snapshot, event, actorScope);
|
|
814
|
+
return [nextSnapshot, executableActions];
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
/**
|
|
818
|
+
* Given actor `logic` and optional `input`, returns a tuple of the
|
|
819
|
+
* `nextSnapshot` and `actions` to execute from the initial transition (no
|
|
820
|
+
* previous state).
|
|
821
|
+
*
|
|
822
|
+
* This is a pure function that does not execute `actions`.
|
|
823
|
+
*/
|
|
824
|
+
function initialTransition(logic, ...[input]) {
|
|
825
|
+
const executableActions = [];
|
|
826
|
+
const actorScope = createInertActorScope(logic);
|
|
827
|
+
actorScope.actionExecutor = action => {
|
|
828
|
+
executableActions.push(action);
|
|
829
|
+
};
|
|
830
|
+
const nextSnapshot = logic.getInitialSnapshot(actorScope, input);
|
|
831
|
+
return [nextSnapshot, executableActions];
|
|
832
|
+
}
|
|
833
|
+
|
|
798
834
|
const defaultWaitForOptions = {
|
|
799
835
|
timeout: Infinity // much more than 10 seconds
|
|
800
836
|
};
|
|
@@ -830,6 +866,7 @@ function waitFor(actorRef, predicate, options) {
|
|
|
830
866
|
signal
|
|
831
867
|
} = resolvedOptions;
|
|
832
868
|
if (signal?.aborted) {
|
|
869
|
+
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
833
870
|
rej(signal.reason);
|
|
834
871
|
return;
|
|
835
872
|
}
|
|
@@ -861,6 +898,7 @@ function waitFor(actorRef, predicate, options) {
|
|
|
861
898
|
* `abort` event
|
|
862
899
|
*/
|
|
863
900
|
let abortListener;
|
|
901
|
+
// eslint-disable-next-line prefer-const
|
|
864
902
|
let sub; // avoid TDZ when disposing synchronously
|
|
865
903
|
|
|
866
904
|
// See if the current snapshot already matches the predicate
|
|
@@ -874,6 +912,7 @@ function waitFor(actorRef, predicate, options) {
|
|
|
874
912
|
abortListener = () => {
|
|
875
913
|
dispose();
|
|
876
914
|
// XState does not "own" the signal, so we should reject with its reason (if any)
|
|
915
|
+
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
877
916
|
rej(signal.reason);
|
|
878
917
|
};
|
|
879
918
|
signal.addEventListener('abort', abortListener);
|
|
@@ -882,6 +921,7 @@ function waitFor(actorRef, predicate, options) {
|
|
|
882
921
|
next: checkEmitted,
|
|
883
922
|
error: err => {
|
|
884
923
|
dispose();
|
|
924
|
+
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
885
925
|
rej(err);
|
|
886
926
|
},
|
|
887
927
|
complete: () => {
|
|
@@ -895,4 +935,4 @@ function waitFor(actorRef, predicate, options) {
|
|
|
895
935
|
});
|
|
896
936
|
}
|
|
897
937
|
|
|
898
|
-
export { SimulatedClock, StateMachine, StateNode, assertEvent, createMachine, getInitialSnapshot, getNextSnapshot, setup, toPromise, waitFor };
|
|
938
|
+
export { SimulatedClock, StateMachine, StateNode, assertEvent, createMachine, getInitialSnapshot, getNextSnapshot, initialTransition, setup, toPromise, transition, waitFor };
|
package/dist/xstate.esm.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { createEmptyActor, fromCallback, fromEventObservable, fromObservable, fromPromise, fromTransition } from '../actors/dist/xstate-actors.esm.js';
|
|
2
|
-
import { t as toArray, S as STATE_DELIMITER, m as mapValues, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, e as evaluateGuard, c as createInvokeId, g as getDelayedTransitions, d as formatInitialTransition, h as getCandidates, r as resolveStateValue, i as getAllStateNodes, j as getStateNodes, k as createMachineSnapshot, l as isInFinalState, n as macrostep, o as transitionNode, p as resolveActionsAndContext, q as createInitEvent, s as microstep, u as getInitialStateNodes, v as toStatePath, w as isStateId, x as getStateNodeByPath, y as getPersistedSnapshot, z as resolveReferencedActor, A as createActor, $ as $$ACTOR_TYPE } from './raise-
|
|
3
|
-
export { B as Actor, I as __unsafe_getAllOwnEventDescriptors, D as and, M as cancel, A as createActor, j as getStateNodes, C as interpret, H as isMachineSnapshot, J as matchesState, E as not, F as or, K as pathToStateValue, O as raise, P as spawnChild, G as stateIn, Q as stop, R as stopChild, L as toObserver } from './raise-
|
|
4
|
-
import { a as assign } from './log-
|
|
5
|
-
export { S as SpecialTargets, a as assign, e as emit, b as enqueueActions, f as forwardTo, l as log, s as sendParent, c as sendTo } from './log-
|
|
2
|
+
import { t as toArray, S as STATE_DELIMITER, m as mapValues, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, e as evaluateGuard, c as createInvokeId, g as getDelayedTransitions, d as formatInitialTransition, h as getCandidates, r as resolveStateValue, i as getAllStateNodes, j as getStateNodes, k as createMachineSnapshot, l as isInFinalState, n as macrostep, o as transitionNode, p as resolveActionsAndContext, q as createInitEvent, s as microstep, u as getInitialStateNodes, v as toStatePath, w as isStateId, x as getStateNodeByPath, y as getPersistedSnapshot, z as resolveReferencedActor, A as createActor, $ as $$ACTOR_TYPE } from './raise-c17ec2bc.esm.js';
|
|
3
|
+
export { B as Actor, I as __unsafe_getAllOwnEventDescriptors, D as and, M as cancel, A as createActor, j as getStateNodes, C as interpret, H as isMachineSnapshot, J as matchesState, E as not, F as or, K as pathToStateValue, O as raise, P as spawnChild, G as stateIn, Q as stop, R as stopChild, L as toObserver } from './raise-c17ec2bc.esm.js';
|
|
4
|
+
import { a as assign } from './log-2a773d37.esm.js';
|
|
5
|
+
export { S as SpecialTargets, a as assign, e as emit, b as enqueueActions, f as forwardTo, l as log, s as sendParent, c as sendTo } from './log-2a773d37.esm.js';
|
|
6
6
|
import '../dev/dist/xstate-dev.esm.js';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -222,10 +222,10 @@ class StateNode {
|
|
|
222
222
|
systemId
|
|
223
223
|
} = invokeConfig;
|
|
224
224
|
const resolvedId = invokeConfig.id ?? createInvokeId(this.id, i);
|
|
225
|
-
const
|
|
225
|
+
const sourceName = typeof src === 'string' ? src : `xstate.invoke.${createInvokeId(this.id, i)}`;
|
|
226
226
|
return {
|
|
227
227
|
...invokeConfig,
|
|
228
|
-
src:
|
|
228
|
+
src: sourceName,
|
|
229
229
|
id: resolvedId,
|
|
230
230
|
systemId: systemId,
|
|
231
231
|
toJSON() {
|
|
@@ -237,7 +237,7 @@ class StateNode {
|
|
|
237
237
|
return {
|
|
238
238
|
...invokeDefValues,
|
|
239
239
|
type: 'xstate.invoke',
|
|
240
|
-
src:
|
|
240
|
+
src: sourceName,
|
|
241
241
|
id: resolvedId
|
|
242
242
|
};
|
|
243
243
|
}
|
|
@@ -420,7 +420,7 @@ class StateMachine {
|
|
|
420
420
|
* @param event The received event
|
|
421
421
|
*/
|
|
422
422
|
transition(snapshot, event, actorScope) {
|
|
423
|
-
return macrostep(snapshot, event, actorScope).snapshot;
|
|
423
|
+
return macrostep(snapshot, event, actorScope, []).snapshot;
|
|
424
424
|
}
|
|
425
425
|
|
|
426
426
|
/**
|
|
@@ -431,7 +431,7 @@ class StateMachine {
|
|
|
431
431
|
* @param event The received event
|
|
432
432
|
*/
|
|
433
433
|
microstep(snapshot, event, actorScope) {
|
|
434
|
-
return macrostep(snapshot, event, actorScope).microstates;
|
|
434
|
+
return macrostep(snapshot, event, actorScope, []).microstates;
|
|
435
435
|
}
|
|
436
436
|
getTransitionData(snapshot, event) {
|
|
437
437
|
return transitionNode(this.root, snapshot.value, snapshot, event) || [];
|
|
@@ -461,7 +461,7 @@ class StateMachine {
|
|
|
461
461
|
input: event.input,
|
|
462
462
|
self
|
|
463
463
|
});
|
|
464
|
-
return resolveActionsAndContext(preInitial, initEvent, actorScope, [assign(assignment)], internalQueue);
|
|
464
|
+
return resolveActionsAndContext(preInitial, initEvent, actorScope, [assign(assignment)], internalQueue, undefined);
|
|
465
465
|
}
|
|
466
466
|
return preInitial;
|
|
467
467
|
}
|
|
@@ -539,13 +539,13 @@ class StateMachine {
|
|
|
539
539
|
children,
|
|
540
540
|
_nodes: Array.from(getAllStateNodes(getStateNodes(this.root, snapshot.value)))
|
|
541
541
|
}, this);
|
|
542
|
-
|
|
542
|
+
const seen = new Set();
|
|
543
543
|
function reviveContext(contextPart, children) {
|
|
544
544
|
if (seen.has(contextPart)) {
|
|
545
545
|
return;
|
|
546
546
|
}
|
|
547
547
|
seen.add(contextPart);
|
|
548
|
-
for (
|
|
548
|
+
for (const key in contextPart) {
|
|
549
549
|
const value = contextPart[key];
|
|
550
550
|
if (value && typeof value === 'object') {
|
|
551
551
|
if ('xstate$$type' in value && value.xstate$$type === $$ACTOR_TYPE) {
|
|
@@ -561,10 +561,6 @@ class StateMachine {
|
|
|
561
561
|
}
|
|
562
562
|
}
|
|
563
563
|
|
|
564
|
-
// this is not 100% accurate since we can't make parallel regions required in the result
|
|
565
|
-
// `TTestValue` doesn't encode this information anyhow for us to be able to do that
|
|
566
|
-
// this is fine for most practical use cases anyway though
|
|
567
|
-
|
|
568
564
|
/**
|
|
569
565
|
* Creates a state machine (statechart) with the given configuration.
|
|
570
566
|
*
|
|
@@ -622,10 +618,13 @@ function createInertActorScope(actorLogic) {
|
|
|
622
618
|
sessionId: '',
|
|
623
619
|
stopChild: () => {},
|
|
624
620
|
system: self.system,
|
|
625
|
-
emit: () => {}
|
|
621
|
+
emit: () => {},
|
|
622
|
+
actionExecutor: () => {}
|
|
626
623
|
};
|
|
627
624
|
return inertActorScope;
|
|
628
625
|
}
|
|
626
|
+
|
|
627
|
+
/** @deprecated Use `initialTransition(…)` instead. */
|
|
629
628
|
function getInitialSnapshot(actorLogic, ...[input]) {
|
|
630
629
|
const actorScope = createInertActorScope(actorLogic);
|
|
631
630
|
return actorLogic.getInitialSnapshot(actorScope, input);
|
|
@@ -638,6 +637,7 @@ function getInitialSnapshot(actorLogic, ...[input]) {
|
|
|
638
637
|
* If the `snapshot` is `undefined`, the initial snapshot of the `actorLogic` is
|
|
639
638
|
* used.
|
|
640
639
|
*
|
|
640
|
+
* @deprecated Use `transition(…)` instead.
|
|
641
641
|
* @example
|
|
642
642
|
*
|
|
643
643
|
* ```ts
|
|
@@ -692,6 +692,9 @@ function setup({
|
|
|
692
692
|
};
|
|
693
693
|
}
|
|
694
694
|
|
|
695
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
|
696
|
+
|
|
697
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
|
695
698
|
class SimulatedClock {
|
|
696
699
|
constructor() {
|
|
697
700
|
this.timeouts = new Map();
|
|
@@ -792,6 +795,39 @@ function toPromise(actor) {
|
|
|
792
795
|
});
|
|
793
796
|
}
|
|
794
797
|
|
|
798
|
+
/**
|
|
799
|
+
* Given actor `logic`, a `snapshot`, and an `event`, returns a tuple of the
|
|
800
|
+
* `nextSnapshot` and `actions` to execute.
|
|
801
|
+
*
|
|
802
|
+
* This is a pure function that does not execute `actions`.
|
|
803
|
+
*/
|
|
804
|
+
function transition(logic, snapshot, event) {
|
|
805
|
+
const executableActions = [];
|
|
806
|
+
const actorScope = createInertActorScope(logic);
|
|
807
|
+
actorScope.actionExecutor = action => {
|
|
808
|
+
executableActions.push(action);
|
|
809
|
+
};
|
|
810
|
+
const nextSnapshot = logic.transition(snapshot, event, actorScope);
|
|
811
|
+
return [nextSnapshot, executableActions];
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
/**
|
|
815
|
+
* Given actor `logic` and optional `input`, returns a tuple of the
|
|
816
|
+
* `nextSnapshot` and `actions` to execute from the initial transition (no
|
|
817
|
+
* previous state).
|
|
818
|
+
*
|
|
819
|
+
* This is a pure function that does not execute `actions`.
|
|
820
|
+
*/
|
|
821
|
+
function initialTransition(logic, ...[input]) {
|
|
822
|
+
const executableActions = [];
|
|
823
|
+
const actorScope = createInertActorScope(logic);
|
|
824
|
+
actorScope.actionExecutor = action => {
|
|
825
|
+
executableActions.push(action);
|
|
826
|
+
};
|
|
827
|
+
const nextSnapshot = logic.getInitialSnapshot(actorScope, input);
|
|
828
|
+
return [nextSnapshot, executableActions];
|
|
829
|
+
}
|
|
830
|
+
|
|
795
831
|
const defaultWaitForOptions = {
|
|
796
832
|
timeout: Infinity // much more than 10 seconds
|
|
797
833
|
};
|
|
@@ -827,6 +863,7 @@ function waitFor(actorRef, predicate, options) {
|
|
|
827
863
|
signal
|
|
828
864
|
} = resolvedOptions;
|
|
829
865
|
if (signal?.aborted) {
|
|
866
|
+
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
830
867
|
rej(signal.reason);
|
|
831
868
|
return;
|
|
832
869
|
}
|
|
@@ -855,6 +892,7 @@ function waitFor(actorRef, predicate, options) {
|
|
|
855
892
|
* `abort` event
|
|
856
893
|
*/
|
|
857
894
|
let abortListener;
|
|
895
|
+
// eslint-disable-next-line prefer-const
|
|
858
896
|
let sub; // avoid TDZ when disposing synchronously
|
|
859
897
|
|
|
860
898
|
// See if the current snapshot already matches the predicate
|
|
@@ -868,6 +906,7 @@ function waitFor(actorRef, predicate, options) {
|
|
|
868
906
|
abortListener = () => {
|
|
869
907
|
dispose();
|
|
870
908
|
// XState does not "own" the signal, so we should reject with its reason (if any)
|
|
909
|
+
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
871
910
|
rej(signal.reason);
|
|
872
911
|
};
|
|
873
912
|
signal.addEventListener('abort', abortListener);
|
|
@@ -876,6 +915,7 @@ function waitFor(actorRef, predicate, options) {
|
|
|
876
915
|
next: checkEmitted,
|
|
877
916
|
error: err => {
|
|
878
917
|
dispose();
|
|
918
|
+
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
879
919
|
rej(err);
|
|
880
920
|
},
|
|
881
921
|
complete: () => {
|
|
@@ -889,4 +929,4 @@ function waitFor(actorRef, predicate, options) {
|
|
|
889
929
|
});
|
|
890
930
|
}
|
|
891
931
|
|
|
892
|
-
export { SimulatedClock, StateMachine, StateNode, assertEvent, createMachine, getInitialSnapshot, getNextSnapshot, setup, toPromise, waitFor };
|
|
932
|
+
export { SimulatedClock, StateMachine, StateNode, assertEvent, createMachine, getInitialSnapshot, getNextSnapshot, initialTransition, setup, toPromise, transition, waitFor };
|