xstate 6.0.0-alpha.63 → 6.0.0-alpha.65
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -1
- package/dist/{createActor-f71670cf.development.cjs.js → createActor-1df42c9e.development.cjs.js} +238 -36
- package/dist/{createActor-523a98c7.esm.js → createActor-4629a290.esm.js} +162 -34
- package/dist/{createActor-48f753a9.development.esm.js → createActor-8f57b47b.development.esm.js} +234 -37
- package/dist/{createActor-eba8226e.cjs.js → createActor-b987e971.cjs.js} +166 -33
- package/dist/declarations/src/SimulatedClock.d.ts +1 -1
- package/dist/declarations/src/State.d.ts +25 -3
- package/dist/declarations/src/StateMachine.d.ts +20 -7
- package/dist/declarations/src/actors/promise.d.ts +5 -5
- package/dist/declarations/src/createMachine.d.ts +8 -6
- package/dist/declarations/src/createMachineFromConfig.d.ts +13 -2
- package/dist/declarations/src/durable/index.d.ts +13 -0
- package/dist/declarations/src/eventTypes.d.ts +8 -0
- package/dist/declarations/src/graph/index.d.ts +1 -0
- package/dist/declarations/src/graph/types.d.ts +20 -2
- package/dist/declarations/src/index.d.ts +2 -1
- package/dist/declarations/src/machineVersions.d.ts +2 -2
- package/dist/declarations/src/serialize.d.ts +7 -2
- package/dist/declarations/src/setup.d.ts +208 -30
- package/dist/declarations/src/systemTransition.d.ts +103 -0
- package/dist/declarations/src/types.d.ts +47 -26
- package/dist/declarations/src/types.v6.d.ts +18 -8
- package/dist/declarations/src/utils.d.ts +9 -0
- package/dist/{effectDescriptor-bc9e3e81.cjs.js → effectDescriptor-4cf24593.cjs.js} +1 -1
- package/dist/{effectDescriptor-ad75e430.esm.js → effectDescriptor-973fc1ba.esm.js} +1 -1
- package/dist/{effectDescriptor-8c87a3e7.development.cjs.js → effectDescriptor-b2b7deaa.development.cjs.js} +1 -1
- package/dist/{effectDescriptor-eadf1b25.development.esm.js → effectDescriptor-c4671afc.development.esm.js} +1 -1
- package/dist/{index-83f11f07.cjs.js → index-0cf33789.development.cjs.js} +37 -15
- package/dist/{index-2a4be1f2.development.esm.js → index-15382daf.development.esm.js} +37 -15
- package/dist/{index-211a5dce.esm.js → index-52ad3d45.esm.js} +37 -15
- package/dist/{index-3cb56f46.development.cjs.js → index-f201d440.cjs.js} +37 -15
- package/dist/xstate-actors.cjs.js +2 -2
- package/dist/xstate-actors.development.cjs.js +2 -2
- package/dist/xstate-actors.development.esm.js +2 -2
- package/dist/xstate-actors.esm.js +2 -2
- package/dist/xstate-actors.umd.min.js +1 -1
- package/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/xstate-durable.cjs.js +36 -4
- package/dist/xstate-durable.development.cjs.js +36 -4
- package/dist/xstate-durable.development.esm.js +36 -4
- package/dist/xstate-durable.esm.js +36 -4
- package/dist/xstate-durable.umd.min.js +1 -1
- package/dist/xstate-durable.umd.min.js.map +1 -1
- package/dist/xstate-graph.cjs.js +8 -4
- package/dist/xstate-graph.cjs.mjs +1 -0
- package/dist/xstate-graph.development.cjs.js +8 -4
- package/dist/xstate-graph.development.cjs.mjs +1 -0
- package/dist/xstate-graph.development.esm.js +8 -4
- package/dist/xstate-graph.esm.js +8 -4
- package/dist/xstate-graph.umd.min.js +1 -1
- package/dist/xstate-graph.umd.min.js.map +1 -1
- package/dist/xstate-validation.cjs.js +24 -7
- package/dist/xstate-validation.development.cjs.js +24 -7
- package/dist/xstate-validation.development.esm.js +24 -7
- package/dist/xstate-validation.esm.js +24 -7
- package/dist/xstate-validation.umd.min.js +1 -1
- package/dist/xstate-validation.umd.min.js.map +1 -1
- package/dist/xstate.cjs.js +1316 -291
- package/dist/xstate.cjs.mjs +3 -0
- package/dist/xstate.development.cjs.js +1335 -291
- package/dist/xstate.development.cjs.mjs +3 -0
- package/dist/xstate.development.esm.js +1335 -294
- package/dist/xstate.esm.js +1316 -294
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/package.json +1 -1
package/dist/{createActor-48f753a9.development.esm.js → createActor-8f57b47b.development.esm.js}
RENAMED
|
@@ -181,6 +181,20 @@ function reportUnhandledError(err) {
|
|
|
181
181
|
|
|
182
182
|
const symbolObservable = (() => typeof Symbol === 'function' && Symbol.observable || '@@observable')();
|
|
183
183
|
|
|
184
|
+
// Runtime metadata stays outside pure snapshots. Timer objects survive unrelated
|
|
185
|
+
// transitions; a cancelled/replaced timer gets a new object and a new deadline.
|
|
186
|
+
const starts = new WeakMap();
|
|
187
|
+
|
|
188
|
+
/** @internal */
|
|
189
|
+
function getTimerStart(timer) {
|
|
190
|
+
return starts.get(timer) ?? timer.startedAt;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** @internal */
|
|
194
|
+
function recordTimerStart(timer, startedAt) {
|
|
195
|
+
starts.set(timer, startedAt);
|
|
196
|
+
}
|
|
197
|
+
|
|
184
198
|
function assertSendToEvent(event) {
|
|
185
199
|
if (typeof event === 'string') {
|
|
186
200
|
throw new Error(// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
@@ -239,6 +253,9 @@ function resolveRegisteredActorSource(actors, logic) {
|
|
|
239
253
|
return cache.get(logic);
|
|
240
254
|
}
|
|
241
255
|
|
|
256
|
+
/** Static scheduling metadata on actor definitions, never on live actors. @internal */
|
|
257
|
+
const systemLogicMetadata = Symbol('xstate.systemLogicMetadata');
|
|
258
|
+
|
|
242
259
|
const subscriptions = /* #__PURE__ */new WeakMap();
|
|
243
260
|
|
|
244
261
|
/**
|
|
@@ -257,7 +274,7 @@ id) {
|
|
|
257
274
|
error: undefined,
|
|
258
275
|
input
|
|
259
276
|
}, []];
|
|
260
|
-
|
|
277
|
+
const logic = {
|
|
261
278
|
id,
|
|
262
279
|
start: (state, {
|
|
263
280
|
self,
|
|
@@ -321,6 +338,12 @@ id) {
|
|
|
321
338
|
getPersistedSnapshot: snapshot => snapshot,
|
|
322
339
|
restoreSnapshot: snapshot => snapshot
|
|
323
340
|
};
|
|
341
|
+
Object.defineProperty(logic, systemLogicMetadata, {
|
|
342
|
+
value: {
|
|
343
|
+
kind: id
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
return logic;
|
|
324
347
|
}
|
|
325
348
|
|
|
326
349
|
/**
|
|
@@ -505,7 +528,33 @@ function withActorScope(args, actorScope) {
|
|
|
505
528
|
}
|
|
506
529
|
|
|
507
530
|
function execCustomEffect() {
|
|
508
|
-
|
|
531
|
+
const result = this.action?.(...this.args);
|
|
532
|
+
{
|
|
533
|
+
warnOnIgnoredEffectResult(this, result);
|
|
534
|
+
}
|
|
535
|
+
return result;
|
|
536
|
+
}
|
|
537
|
+
const warnedEffectResults = new WeakSet();
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* A function passed to `enq(...)` runs as an effect after the transition is
|
|
541
|
+
* computed, so a `{ context }` or `{ children }` it returns is never applied.
|
|
542
|
+
* Development builds say so, once per function.
|
|
543
|
+
*/
|
|
544
|
+
function warnOnIgnoredEffectResult(effect, result) {
|
|
545
|
+
if (!effect.action || result === null || typeof result !== 'object' || warnedEffectResults.has(effect.action)) {
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
const prototype = Object.getPrototypeOf(result);
|
|
549
|
+
if (prototype !== Object.prototype && prototype !== null) {
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
const keys = ['context', 'children'].filter(key => key in result);
|
|
553
|
+
if (!keys.length) {
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
556
|
+
warnedEffectResults.add(effect.action);
|
|
557
|
+
console.warn(`Action "${effect.type || '(anonymous)'}" returned { ${keys.join(', ')} }, which is ignored: functions passed to enq(...) run as effects after the transition. Return the patch from the transition, entry or exit function instead; a named action can be called there directly and its result returned.`);
|
|
509
558
|
}
|
|
510
559
|
function execEmitEffect(runtime = this.source.system) {
|
|
511
560
|
return runtime.emitEvent(this.source, this.event);
|
|
@@ -1034,6 +1083,16 @@ function createTransitionEnqueue(actorScope, actions, internalEvents, actorSubsc
|
|
|
1034
1083
|
props[key] = guard(props[key]);
|
|
1035
1084
|
}
|
|
1036
1085
|
const enqueue = createEnqueueObject(props, guard((action, ...args) => {
|
|
1086
|
+
// A named action is `undefined` when it has no implementation. Skip it:
|
|
1087
|
+
// an `{ action, args }` record without a function would be emitted as
|
|
1088
|
+
// an event. Speculative passes (`can()`, conflict resolution) run with
|
|
1089
|
+
// `createActors: false`; warn only when the transition really runs.
|
|
1090
|
+
if (typeof action !== 'function') {
|
|
1091
|
+
if (createActors) {
|
|
1092
|
+
warnNotAFunction(action);
|
|
1093
|
+
}
|
|
1094
|
+
return;
|
|
1095
|
+
}
|
|
1037
1096
|
pushBuiltInAction(actions, action, ...args);
|
|
1038
1097
|
}));
|
|
1039
1098
|
enqueueClosers.set(enqueue, () => {
|
|
@@ -1058,6 +1117,10 @@ function lateEnqueueCall() {
|
|
|
1058
1117
|
throw new Error('enq.* called after the transition function returned');
|
|
1059
1118
|
}
|
|
1060
1119
|
}
|
|
1120
|
+
function warnNotAFunction(value) {
|
|
1121
|
+
const received = typeof value === 'string' ? `the string "${value}"` : value !== null && typeof value === 'object' ? 'an object' : String(value);
|
|
1122
|
+
console.warn(`enq(...) received ${received} instead of a function, so nothing was enqueued. A named action is undefined when it has no implementation: implement it in setup({ actions }) or the machine config, or pass it to machine.provide({ actions }).`);
|
|
1123
|
+
}
|
|
1061
1124
|
function getBuiltInActionFields(action, args) {
|
|
1062
1125
|
switch (action) {
|
|
1063
1126
|
case builtInActions['@xstate.spawn']:
|
|
@@ -2263,6 +2326,10 @@ function getDelayedTransitions(stateNode) {
|
|
|
2263
2326
|
}));
|
|
2264
2327
|
}
|
|
2265
2328
|
function formatTransition(stateNode, descriptor, transitionConfig) {
|
|
2329
|
+
const removedKey = getRemovedTransitionKey(transitionConfig);
|
|
2330
|
+
if (removedKey) {
|
|
2331
|
+
throw new Error(`Transition "${descriptor || 'always'}" in state "${stateNode.id}" uses ${removedKey}, which was removed in v6. Use a transition function.`);
|
|
2332
|
+
}
|
|
2266
2333
|
const normalizedTarget = normalizeTarget(transitionConfig.target);
|
|
2267
2334
|
const reenter = transitionConfig.reenter ?? false;
|
|
2268
2335
|
const target = resolveTarget(stateNode, normalizedTarget);
|
|
@@ -2273,14 +2340,46 @@ function formatTransition(stateNode, descriptor, transitionConfig) {
|
|
|
2273
2340
|
source: stateNode,
|
|
2274
2341
|
reenter,
|
|
2275
2342
|
eventType: descriptor,
|
|
2276
|
-
toJSON: () => (
|
|
2277
|
-
...transition,
|
|
2278
|
-
source: `#${stateNode.id}`,
|
|
2279
|
-
target: target ? target.map(t => `#${t.id}`) : undefined
|
|
2280
|
-
})
|
|
2343
|
+
toJSON: () => transitionDefinitionToJSON(transition)
|
|
2281
2344
|
};
|
|
2282
2345
|
return transition;
|
|
2283
2346
|
}
|
|
2347
|
+
function transitionDefinitionToJSON(transition) {
|
|
2348
|
+
const {
|
|
2349
|
+
definition: _,
|
|
2350
|
+
...serializableTransition
|
|
2351
|
+
} = transition;
|
|
2352
|
+
return {
|
|
2353
|
+
...serializableTransition,
|
|
2354
|
+
source: `#${transition.source.id}`,
|
|
2355
|
+
target: transition.target?.map(target => `#${target.id}`)
|
|
2356
|
+
};
|
|
2357
|
+
}
|
|
2358
|
+
|
|
2359
|
+
/**
|
|
2360
|
+
* Returns the v5 key of a transition object that v6 would misread, in every
|
|
2361
|
+
* build: `cond` is never read, so the transition would always be taken,
|
|
2362
|
+
* transition `actions` would not run as written, and only a function `guard`
|
|
2363
|
+
* can be called. Development builds explain each key earlier, in
|
|
2364
|
+
* `diagnoseAuthorConfig`. Compiled configs (JSON, SCXML) never set them.
|
|
2365
|
+
*/
|
|
2366
|
+
function getRemovedTransitionKey(transitionConfig) {
|
|
2367
|
+
const {
|
|
2368
|
+
cond,
|
|
2369
|
+
actions,
|
|
2370
|
+
guard
|
|
2371
|
+
} = transitionConfig;
|
|
2372
|
+
if (cond !== undefined) {
|
|
2373
|
+
return '"cond"';
|
|
2374
|
+
}
|
|
2375
|
+
if (actions !== undefined) {
|
|
2376
|
+
return '"actions"';
|
|
2377
|
+
}
|
|
2378
|
+
if (guard !== undefined && typeof guard !== 'function') {
|
|
2379
|
+
return 'an object-form "guard"';
|
|
2380
|
+
}
|
|
2381
|
+
return undefined;
|
|
2382
|
+
}
|
|
2284
2383
|
function isStateNodeDescendantOf(stateNode, ancestor) {
|
|
2285
2384
|
for (let current = stateNode.parent; current; current = current.parent) {
|
|
2286
2385
|
if (current === ancestor) {
|
|
@@ -2623,12 +2722,18 @@ function removeConflictingTransitions(enabledTransitions, stateNodeSet, snapshot
|
|
|
2623
2722
|
}
|
|
2624
2723
|
function createTransitionResultResolver(snapshot, event, actorScope, resolveActions, selectionResults) {
|
|
2625
2724
|
let cache;
|
|
2626
|
-
return transition => {
|
|
2627
|
-
if (!transition.to) {
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2725
|
+
return (transition, applied) => {
|
|
2726
|
+
if (!transition.to && !applied) {
|
|
2727
|
+
// An object transition's targets are static, so reading them must not
|
|
2728
|
+
// run its `context` and `input` mappers
|
|
2729
|
+
return {
|
|
2730
|
+
targets: transition.target,
|
|
2731
|
+
context: undefined,
|
|
2732
|
+
reenter: transition.reenter,
|
|
2733
|
+
actions: undefined,
|
|
2734
|
+
internalEvents: undefined,
|
|
2735
|
+
input: undefined
|
|
2736
|
+
};
|
|
2632
2737
|
}
|
|
2633
2738
|
let result = cache?.get(transition);
|
|
2634
2739
|
if (!result) {
|
|
@@ -2856,13 +2961,20 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2856
2961
|
children: args.children,
|
|
2857
2962
|
actions: args.actions,
|
|
2858
2963
|
actors: args.actors,
|
|
2964
|
+
guards: currentSnapshot.machine.sources.guards,
|
|
2965
|
+
delays: currentSnapshot.machine.sources.delays,
|
|
2859
2966
|
input,
|
|
2860
2967
|
stateNode
|
|
2861
2968
|
}, actorScope) : {
|
|
2862
2969
|
...args,
|
|
2970
|
+
guards: currentSnapshot.machine.sources.guards,
|
|
2971
|
+
delays: currentSnapshot.machine.sources.delays,
|
|
2863
2972
|
input,
|
|
2864
2973
|
stateNode
|
|
2865
|
-
},
|
|
2974
|
+
},
|
|
2975
|
+
// This function runs during action resolution, where enqueued
|
|
2976
|
+
// effects are no longer collected.
|
|
2977
|
+
createIgnoredEnqueue(transitionFn, kind, stateNode.id) ), '_special' in transitionFn ? {
|
|
2866
2978
|
_special: true
|
|
2867
2979
|
} : {});
|
|
2868
2980
|
return [[wrappedAction], undefined, undefined];
|
|
@@ -2900,7 +3012,7 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2900
3012
|
}
|
|
2901
3013
|
for (const exitStateNode of statesToExit) {
|
|
2902
3014
|
const stateInput = getStateInput(currentSnapshot, exitStateNode.id);
|
|
2903
|
-
const [exitActions, nextContext, internalEvents] = exitStateNode.exit ? getStateActionsAndContext(exitStateNode.exit, nextState.context,
|
|
3015
|
+
const [exitActions, nextContext, internalEvents] = exitStateNode.exit ? getStateActionsAndContext(exitStateNode.exit, nextState.context, nextState.children, stateInput, 'exit', exitStateNode) : [[], undefined, undefined];
|
|
2904
3016
|
if (internalEvents?.length) {
|
|
2905
3017
|
internalQueue.push(...internalEvents);
|
|
2906
3018
|
}
|
|
@@ -2930,11 +3042,20 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2930
3042
|
let context = nextState.context;
|
|
2931
3043
|
const transitionActions = [];
|
|
2932
3044
|
const internalEvents = [];
|
|
3045
|
+
const resolvedTransitions = [];
|
|
2933
3046
|
for (const t of filteredTransitions) {
|
|
2934
|
-
|
|
2935
|
-
|
|
3047
|
+
const res = getCurrentTransitionResult(t, true);
|
|
3048
|
+
if (t.to) {
|
|
3049
|
+
const resolvedTransition = {
|
|
3050
|
+
...t,
|
|
3051
|
+
target: res.targets,
|
|
3052
|
+
definition: t
|
|
3053
|
+
};
|
|
3054
|
+
resolvedTransition.toJSON = () => transitionDefinitionToJSON(resolvedTransition);
|
|
3055
|
+
resolvedTransitions.push(resolvedTransition);
|
|
3056
|
+
} else {
|
|
3057
|
+
resolvedTransitions.push(t);
|
|
2936
3058
|
}
|
|
2937
|
-
const res = getCurrentTransitionResult(t);
|
|
2938
3059
|
if (res.context !== undefined) {
|
|
2939
3060
|
context = mergeContextPatch(context, res.context);
|
|
2940
3061
|
}
|
|
@@ -3090,7 +3211,7 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
3090
3211
|
const {
|
|
3091
3212
|
targets,
|
|
3092
3213
|
input
|
|
3093
|
-
} = getCurrentTransitionResult(transition);
|
|
3214
|
+
} = getCurrentTransitionResult(transition, true);
|
|
3094
3215
|
if (input && targets) {
|
|
3095
3216
|
for (const targetNode of targets.filter(targetNode => enteredTargetsByTransition.get(transition)?.has(targetNode))) {
|
|
3096
3217
|
stateInputMap[targetNode.id] = input;
|
|
@@ -3099,12 +3220,12 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
3099
3220
|
}
|
|
3100
3221
|
}
|
|
3101
3222
|
const completedNodes = new Set();
|
|
3102
|
-
const children = {
|
|
3103
|
-
...nextState.children
|
|
3104
|
-
};
|
|
3105
3223
|
for (const stateNodeToEnter of [...statesToEnter].sort((a, b) => a.order - b.order)) {
|
|
3106
3224
|
mutStateNodeSet.add(stateNodeToEnter);
|
|
3107
3225
|
const actions = [];
|
|
3226
|
+
// Read the children for each state: the entry actions of the states
|
|
3227
|
+
// entered before this one may have spawned or stopped children.
|
|
3228
|
+
let children = nextState.children;
|
|
3108
3229
|
|
|
3109
3230
|
// Final states are inert, so (as in SCXML) their invocations never
|
|
3110
3231
|
// start.
|
|
@@ -3143,7 +3264,10 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
3143
3264
|
args: [actor]
|
|
3144
3265
|
});
|
|
3145
3266
|
if (invokeDef.id) {
|
|
3146
|
-
children
|
|
3267
|
+
children = {
|
|
3268
|
+
...children,
|
|
3269
|
+
[invokeDef.id]: actor
|
|
3270
|
+
};
|
|
3147
3271
|
}
|
|
3148
3272
|
}
|
|
3149
3273
|
if (invoked) {
|
|
@@ -3263,7 +3387,12 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
3263
3387
|
nextStateNodesToExit.forEach(stateNode => {
|
|
3264
3388
|
if (stateNode.exit) {
|
|
3265
3389
|
const stateInput = getStateInput(nextState, stateNode.id);
|
|
3266
|
-
const [exitActions
|
|
3390
|
+
const [exitActions, nextContext, nextInternalEvents] = getStateActionsAndContext(stateNode.exit, nextState.context, nextState.children, stateInput, 'exit', stateNode);
|
|
3391
|
+
if (nextContext) {
|
|
3392
|
+
nextState = cloneMachineSnapshot(nextState, {
|
|
3393
|
+
context: nextContext
|
|
3394
|
+
});
|
|
3395
|
+
}
|
|
3267
3396
|
allExitActions.push(...exitActions);
|
|
3268
3397
|
if (nextInternalEvents?.length) {
|
|
3269
3398
|
internalQueue.push(...nextInternalEvents);
|
|
@@ -3284,14 +3413,14 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
3284
3413
|
// If context was changed (e.g. by entry actions during self-transition),
|
|
3285
3414
|
// clone to ensure reference inequality for eventless transition re-evaluation
|
|
3286
3415
|
if (nextState.context !== originalContext) {
|
|
3287
|
-
return [nextState === currentSnapshot ? cloneMachineSnapshot(nextState) : nextState, executableActions];
|
|
3416
|
+
return [nextState === currentSnapshot ? cloneMachineSnapshot(nextState) : nextState, executableActions, resolvedTransitions];
|
|
3288
3417
|
}
|
|
3289
|
-
return [nextState, executableActions];
|
|
3418
|
+
return [nextState, executableActions, resolvedTransitions];
|
|
3290
3419
|
}
|
|
3291
3420
|
return [cloneMachineSnapshot(nextState, {
|
|
3292
3421
|
_nodes: nextStateNodes,
|
|
3293
3422
|
historyValue
|
|
3294
|
-
}), executableActions];
|
|
3423
|
+
}), executableActions, resolvedTransitions];
|
|
3295
3424
|
}
|
|
3296
3425
|
}
|
|
3297
3426
|
|
|
@@ -3401,6 +3530,15 @@ class InfiniteTransitionError extends Error {
|
|
|
3401
3530
|
}
|
|
3402
3531
|
}
|
|
3403
3532
|
function macrostep(snapshot, event, actorScope, internalQueue, initialMicrosteps = []) {
|
|
3533
|
+
// A done, error or stopped snapshot processes no events, as in an actor:
|
|
3534
|
+
// every event is unhandled. The initial macrostep passes `initialMicrosteps`
|
|
3535
|
+
// and may start from a snapshot that is already done.
|
|
3536
|
+
if (snapshot.status !== 'active' && !initialMicrosteps.length) {
|
|
3537
|
+
return {
|
|
3538
|
+
snapshot,
|
|
3539
|
+
microsteps: [[snapshot, [], []]]
|
|
3540
|
+
};
|
|
3541
|
+
}
|
|
3404
3542
|
let nextSnapshot = snapshot;
|
|
3405
3543
|
const microsteps = initialMicrosteps.slice();
|
|
3406
3544
|
// Whether a transition handled the external event. A handled event always
|
|
@@ -3469,6 +3607,7 @@ function macrostep(snapshot, event, actorScope, internalQueue, initialMicrosteps
|
|
|
3469
3607
|
};
|
|
3470
3608
|
}
|
|
3471
3609
|
function addMicrostep(step, transitions) {
|
|
3610
|
+
transitions = step[2] ?? transitions;
|
|
3472
3611
|
// collect microsteps; their transitions are surfaced on the enclosing
|
|
3473
3612
|
// '@xstate.transition' event via its `microsteps[]` facet (there is no
|
|
3474
3613
|
// standalone microstep event) and returned by `getMicrosteps()`
|
|
@@ -3624,6 +3763,42 @@ function assertSyncTransitionResult(res, event, sourceId, kind) {
|
|
|
3624
3763
|
throw new Error(kind ? `${kind === 'entry' ? 'Entry' : 'Exit'} functions must be synchronous. The ${kind} function of state "${sourceId}" returned a promise (event "${event.type}"). Move async work into an invoked or spawned actor, or enq.effect.` : `Transition functions must be synchronous. Transition for event "${event.type}" in state "${sourceId}" returned a promise. Move async work into an invoked or spawned actor, or enq.effect.`);
|
|
3625
3764
|
}
|
|
3626
3765
|
}
|
|
3766
|
+
const ignoredEnqueues = new WeakMap();
|
|
3767
|
+
|
|
3768
|
+
/**
|
|
3769
|
+
* The enqueue object that an entry or exit function gets in development when it
|
|
3770
|
+
* is not declared with exactly two parameters. Such a function runs during
|
|
3771
|
+
* action resolution, where enqueued effects are no longer collected, so every
|
|
3772
|
+
* call is ignored. This one warns, once per function.
|
|
3773
|
+
*/
|
|
3774
|
+
function createIgnoredEnqueue(fn, kind, stateNodeId) {
|
|
3775
|
+
let enqueue = ignoredEnqueues.get(fn);
|
|
3776
|
+
if (enqueue) {
|
|
3777
|
+
return enqueue;
|
|
3778
|
+
}
|
|
3779
|
+
let warned = false;
|
|
3780
|
+
const ignore = (method, result) => (..._args) => {
|
|
3781
|
+
if (!warned) {
|
|
3782
|
+
warned = true;
|
|
3783
|
+
console.warn(`The ${kind} function of state "${stateNodeId}" called ${method}(...), which was ignored. Only ${kind} functions declared with exactly two parameters, (args, enq) => ..., get a working enq. This one has fn.length ${fn.length}; fn.length stops counting at a default or rest parameter.`);
|
|
3784
|
+
}
|
|
3785
|
+
return result?.();
|
|
3786
|
+
};
|
|
3787
|
+
const emptyActor = () => ({});
|
|
3788
|
+
enqueue = createEnqueueObject({
|
|
3789
|
+
cancel: ignore('enq.cancel'),
|
|
3790
|
+
emit: ignore('enq.emit'),
|
|
3791
|
+
log: ignore('enq.log'),
|
|
3792
|
+
raise: ignore('enq.raise'),
|
|
3793
|
+
sendTo: ignore('enq.sendTo'),
|
|
3794
|
+
stop: ignore('enq.stop'),
|
|
3795
|
+
spawn: ignore('enq.spawn', emptyActor),
|
|
3796
|
+
listen: ignore('enq.listen', emptyActor),
|
|
3797
|
+
subscribeTo: ignore('enq.subscribeTo', emptyActor)
|
|
3798
|
+
}, ignore('enq'));
|
|
3799
|
+
ignoredEnqueues.set(fn, enqueue);
|
|
3800
|
+
return enqueue;
|
|
3801
|
+
}
|
|
3627
3802
|
let transitionEffectEnqueue;
|
|
3628
3803
|
function getTransitionEffectEnqueue() {
|
|
3629
3804
|
return transitionEffectEnqueue ??= createEnqueueObject({
|
|
@@ -3953,6 +4128,17 @@ function isMachineSnapshot(value) {
|
|
|
3953
4128
|
return !!value && typeof value === 'object' && 'machine' in value && 'value' in value;
|
|
3954
4129
|
}
|
|
3955
4130
|
|
|
4131
|
+
/**
|
|
4132
|
+
* The values that `snapshot.matches(...)` accepts for a state value: a state
|
|
4133
|
+
* key, a dot-delimited path to a descendant state, or a partial state value.
|
|
4134
|
+
* Non-literal state values accept any value.
|
|
4135
|
+
*/
|
|
4136
|
+
|
|
4137
|
+
/**
|
|
4138
|
+
* `unknown` if `matches(...)` accepts `TTestStateValue` for `TStateValue`,
|
|
4139
|
+
* otherwise `never`. Non-literal test values are always accepted.
|
|
4140
|
+
*/
|
|
4141
|
+
|
|
3956
4142
|
/** @public */
|
|
3957
4143
|
|
|
3958
4144
|
const machineSnapshotMatches = function matches(testValue) {
|
|
@@ -4156,7 +4342,7 @@ function getPersistedSnapshot(snapshot, options) {
|
|
|
4156
4342
|
// readings (a simulated clock, a monotonic counter) are meaningless in any
|
|
4157
4343
|
// other process, and restoring them under the wall clock would fire every
|
|
4158
4344
|
// pending delay instantly. Pure-transition snapshots have no local
|
|
4159
|
-
// schedule
|
|
4345
|
+
// schedule; durable executions record an accepted start separately.
|
|
4160
4346
|
const scheduledTimers = snapshotActor?.system?._clock?.now ? undefined : snapshotActor?.system?._snapshot?._scheduledTimers;
|
|
4161
4347
|
for (const id in timers) {
|
|
4162
4348
|
const timer = timers[id];
|
|
@@ -4187,10 +4373,10 @@ function getPersistedSnapshot(snapshot, options) {
|
|
|
4187
4373
|
// deadline. Derived from dueAt, not the scheduling moment, so repeated
|
|
4188
4374
|
// persist/restore cycles keep the same deadline. Without a live schedule
|
|
4189
4375
|
// (a restored-but-never-started actor, a pure-transition snapshot) the
|
|
4190
|
-
// timer's
|
|
4191
|
-
//
|
|
4376
|
+
// timer's accepted durable start or carried-in start passes through,
|
|
4377
|
+
// so re-persisting cannot push the deadline back.
|
|
4192
4378
|
const scheduled = scheduledTimers?.[`${snapshotActor.sessionId}.${id}`];
|
|
4193
|
-
const startedAt = scheduled ? scheduled.dueAt - timer.delay : timer
|
|
4379
|
+
const startedAt = scheduled ? scheduled.dueAt - timer.delay : getTimerStart(timer);
|
|
4194
4380
|
timersJson[id] = {
|
|
4195
4381
|
id: timer.id,
|
|
4196
4382
|
delay: timer.delay,
|
|
@@ -4477,7 +4663,14 @@ function getAllOwnEventDescriptors(snapshot) {
|
|
|
4477
4663
|
return [...new Set([...snapshot.nodes.flatMap(sn => sn.ownEvents)])];
|
|
4478
4664
|
}
|
|
4479
4665
|
|
|
4480
|
-
/**
|
|
4666
|
+
/**
|
|
4667
|
+
* Returns one event per transition of the active state nodes of `snapshot`,
|
|
4668
|
+
* including the internal events for invoked actors (`xstate.done.actor`,
|
|
4669
|
+
* `xstate.error.actor`) and delayed transitions (`xstate.after`). Graph
|
|
4670
|
+
* traversal sends these when the `events` option is not given.
|
|
4671
|
+
*
|
|
4672
|
+
* @public
|
|
4673
|
+
*/
|
|
4481
4674
|
function getAllOwnEvents(snapshot) {
|
|
4482
4675
|
const events = snapshot.nodes.flatMap(stateNode => [...stateNode.transitions.values()].flatMap(transitions => transitions.map(transition => {
|
|
4483
4676
|
const event = {
|
|
@@ -6038,7 +6231,10 @@ class Actor {
|
|
|
6038
6231
|
const [nextSnapshot, effects] = nextState;
|
|
6039
6232
|
if (nextSnapshot === previousSnapshot && !effects.length &&
|
|
6040
6233
|
// State machine snapshots only; other logic may ignore events freely.
|
|
6041
|
-
'machine' in previousSnapshot &&
|
|
6234
|
+
'machine' in previousSnapshot && (
|
|
6235
|
+
// `xstate.route` is sent by users, so a route that matches nothing is
|
|
6236
|
+
// reported like any other unhandled event.
|
|
6237
|
+
!event.type.startsWith('xstate.') || event.type === 'xstate.route')) {
|
|
6042
6238
|
this._reportUnhandledEvent(event);
|
|
6043
6239
|
}
|
|
6044
6240
|
snapshot = nextSnapshot;
|
|
@@ -6059,10 +6255,11 @@ class Actor {
|
|
|
6059
6255
|
_reportUnhandledEvent(event) {
|
|
6060
6256
|
safeCall(() => this.options.onUnhandledEvent?.(event, this._snapshot));
|
|
6061
6257
|
{
|
|
6258
|
+
const to = event.type === 'xstate.route' ? ` to ${JSON.stringify(event.to)}` : '';
|
|
6062
6259
|
const warned = this._warnedUnhandledTypes ??= new Set();
|
|
6063
|
-
if (!warned.has(event.type)) {
|
|
6064
|
-
warned.add(event.type);
|
|
6065
|
-
console.warn(`Actor ${this.id} received event "${event.type}" in state ${JSON.stringify(this._snapshot.value)} with no matching transition`);
|
|
6260
|
+
if (!warned.has(event.type + to)) {
|
|
6261
|
+
warned.add(event.type + to);
|
|
6262
|
+
console.warn(`Actor ${this.id} received event "${event.type}"${to} in state ${JSON.stringify(this._snapshot.value)} with no matching transition`);
|
|
6066
6263
|
}
|
|
6067
6264
|
}
|
|
6068
6265
|
}
|
|
@@ -6371,4 +6568,4 @@ function createActor(logic, ...[options]) {
|
|
|
6371
6568
|
return new Actor(logic, options);
|
|
6372
6569
|
}
|
|
6373
6570
|
|
|
6374
|
-
export { parseGeneratedActorId as $, attachSnapshotActorRef as A, macrostep as B, isInertActorScope as C, setSnapshotActorRef as D, cloneMachineSnapshot as E, transitionNode as F, getTransitionResult as G, hasEffect as H, createErrorPlatformEvent as I, withActorSelf as J, resolveActionsWithContext as K, takeSpawnAllocationCounters as L, mergeActorIdCounters as M, NULL_EVENT as N, createInitEvent as O, createSpawnEffect as P, initialMicrostep as Q, createStartEffect as R, STATE_DELIMITER as S, toStatePath as T, isStateId as U, getStateNodeByPath as V, getPersistedSnapshot as W, XSTATE_TIMER as X, createRemoteActorRef as Y, resolveReferencedActor as Z, createInvokeTimeoutEvent as _, allocateChildId as a, ACTOR_REF_TYPE as a0, createActor as a1, parseDelayToMilliseconds as a2, isAtomicStateNode as a3, ProcessingStatus as a4, isActorRefLike as a5,
|
|
6571
|
+
export { parseGeneratedActorId as $, attachSnapshotActorRef as A, macrostep as B, isInertActorScope as C, setSnapshotActorRef as D, cloneMachineSnapshot as E, transitionNode as F, getTransitionResult as G, hasEffect as H, createErrorPlatformEvent as I, withActorSelf as J, resolveActionsWithContext as K, takeSpawnAllocationCounters as L, mergeActorIdCounters as M, NULL_EVENT as N, createInitEvent as O, createSpawnEffect as P, initialMicrostep as Q, createStartEffect as R, STATE_DELIMITER as S, toStatePath as T, isStateId as U, getStateNodeByPath as V, getPersistedSnapshot as W, XSTATE_TIMER as X, createRemoteActorRef as Y, resolveReferencedActor as Z, createInvokeTimeoutEvent as _, allocateChildId as a, ACTOR_REF_TYPE as a0, createActor as a1, parseDelayToMilliseconds as a2, isAtomicStateNode as a3, ProcessingStatus as a4, isActorRefLike as a5, encodeAddressSegment as a6, systemLogicMetadata as a7, getActorIdPrefix as a8, finalizeTransitionResult as a9, createSendToEffect as aA, XSTATE_INIT as aB, hasAmbientInspector as aC, getProperAncestors as aD, isRemoteActorRef as aE, getAllOwnEvents as aF, matchesEvent as aG, getRootActorId as aH, RUNTIME_OPERATIONS as aI, withSystemInspector as aJ, createTimerEffect as aK, getSnapshotActorRef as aL, withExecutionIdentity as aM, getTimerStart as aN, recordTimerStart as aO, createDoneActorEvent as aa, createErrorActorEvent as ab, isMachineSnapshot as ac, listenerLogic as ad, subscriptionLogic as ae, createListenerLogic as af, createSubscriptionLogic as ag, Actor as ah, InfiniteTransitionError as ai, getAllOwnEventDescriptors as aj, matchesState as ak, checkStateIn as al, pathToStateValue as am, toObserver as an, executeEffects as ao, isBuiltInExecutableAction as ap, deliverEvent as aq, runStep as ar, stopActor as as, terminateActor as at, XSTATE_STOP as au, createCustomEffect as av, XSTATE_LOGIC_EFFECT_START as aw, XSTATE_LOGIC_EFFECT_RESOLVE as ax, XSTATE_LOGIC_EFFECT_REJECT as ay, createEmitEffect as az, assertChildIdFree as b, reserveChildId as c, mapValues as d, createInvokeId as e, getEventDescriptorKey as f, getDelayedTransitions as g, getCandidates as h, evaluateCandidate as i, formatTransition as j, toTransitionConfigArray as k, createInvokeTimeoutEventId as l, matchesEventDescriptor as m, matchesActorSession as n, formatRouteTransitions as o, resolveStateValue as p, getAllStateNodes as q, resolveRegisteredActorSource as r, getStateNodes as s, toArray as t, createMachineSnapshot as u, isInFinalState as v, createInertActorScope as w, setInertActorScopeSnapshot as x, createDeadLetterEffect as y, beginSpawnAllocation as z };
|