xstate 5.0.0-beta.36 → 5.0.0-beta.38
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 +4 -3
- package/actions/dist/xstate-actions.cjs.mjs +1 -0
- package/actions/dist/xstate-actions.development.cjs.js +4 -3
- package/actions/dist/xstate-actions.development.cjs.mjs +1 -0
- package/actions/dist/xstate-actions.development.esm.js +3 -3
- package/actions/dist/xstate-actions.esm.js +3 -3
- 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/declarations/src/State.d.ts +2 -2
- package/dist/declarations/src/StateMachine.d.ts +4 -4
- package/dist/declarations/src/actions/assign.d.ts +4 -4
- package/dist/declarations/src/actions/cancel.d.ts +4 -4
- package/dist/declarations/src/actions/choose.d.ts +3 -3
- package/dist/declarations/src/actions/log.d.ts +4 -4
- package/dist/declarations/src/actions/pure.d.ts +4 -4
- package/dist/declarations/src/actions/raise.d.ts +3 -3
- package/dist/declarations/src/actions/send.d.ts +7 -7
- package/dist/declarations/src/actions/spawn.d.ts +34 -0
- package/dist/declarations/src/actions/stop.d.ts +4 -4
- package/dist/declarations/src/actions.d.ts +1 -0
- package/dist/declarations/src/actors/callback.d.ts +2 -2
- package/dist/declarations/src/actors/observable.d.ts +2 -3
- package/dist/declarations/src/actors/promise.d.ts +0 -1
- package/dist/declarations/src/actors/transition.d.ts +1 -1
- package/dist/declarations/src/guards.d.ts +9 -10
- package/dist/declarations/src/interpreter.d.ts +2 -2
- package/dist/declarations/src/spawn.d.ts +1 -2
- package/dist/declarations/src/stateUtils.d.ts +0 -5
- package/dist/declarations/src/typegenTypes.d.ts +2 -0
- package/dist/declarations/src/types.d.ts +47 -58
- package/dist/declarations/src/utils.d.ts +6 -6
- package/dist/declarations/src/waitFor.d.ts +1 -1
- package/dist/{interpreter-5c4e6634.development.esm.js → interpreter-4005eb36.development.esm.js} +14 -24
- package/dist/{interpreter-69605bf0.cjs.js → interpreter-b6f22ee2.cjs.js} +14 -24
- package/dist/{interpreter-de5217bc.esm.js → interpreter-c80ce92e.esm.js} +14 -24
- package/dist/{interpreter-d3567419.development.cjs.js → interpreter-ed3f81f7.development.cjs.js} +14 -24
- package/dist/{raise-5b7ad3b7.development.esm.js → raise-42073973.development.esm.js} +138 -118
- package/dist/{raise-c51b81a3.cjs.js → raise-7faa9b3b.cjs.js} +139 -118
- package/dist/{raise-106ea558.development.cjs.js → raise-b69a3d16.development.cjs.js} +138 -117
- package/dist/{raise-ffe1014a.esm.js → raise-c989c7fb.esm.js} +139 -119
- package/dist/{send-778692de.cjs.js → send-34160163.cjs.js} +31 -27
- package/dist/{send-0a7aa74e.esm.js → send-4b616da9.esm.js} +31 -27
- package/dist/{send-25e70bd4.development.cjs.js → send-58725522.development.cjs.js} +31 -27
- package/dist/{send-e93554d6.development.esm.js → send-bff8c910.development.esm.js} +31 -27
- package/dist/xstate.cjs.js +11 -16
- package/dist/xstate.cjs.mjs +1 -0
- package/dist/xstate.development.cjs.js +11 -16
- package/dist/xstate.development.cjs.mjs +1 -0
- package/dist/xstate.development.esm.js +13 -19
- package/dist/xstate.esm.js +13 -19
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.js +2 -2
- package/guards/dist/xstate-guards.development.cjs.js +2 -2
- package/guards/dist/xstate-guards.development.esm.js +2 -2
- package/guards/dist/xstate-guards.esm.js +2 -2
- 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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as resolveReferencedActor, d as createActor, f as ActorStatus, j as createErrorActorEvent, k as toStateValue, l as STATE_IDENTIFIER, n as normalizeTarget, t as toArray, N as NULL_EVENT, a as toTransitionConfigArray, S as STATE_DELIMITER, o as toStatePath, q as createDoneStateEvent, s as resolveOutput, X as XSTATE_STOP, u as XSTATE_INIT, W as WILDCARD, v as createAfterEvent, w as flatten, e as matchesState, $ as $$ACTOR_TYPE } from './interpreter-
|
|
1
|
+
import { r as resolveReferencedActor, d as createActor, f as ActorStatus, j as createErrorActorEvent, k as toStateValue, l as STATE_IDENTIFIER, n as normalizeTarget, t as toArray, N as NULL_EVENT, a as toTransitionConfigArray, S as STATE_DELIMITER, o as toStatePath, q as createDoneStateEvent, s as resolveOutput, X as XSTATE_STOP, u as XSTATE_INIT, W as WILDCARD, v as createAfterEvent, w as flatten, e as matchesState, $ as $$ACTOR_TYPE } from './interpreter-c80ce92e.esm.js';
|
|
2
2
|
|
|
3
3
|
const cache = new WeakMap();
|
|
4
4
|
function memo(object, key, fn) {
|
|
@@ -14,10 +14,10 @@ function memo(object, key, fn) {
|
|
|
14
14
|
return memoizedData[key];
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
function resolveCancel(_, state, actionArgs, {
|
|
17
|
+
function resolveCancel(_, state, actionArgs, actionParams, {
|
|
18
18
|
sendId
|
|
19
19
|
}) {
|
|
20
|
-
const resolvedSendId = typeof sendId === 'function' ? sendId(actionArgs) : sendId;
|
|
20
|
+
const resolvedSendId = typeof sendId === 'function' ? sendId(actionArgs, actionParams) : sendId;
|
|
21
21
|
return [state, resolvedSendId];
|
|
22
22
|
}
|
|
23
23
|
function executeCancel(actorContext, resolvedSendId) {
|
|
@@ -31,7 +31,7 @@ function executeCancel(actorContext, resolvedSendId) {
|
|
|
31
31
|
* @param sendId The `id` of the `send(...)` action to cancel.
|
|
32
32
|
*/
|
|
33
33
|
function cancel(sendId) {
|
|
34
|
-
function cancel(
|
|
34
|
+
function cancel(args, params) {
|
|
35
35
|
}
|
|
36
36
|
cancel.type = 'xstate.cancel';
|
|
37
37
|
cancel.sendId = sendId;
|
|
@@ -40,21 +40,25 @@ function cancel(sendId) {
|
|
|
40
40
|
return cancel;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
function
|
|
43
|
+
function resolveSpawn(actorContext, state, actionArgs, _actionParams, {
|
|
44
44
|
id,
|
|
45
45
|
systemId,
|
|
46
46
|
src,
|
|
47
47
|
input,
|
|
48
48
|
syncSnapshot
|
|
49
49
|
}) {
|
|
50
|
-
const referenced = resolveReferencedActor(state.machine
|
|
50
|
+
const referenced = typeof src === 'string' ? resolveReferencedActor(state.machine, src) : {
|
|
51
|
+
src,
|
|
52
|
+
input: undefined
|
|
53
|
+
};
|
|
54
|
+
const resolvedId = typeof id === 'function' ? id(actionArgs) : id;
|
|
51
55
|
let actorRef;
|
|
52
56
|
if (referenced) {
|
|
53
57
|
// TODO: inline `input: undefined` should win over the referenced one
|
|
54
58
|
const configuredInput = input || referenced.input;
|
|
55
59
|
actorRef = createActor(referenced.src, {
|
|
56
|
-
id,
|
|
57
|
-
src,
|
|
60
|
+
id: resolvedId,
|
|
61
|
+
src: typeof src === 'string' ? src : undefined,
|
|
58
62
|
parent: actorContext?.self,
|
|
59
63
|
systemId,
|
|
60
64
|
input: typeof configuredInput === 'function' ? configuredInput({
|
|
@@ -73,23 +77,21 @@ function resolveInvoke(actorContext, state, actionArgs, {
|
|
|
73
77
|
});
|
|
74
78
|
}
|
|
75
79
|
},
|
|
76
|
-
error: () => {
|
|
77
|
-
/* TODO */
|
|
78
|
-
}
|
|
80
|
+
error: () => {}
|
|
79
81
|
});
|
|
80
82
|
}
|
|
81
83
|
}
|
|
82
84
|
return [cloneState(state, {
|
|
83
85
|
children: {
|
|
84
86
|
...state.children,
|
|
85
|
-
[
|
|
87
|
+
[resolvedId]: actorRef
|
|
86
88
|
}
|
|
87
89
|
}), {
|
|
88
90
|
id,
|
|
89
91
|
actorRef
|
|
90
92
|
}];
|
|
91
93
|
}
|
|
92
|
-
function
|
|
94
|
+
function executeSpawn(actorContext, {
|
|
93
95
|
id,
|
|
94
96
|
actorRef
|
|
95
97
|
}) {
|
|
@@ -108,33 +110,29 @@ function executeInvoke(actorContext, {
|
|
|
108
110
|
}
|
|
109
111
|
});
|
|
110
112
|
}
|
|
111
|
-
|
|
112
|
-
// we don't export this since it's an internal action that is not meant to be used in the user's code
|
|
113
|
-
|
|
114
|
-
function invoke({
|
|
113
|
+
function spawn(...[src, {
|
|
115
114
|
id,
|
|
116
115
|
systemId,
|
|
117
|
-
src,
|
|
118
116
|
input,
|
|
119
|
-
|
|
120
|
-
}) {
|
|
121
|
-
function
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
return
|
|
117
|
+
syncSnapshot = false
|
|
118
|
+
} = {}]) {
|
|
119
|
+
function spawn(args, params) {
|
|
120
|
+
}
|
|
121
|
+
spawn.type = 'xstate.spawn';
|
|
122
|
+
spawn.id = id;
|
|
123
|
+
spawn.systemId = systemId;
|
|
124
|
+
spawn.src = src;
|
|
125
|
+
spawn.input = input;
|
|
126
|
+
spawn.syncSnapshot = syncSnapshot;
|
|
127
|
+
spawn.resolve = resolveSpawn;
|
|
128
|
+
spawn.execute = executeSpawn;
|
|
129
|
+
return spawn;
|
|
132
130
|
}
|
|
133
131
|
|
|
134
|
-
function resolveStop(_, state, args, {
|
|
132
|
+
function resolveStop(_, state, args, actionParams, {
|
|
135
133
|
actorRef
|
|
136
134
|
}) {
|
|
137
|
-
const actorRefOrString = typeof actorRef === 'function' ? actorRef(args) : actorRef;
|
|
135
|
+
const actorRefOrString = typeof actorRef === 'function' ? actorRef(args, actionParams) : actorRef;
|
|
138
136
|
const resolvedActorRef = typeof actorRefOrString === 'string' ? state.children[actorRefOrString] : actorRefOrString;
|
|
139
137
|
let children = state.children;
|
|
140
138
|
if (resolvedActorRef) {
|
|
@@ -151,11 +149,22 @@ function executeStop(actorContext, actorRef) {
|
|
|
151
149
|
if (!actorRef) {
|
|
152
150
|
return;
|
|
153
151
|
}
|
|
152
|
+
|
|
153
|
+
// we need to eagerly unregister it here so a new actor with the same systemId can be registered immediately
|
|
154
|
+
// since we defer actual stopping of the actor but we don't defer actor creations (and we can't do that)
|
|
155
|
+
// this could throw on `systemId` collision, for example, when dealing with reentering transitions
|
|
156
|
+
actorContext.system._unregister(actorRef);
|
|
157
|
+
|
|
158
|
+
// this allows us to prevent an actor from being started if it gets stopped within the same macrostep
|
|
159
|
+
// this can happen, for example, when the invoking state is being exited immediately by an always transition
|
|
154
160
|
if (actorRef.status !== ActorStatus.Running) {
|
|
155
161
|
actorContext.stopChild(actorRef);
|
|
156
162
|
return;
|
|
157
163
|
}
|
|
158
|
-
//
|
|
164
|
+
// stopping a child enqueues a stop event in the child actor's mailbox
|
|
165
|
+
// we need for all of the already enqueued events to be processed before we stop the child
|
|
166
|
+
// the parent itself might want to send some events to a child (for example from exit actions on the invoking state)
|
|
167
|
+
// and we don't want to ignore those events
|
|
159
168
|
actorContext.defer(() => {
|
|
160
169
|
actorContext.stopChild(actorRef);
|
|
161
170
|
});
|
|
@@ -166,7 +175,7 @@ function executeStop(actorContext, actorRef) {
|
|
|
166
175
|
* @param actorRef The actor to stop.
|
|
167
176
|
*/
|
|
168
177
|
function stop(actorRef) {
|
|
169
|
-
function stop(
|
|
178
|
+
function stop(args, params) {
|
|
170
179
|
}
|
|
171
180
|
stop.type = 'xstate.stop';
|
|
172
181
|
stop.actorRef = actorRef;
|
|
@@ -179,12 +188,13 @@ function checkStateIn(state, _, {
|
|
|
179
188
|
stateValue
|
|
180
189
|
}) {
|
|
181
190
|
if (typeof stateValue === 'string' && isStateId(stateValue)) {
|
|
182
|
-
|
|
191
|
+
const target = state.machine.getStateNodeById(stateValue);
|
|
192
|
+
return state.configuration.some(sn => sn === target);
|
|
183
193
|
}
|
|
184
194
|
return state.matches(stateValue);
|
|
185
195
|
}
|
|
186
196
|
function stateIn(stateValue) {
|
|
187
|
-
function stateIn(
|
|
197
|
+
function stateIn(args, params) {
|
|
188
198
|
return false;
|
|
189
199
|
}
|
|
190
200
|
stateIn.check = checkStateIn;
|
|
@@ -200,7 +210,7 @@ function checkNot(state, {
|
|
|
200
210
|
return !evaluateGuard(guards[0], context, event, state);
|
|
201
211
|
}
|
|
202
212
|
function not(guard) {
|
|
203
|
-
function not(
|
|
213
|
+
function not(args, params) {
|
|
204
214
|
return false;
|
|
205
215
|
}
|
|
206
216
|
not.check = checkNot;
|
|
@@ -216,7 +226,7 @@ function checkAnd(state, {
|
|
|
216
226
|
return guards.every(guard => evaluateGuard(guard, context, event, state));
|
|
217
227
|
}
|
|
218
228
|
function and(guards) {
|
|
219
|
-
function and(
|
|
229
|
+
function and(args, params) {
|
|
220
230
|
return false;
|
|
221
231
|
}
|
|
222
232
|
and.check = checkAnd;
|
|
@@ -232,7 +242,7 @@ function checkOr(state, {
|
|
|
232
242
|
return guards.some(guard => evaluateGuard(guard, context, event, state));
|
|
233
243
|
}
|
|
234
244
|
function or(guards) {
|
|
235
|
-
function or(
|
|
245
|
+
function or(args, params) {
|
|
236
246
|
return false;
|
|
237
247
|
}
|
|
238
248
|
or.check = checkOr;
|
|
@@ -255,22 +265,17 @@ function evaluateGuard(guard, context, event, state) {
|
|
|
255
265
|
}
|
|
256
266
|
const guardArgs = {
|
|
257
267
|
context,
|
|
258
|
-
event
|
|
259
|
-
guard: isInline ? undefined : typeof guard === 'string' ? {
|
|
260
|
-
type: guard
|
|
261
|
-
} : typeof guard.params === 'function' ? {
|
|
262
|
-
type: guard.type,
|
|
263
|
-
params: guard.params({
|
|
264
|
-
context,
|
|
265
|
-
event
|
|
266
|
-
})
|
|
267
|
-
} : guard
|
|
268
|
+
event
|
|
268
269
|
};
|
|
270
|
+
const guardParams = isInline || typeof guard === 'string' ? undefined : 'params' in guard ? typeof guard.params === 'function' ? guard.params({
|
|
271
|
+
context,
|
|
272
|
+
event
|
|
273
|
+
}) : guard.params : undefined;
|
|
269
274
|
if (!('check' in resolved)) {
|
|
270
275
|
// the existing type of `.guards` assumes non-nullable `TExpressionGuard`
|
|
271
276
|
// inline guards expect `TExpressionGuard` to be set to `undefined`
|
|
272
277
|
// it's fine to cast this here, our logic makes sure that we call those 2 "variants" correctly
|
|
273
|
-
return resolved(guardArgs);
|
|
278
|
+
return resolved(guardArgs, guardParams);
|
|
274
279
|
}
|
|
275
280
|
const builtinGuard = resolved;
|
|
276
281
|
return builtinGuard.check(state, guardArgs, resolved // this holds all params
|
|
@@ -283,6 +288,9 @@ function getChildren(stateNode) {
|
|
|
283
288
|
}
|
|
284
289
|
function getProperAncestors(stateNode, toStateNode) {
|
|
285
290
|
const ancestors = [];
|
|
291
|
+
if (toStateNode === stateNode) {
|
|
292
|
+
return ancestors;
|
|
293
|
+
}
|
|
286
294
|
|
|
287
295
|
// add all ancestors
|
|
288
296
|
let m = stateNode.parent;
|
|
@@ -559,12 +567,14 @@ function resolveTarget(stateNode, targets) {
|
|
|
559
567
|
}
|
|
560
568
|
});
|
|
561
569
|
}
|
|
562
|
-
function
|
|
570
|
+
function resolveHistoryDefaultTransition(stateNode) {
|
|
563
571
|
const normalizedTarget = normalizeTarget(stateNode.config.target);
|
|
564
572
|
if (!normalizedTarget) {
|
|
565
|
-
return stateNode.parent.initial
|
|
573
|
+
return stateNode.parent.initial;
|
|
566
574
|
}
|
|
567
|
-
return
|
|
575
|
+
return {
|
|
576
|
+
target: normalizedTarget.map(t => typeof t === 'string' ? getStateNodeByPath(stateNode.parent, t) : t)
|
|
577
|
+
};
|
|
568
578
|
}
|
|
569
579
|
function isHistoryNode(stateNode) {
|
|
570
580
|
return stateNode.type === 'history';
|
|
@@ -791,9 +801,7 @@ function getEffectiveTargetStates(transition, historyValue) {
|
|
|
791
801
|
targets.add(node);
|
|
792
802
|
}
|
|
793
803
|
} else {
|
|
794
|
-
for (const node of getEffectiveTargetStates({
|
|
795
|
-
target: resolveHistoryTarget(targetNode)
|
|
796
|
-
}, historyValue)) {
|
|
804
|
+
for (const node of getEffectiveTargetStates(resolveHistoryDefaultTransition(targetNode), historyValue)) {
|
|
797
805
|
targets.add(node);
|
|
798
806
|
}
|
|
799
807
|
}
|
|
@@ -806,9 +814,9 @@ function getEffectiveTargetStates(transition, historyValue) {
|
|
|
806
814
|
function getTransitionDomain(transition, historyValue) {
|
|
807
815
|
const targetStates = getEffectiveTargetStates(transition, historyValue);
|
|
808
816
|
if (!targetStates) {
|
|
809
|
-
return
|
|
817
|
+
return;
|
|
810
818
|
}
|
|
811
|
-
if (!transition.reenter &&
|
|
819
|
+
if (!transition.reenter && targetStates.every(target => target === transition.source || isDescendant(target, transition.source))) {
|
|
812
820
|
return transition.source;
|
|
813
821
|
}
|
|
814
822
|
const lcca = findLCCA(targetStates.concat(transition.source));
|
|
@@ -819,6 +827,9 @@ function computeExitSet(transitions, configuration, historyValue) {
|
|
|
819
827
|
for (const t of transitions) {
|
|
820
828
|
if (t.target?.length) {
|
|
821
829
|
const domain = getTransitionDomain(t, historyValue);
|
|
830
|
+
if (t.reenter && t.source === domain) {
|
|
831
|
+
statesToExit.add(domain);
|
|
832
|
+
}
|
|
822
833
|
for (const stateNode of configuration) {
|
|
823
834
|
if (isDescendant(stateNode, domain)) {
|
|
824
835
|
statesToExit.add(stateNode);
|
|
@@ -842,11 +853,6 @@ function areConfigurationsEqual(previousConfiguration, nextConfigurationSet) {
|
|
|
842
853
|
|
|
843
854
|
/**
|
|
844
855
|
* https://www.w3.org/TR/scxml/#microstepProcedure
|
|
845
|
-
*
|
|
846
|
-
* @private
|
|
847
|
-
* @param transitions
|
|
848
|
-
* @param currentState
|
|
849
|
-
* @param mutConfiguration
|
|
850
856
|
*/
|
|
851
857
|
function microstep(transitions, currentState, actorCtx, event, isInitial, internalQueue) {
|
|
852
858
|
if (!transitions.length) {
|
|
@@ -895,6 +901,9 @@ function getMachineOutput(state, event, actorCtx, rootNode, rootCompletionNode)
|
|
|
895
901
|
function enterStates(currentState, event, actorCtx, filteredTransitions, mutConfiguration, internalQueue, historyValue, isInitial) {
|
|
896
902
|
let nextState = currentState;
|
|
897
903
|
const statesToEnter = new Set();
|
|
904
|
+
// those are states that were directly targeted or indirectly targeted by the explicit target
|
|
905
|
+
// in other words, those are states for which initial actions should be executed
|
|
906
|
+
// when we target `#deep_child` initial actions of its ancestors shouldn't be executed
|
|
898
907
|
const statesForDefaultEntry = new Set();
|
|
899
908
|
computeEntrySet(filteredTransitions, historyValue, statesForDefaultEntry, statesToEnter);
|
|
900
909
|
|
|
@@ -910,7 +919,10 @@ function enterStates(currentState, event, actorCtx, filteredTransitions, mutConf
|
|
|
910
919
|
// Add entry actions
|
|
911
920
|
actions.push(...stateNodeToEnter.entry);
|
|
912
921
|
for (const invokeDef of stateNodeToEnter.invoke) {
|
|
913
|
-
actions.push(
|
|
922
|
+
actions.push(spawn(invokeDef.src, {
|
|
923
|
+
...invokeDef,
|
|
924
|
+
syncSnapshot: !!invokeDef.onSnapshot
|
|
925
|
+
}));
|
|
914
926
|
}
|
|
915
927
|
if (statesForDefaultEntry.has(stateNodeToEnter)) {
|
|
916
928
|
const initialActions = stateNodeToEnter.initial.actions;
|
|
@@ -919,20 +931,16 @@ function enterStates(currentState, event, actorCtx, filteredTransitions, mutConf
|
|
|
919
931
|
nextState = resolveActionsAndContext(nextState, event, actorCtx, actions, internalQueue, stateNodeToEnter.invoke.map(invokeDef => invokeDef.id));
|
|
920
932
|
if (stateNodeToEnter.type === 'final') {
|
|
921
933
|
const parent = stateNodeToEnter.parent;
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
completedNodes.add(parent);
|
|
926
|
-
let rootCompletionNode = parent?.type === 'parallel' ? parent : stateNodeToEnter;
|
|
927
|
-
let ancestorMarker = parent?.parent;
|
|
928
|
-
if (ancestorMarker) {
|
|
934
|
+
let ancestorMarker = parent?.type === 'parallel' ? parent : parent?.parent;
|
|
935
|
+
let rootCompletionNode = ancestorMarker || stateNodeToEnter;
|
|
936
|
+
if (parent?.type === 'compound') {
|
|
929
937
|
internalQueue.push(createDoneStateEvent(parent.id, stateNodeToEnter.output ? resolveOutput(stateNodeToEnter.output, nextState.context, event, actorCtx.self) : undefined));
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
938
|
+
}
|
|
939
|
+
while (ancestorMarker?.type === 'parallel' && !completedNodes.has(ancestorMarker) && isInFinalState(mutConfiguration, ancestorMarker)) {
|
|
940
|
+
completedNodes.add(ancestorMarker);
|
|
941
|
+
internalQueue.push(createDoneStateEvent(ancestorMarker.id));
|
|
942
|
+
rootCompletionNode = ancestorMarker;
|
|
943
|
+
ancestorMarker = ancestorMarker.parent;
|
|
936
944
|
}
|
|
937
945
|
if (ancestorMarker) {
|
|
938
946
|
continue;
|
|
@@ -947,13 +955,24 @@ function enterStates(currentState, event, actorCtx, filteredTransitions, mutConf
|
|
|
947
955
|
}
|
|
948
956
|
function computeEntrySet(transitions, historyValue, statesForDefaultEntry, statesToEnter) {
|
|
949
957
|
for (const t of transitions) {
|
|
958
|
+
const domain = getTransitionDomain(t, historyValue);
|
|
950
959
|
for (const s of t.target || []) {
|
|
960
|
+
if (!isHistoryNode(s) && (
|
|
961
|
+
// if the target is different than the source then it will *definitely* be entered
|
|
962
|
+
t.source !== s ||
|
|
963
|
+
// we know that the domain can't lie within the source
|
|
964
|
+
// if it's different than the source then it's outside of it and it means that the target has to be entered as well
|
|
965
|
+
t.source !== domain ||
|
|
966
|
+
// reentering transitions always enter the target, even if it's the source itself
|
|
967
|
+
t.reenter)) {
|
|
968
|
+
statesToEnter.add(s);
|
|
969
|
+
statesForDefaultEntry.add(s);
|
|
970
|
+
}
|
|
951
971
|
addDescendantStatesToEnter(s, historyValue, statesForDefaultEntry, statesToEnter);
|
|
952
972
|
}
|
|
953
|
-
const ancestor = getTransitionDomain(t, historyValue);
|
|
954
973
|
const targetStates = getEffectiveTargetStates(t, historyValue);
|
|
955
974
|
for (const s of targetStates) {
|
|
956
|
-
addAncestorStatesToEnter(s,
|
|
975
|
+
addAncestorStatesToEnter(s, domain, statesToEnter, historyValue, statesForDefaultEntry);
|
|
957
976
|
}
|
|
958
977
|
}
|
|
959
978
|
}
|
|
@@ -962,37 +981,42 @@ function addDescendantStatesToEnter(stateNode, historyValue, statesForDefaultEnt
|
|
|
962
981
|
if (historyValue[stateNode.id]) {
|
|
963
982
|
const historyStateNodes = historyValue[stateNode.id];
|
|
964
983
|
for (const s of historyStateNodes) {
|
|
984
|
+
statesToEnter.add(s);
|
|
965
985
|
addDescendantStatesToEnter(s, historyValue, statesForDefaultEntry, statesToEnter);
|
|
966
986
|
}
|
|
967
987
|
for (const s of historyStateNodes) {
|
|
968
988
|
addAncestorStatesToEnter(s, stateNode.parent, statesToEnter, historyValue, statesForDefaultEntry);
|
|
969
|
-
for (const stateForDefaultEntry of statesForDefaultEntry) {
|
|
970
|
-
statesForDefaultEntry.add(stateForDefaultEntry);
|
|
971
|
-
}
|
|
972
989
|
}
|
|
973
990
|
} else {
|
|
974
|
-
const
|
|
975
|
-
for (const s of
|
|
991
|
+
const historyDefaultTransition = resolveHistoryDefaultTransition(stateNode);
|
|
992
|
+
for (const s of historyDefaultTransition.target) {
|
|
993
|
+
statesToEnter.add(s);
|
|
994
|
+
if (historyDefaultTransition === stateNode.parent?.initial) {
|
|
995
|
+
statesForDefaultEntry.add(stateNode.parent);
|
|
996
|
+
}
|
|
976
997
|
addDescendantStatesToEnter(s, historyValue, statesForDefaultEntry, statesToEnter);
|
|
977
998
|
}
|
|
978
|
-
for (const s of
|
|
999
|
+
for (const s of historyDefaultTransition.target) {
|
|
979
1000
|
addAncestorStatesToEnter(s, stateNode, statesToEnter, historyValue, statesForDefaultEntry);
|
|
980
|
-
for (const stateForDefaultEntry of statesForDefaultEntry) {
|
|
981
|
-
statesForDefaultEntry.add(stateForDefaultEntry);
|
|
982
|
-
}
|
|
983
1001
|
}
|
|
984
1002
|
}
|
|
985
1003
|
} else {
|
|
986
|
-
statesToEnter.add(stateNode);
|
|
987
1004
|
if (stateNode.type === 'compound') {
|
|
988
|
-
statesForDefaultEntry.add(stateNode);
|
|
989
1005
|
const [initialState] = stateNode.initial.target;
|
|
1006
|
+
if (!isHistoryNode(initialState)) {
|
|
1007
|
+
statesToEnter.add(initialState);
|
|
1008
|
+
statesForDefaultEntry.add(initialState);
|
|
1009
|
+
}
|
|
990
1010
|
addDescendantStatesToEnter(initialState, historyValue, statesForDefaultEntry, statesToEnter);
|
|
991
1011
|
addAncestorStatesToEnter(initialState, stateNode, statesToEnter, historyValue, statesForDefaultEntry);
|
|
992
1012
|
} else {
|
|
993
1013
|
if (stateNode.type === 'parallel') {
|
|
994
1014
|
for (const child of getChildren(stateNode).filter(sn => !isHistoryNode(sn))) {
|
|
995
1015
|
if (![...statesToEnter].some(s => isDescendant(s, child))) {
|
|
1016
|
+
if (!isHistoryNode(child)) {
|
|
1017
|
+
statesToEnter.add(child);
|
|
1018
|
+
statesForDefaultEntry.add(child);
|
|
1019
|
+
}
|
|
996
1020
|
addDescendantStatesToEnter(child, historyValue, statesForDefaultEntry, statesToEnter);
|
|
997
1021
|
}
|
|
998
1022
|
}
|
|
@@ -1007,6 +1031,7 @@ function addAncestorStatesToEnter(stateNode, toStateNode, statesToEnter, history
|
|
|
1007
1031
|
if (anc.type === 'parallel') {
|
|
1008
1032
|
for (const child of getChildren(anc).filter(sn => !isHistoryNode(sn))) {
|
|
1009
1033
|
if (![...statesToEnter].some(s => isDescendant(s, child))) {
|
|
1034
|
+
statesToEnter.add(child);
|
|
1010
1035
|
addDescendantStatesToEnter(child, historyValue, statesForDefaultEntry, statesToEnter);
|
|
1011
1036
|
}
|
|
1012
1037
|
}
|
|
@@ -1061,31 +1086,24 @@ function resolveActionsAndContextWorker(currentState, event, actorCtx, actions,
|
|
|
1061
1086
|
context: intermediateState.context,
|
|
1062
1087
|
event,
|
|
1063
1088
|
self: actorCtx?.self,
|
|
1064
|
-
system: actorCtx?.system
|
|
1065
|
-
action: isInline ? undefined : typeof action === 'string' ? {
|
|
1066
|
-
type: action
|
|
1067
|
-
} : typeof action.params === 'function' ? {
|
|
1068
|
-
type: action.type,
|
|
1069
|
-
params: action.params({
|
|
1070
|
-
context: intermediateState.context,
|
|
1071
|
-
event
|
|
1072
|
-
})
|
|
1073
|
-
} :
|
|
1074
|
-
// TS isn't able to narrow it down here
|
|
1075
|
-
action
|
|
1089
|
+
system: actorCtx?.system
|
|
1076
1090
|
};
|
|
1091
|
+
const actionParams = isInline || typeof action === 'string' ? undefined : 'params' in action ? typeof action.params === 'function' ? action.params({
|
|
1092
|
+
context: intermediateState.context,
|
|
1093
|
+
event
|
|
1094
|
+
}) : action.params : undefined;
|
|
1077
1095
|
if (!('resolve' in resolvedAction)) {
|
|
1078
1096
|
if (actorCtx?.self.status === ActorStatus.Running) {
|
|
1079
|
-
resolvedAction(actionArgs);
|
|
1097
|
+
resolvedAction(actionArgs, actionParams);
|
|
1080
1098
|
} else {
|
|
1081
1099
|
actorCtx?.defer(() => {
|
|
1082
|
-
resolvedAction(actionArgs);
|
|
1100
|
+
resolvedAction(actionArgs, actionParams);
|
|
1083
1101
|
});
|
|
1084
1102
|
}
|
|
1085
1103
|
continue;
|
|
1086
1104
|
}
|
|
1087
1105
|
const builtinAction = resolvedAction;
|
|
1088
|
-
const [nextState, params, actions] = builtinAction.resolve(actorCtx, intermediateState, actionArgs, resolvedAction,
|
|
1106
|
+
const [nextState, params, actions] = builtinAction.resolve(actorCtx, intermediateState, actionArgs, actionParams, resolvedAction,
|
|
1089
1107
|
// this holds all params
|
|
1090
1108
|
extra);
|
|
1091
1109
|
intermediateState = nextState;
|
|
@@ -1122,7 +1140,9 @@ function macrostep(state, event, actorCtx, internalQueue = []) {
|
|
|
1122
1140
|
|
|
1123
1141
|
// Handle stop event
|
|
1124
1142
|
if (event.type === XSTATE_STOP) {
|
|
1125
|
-
nextState = stopChildren(nextState, event, actorCtx)
|
|
1143
|
+
nextState = cloneState(stopChildren(nextState, event, actorCtx), {
|
|
1144
|
+
status: 'stopped'
|
|
1145
|
+
});
|
|
1126
1146
|
states.push(nextState);
|
|
1127
1147
|
return {
|
|
1128
1148
|
state: nextState,
|
|
@@ -1174,7 +1194,7 @@ function selectEventlessTransitions(nextState, event) {
|
|
|
1174
1194
|
const enabledTransitionSet = new Set();
|
|
1175
1195
|
const atomicStates = nextState.configuration.filter(isAtomicStateNode);
|
|
1176
1196
|
for (const stateNode of atomicStates) {
|
|
1177
|
-
loop: for (const s of [stateNode].concat(getProperAncestors(stateNode,
|
|
1197
|
+
loop: for (const s of [stateNode].concat(getProperAncestors(stateNode, undefined))) {
|
|
1178
1198
|
if (!s.always) {
|
|
1179
1199
|
continue;
|
|
1180
1200
|
}
|
|
@@ -1379,17 +1399,17 @@ function getPersistedState(state) {
|
|
|
1379
1399
|
for (const id in children) {
|
|
1380
1400
|
const child = children[id];
|
|
1381
1401
|
childrenJson[id] = {
|
|
1382
|
-
state: child.getPersistedState
|
|
1383
|
-
src: child.src
|
|
1402
|
+
state: child.getPersistedState(),
|
|
1403
|
+
src: child.src,
|
|
1404
|
+
systemId: child._systemId
|
|
1384
1405
|
};
|
|
1385
1406
|
}
|
|
1386
|
-
|
|
1407
|
+
const persisted = {
|
|
1387
1408
|
...jsonValues,
|
|
1388
|
-
// TODO: this makes `PersistedMachineState`'s type kind of a lie
|
|
1389
|
-
// it doesn't truly use `TContext` but rather some kind of a derived form of it
|
|
1390
1409
|
context: persistContext(context),
|
|
1391
1410
|
children: childrenJson
|
|
1392
1411
|
};
|
|
1412
|
+
return persisted;
|
|
1393
1413
|
}
|
|
1394
1414
|
function persistContext(contextPart) {
|
|
1395
1415
|
let copy;
|
|
@@ -1418,7 +1438,7 @@ function persistContext(contextPart) {
|
|
|
1418
1438
|
return copy ?? contextPart;
|
|
1419
1439
|
}
|
|
1420
1440
|
|
|
1421
|
-
function resolveRaise(_, state, args, {
|
|
1441
|
+
function resolveRaise(_, state, args, actionParams, {
|
|
1422
1442
|
event: eventOrExpr,
|
|
1423
1443
|
id,
|
|
1424
1444
|
delay
|
|
@@ -1429,13 +1449,13 @@ function resolveRaise(_, state, args, {
|
|
|
1429
1449
|
if (typeof eventOrExpr === 'string') {
|
|
1430
1450
|
throw new Error(`Only event objects may be used with raise; use raise({ type: "${eventOrExpr}" }) instead`);
|
|
1431
1451
|
}
|
|
1432
|
-
const resolvedEvent = typeof eventOrExpr === 'function' ? eventOrExpr(args) : eventOrExpr;
|
|
1452
|
+
const resolvedEvent = typeof eventOrExpr === 'function' ? eventOrExpr(args, actionParams) : eventOrExpr;
|
|
1433
1453
|
let resolvedDelay;
|
|
1434
1454
|
if (typeof delay === 'string') {
|
|
1435
1455
|
const configDelay = delaysMap && delaysMap[delay];
|
|
1436
|
-
resolvedDelay = typeof configDelay === 'function' ? configDelay(args) : configDelay;
|
|
1456
|
+
resolvedDelay = typeof configDelay === 'function' ? configDelay(args, actionParams) : configDelay;
|
|
1437
1457
|
} else {
|
|
1438
|
-
resolvedDelay = typeof delay === 'function' ? delay(args) : delay;
|
|
1458
|
+
resolvedDelay = typeof delay === 'function' ? delay(args, actionParams) : delay;
|
|
1439
1459
|
}
|
|
1440
1460
|
if (typeof resolvedDelay !== 'number') {
|
|
1441
1461
|
internalQueue.push(resolvedEvent);
|
|
@@ -1459,7 +1479,7 @@ function executeRaise(actorContext, params) {
|
|
|
1459
1479
|
* @param eventType The event to raise.
|
|
1460
1480
|
*/
|
|
1461
1481
|
function raise(eventOrExpr, options) {
|
|
1462
|
-
function raise(
|
|
1482
|
+
function raise(args, params) {
|
|
1463
1483
|
}
|
|
1464
1484
|
raise.type = 'xstate.raise';
|
|
1465
1485
|
raise.event = eventOrExpr;
|
|
@@ -1470,4 +1490,4 @@ function raise(eventOrExpr, options) {
|
|
|
1470
1490
|
return raise;
|
|
1471
1491
|
}
|
|
1472
1492
|
|
|
1473
|
-
export { raise as A, stop as B, State as S, formatTransition as a, formatInitialTransition as b, getCandidates as c, getConfiguration as d, evaluateGuard as e, formatTransitions as f, getDelayedTransitions as g, getStateNodes as h, isInFinalState as i, cloneState as j, macrostep as k, getInitialConfiguration as l, memo as m, resolveActionsAndContext as n, microstep as o, getInitialStateNodes as p, isStateId as q, resolveStateValue as r, getStateNodeByPath as s, transitionNode as t, getPersistedState as u, and as v, not as w, or as x, stateIn as y, cancel as z };
|
|
1493
|
+
export { raise as A, stop as B, spawn as C, State as S, formatTransition as a, formatInitialTransition as b, getCandidates as c, getConfiguration as d, evaluateGuard as e, formatTransitions as f, getDelayedTransitions as g, getStateNodes as h, isInFinalState as i, cloneState as j, macrostep as k, getInitialConfiguration as l, memo as m, resolveActionsAndContext as n, microstep as o, getInitialStateNodes as p, isStateId as q, resolveStateValue as r, getStateNodeByPath as s, transitionNode as t, getPersistedState as u, and as v, not as w, or as x, stateIn as y, cancel as z };
|