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
|
@@ -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(`Only event objects may be used with sendTo`);
|
|
@@ -238,6 +252,9 @@ function resolveRegisteredActorSource(actors, logic) {
|
|
|
238
252
|
return cache.get(logic);
|
|
239
253
|
}
|
|
240
254
|
|
|
255
|
+
/** Static scheduling metadata on actor definitions, never on live actors. @internal */
|
|
256
|
+
const systemLogicMetadata = Symbol('xstate.systemLogicMetadata');
|
|
257
|
+
|
|
241
258
|
const subscriptions = /* #__PURE__ */new WeakMap();
|
|
242
259
|
|
|
243
260
|
/**
|
|
@@ -256,7 +273,7 @@ id) {
|
|
|
256
273
|
error: undefined,
|
|
257
274
|
input
|
|
258
275
|
}, []];
|
|
259
|
-
|
|
276
|
+
const logic = {
|
|
260
277
|
id,
|
|
261
278
|
start: (state, {
|
|
262
279
|
self,
|
|
@@ -320,6 +337,12 @@ id) {
|
|
|
320
337
|
getPersistedSnapshot: snapshot => snapshot,
|
|
321
338
|
restoreSnapshot: snapshot => snapshot
|
|
322
339
|
};
|
|
340
|
+
Object.defineProperty(logic, systemLogicMetadata, {
|
|
341
|
+
value: {
|
|
342
|
+
kind: id
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
return logic;
|
|
323
346
|
}
|
|
324
347
|
|
|
325
348
|
/**
|
|
@@ -504,7 +527,8 @@ function withActorScope(args, actorScope) {
|
|
|
504
527
|
}
|
|
505
528
|
|
|
506
529
|
function execCustomEffect() {
|
|
507
|
-
|
|
530
|
+
const result = this.action?.(...this.args);
|
|
531
|
+
return result;
|
|
508
532
|
}
|
|
509
533
|
function execEmitEffect(runtime = this.source.system) {
|
|
510
534
|
return runtime.emitEvent(this.source, this.event);
|
|
@@ -1026,6 +1050,13 @@ function createTransitionEnqueue(actorScope, actions, internalEvents, actorSubsc
|
|
|
1026
1050
|
props[key] = guard(props[key]);
|
|
1027
1051
|
}
|
|
1028
1052
|
const enqueue = createEnqueueObject(props, guard((action, ...args) => {
|
|
1053
|
+
// A named action is `undefined` when it has no implementation. Skip it:
|
|
1054
|
+
// an `{ action, args }` record without a function would be emitted as
|
|
1055
|
+
// an event. Speculative passes (`can()`, conflict resolution) run with
|
|
1056
|
+
// `createActors: false`; warn only when the transition really runs.
|
|
1057
|
+
if (typeof action !== 'function') {
|
|
1058
|
+
return;
|
|
1059
|
+
}
|
|
1029
1060
|
pushBuiltInAction(actions, action, ...args);
|
|
1030
1061
|
}));
|
|
1031
1062
|
enqueueClosers.set(enqueue, () => {
|
|
@@ -2243,6 +2274,10 @@ function getDelayedTransitions(stateNode) {
|
|
|
2243
2274
|
}));
|
|
2244
2275
|
}
|
|
2245
2276
|
function formatTransition(stateNode, descriptor, transitionConfig) {
|
|
2277
|
+
const removedKey = getRemovedTransitionKey(transitionConfig);
|
|
2278
|
+
if (removedKey) {
|
|
2279
|
+
throw new Error(`Transition "${descriptor || 'always'}" in state "${stateNode.id}" uses ${removedKey}, which was removed in v6. Use a transition function.`);
|
|
2280
|
+
}
|
|
2246
2281
|
const normalizedTarget = normalizeTarget(transitionConfig.target);
|
|
2247
2282
|
const reenter = transitionConfig.reenter ?? false;
|
|
2248
2283
|
const target = resolveTarget(stateNode, normalizedTarget);
|
|
@@ -2253,14 +2288,46 @@ function formatTransition(stateNode, descriptor, transitionConfig) {
|
|
|
2253
2288
|
source: stateNode,
|
|
2254
2289
|
reenter,
|
|
2255
2290
|
eventType: descriptor,
|
|
2256
|
-
toJSON: () => (
|
|
2257
|
-
...transition,
|
|
2258
|
-
source: `#${stateNode.id}`,
|
|
2259
|
-
target: target ? target.map(t => `#${t.id}`) : undefined
|
|
2260
|
-
})
|
|
2291
|
+
toJSON: () => transitionDefinitionToJSON(transition)
|
|
2261
2292
|
};
|
|
2262
2293
|
return transition;
|
|
2263
2294
|
}
|
|
2295
|
+
function transitionDefinitionToJSON(transition) {
|
|
2296
|
+
const {
|
|
2297
|
+
definition: _,
|
|
2298
|
+
...serializableTransition
|
|
2299
|
+
} = transition;
|
|
2300
|
+
return {
|
|
2301
|
+
...serializableTransition,
|
|
2302
|
+
source: `#${transition.source.id}`,
|
|
2303
|
+
target: transition.target?.map(target => `#${target.id}`)
|
|
2304
|
+
};
|
|
2305
|
+
}
|
|
2306
|
+
|
|
2307
|
+
/**
|
|
2308
|
+
* Returns the v5 key of a transition object that v6 would misread, in every
|
|
2309
|
+
* build: `cond` is never read, so the transition would always be taken,
|
|
2310
|
+
* transition `actions` would not run as written, and only a function `guard`
|
|
2311
|
+
* can be called. Development builds explain each key earlier, in
|
|
2312
|
+
* `diagnoseAuthorConfig`. Compiled configs (JSON, SCXML) never set them.
|
|
2313
|
+
*/
|
|
2314
|
+
function getRemovedTransitionKey(transitionConfig) {
|
|
2315
|
+
const {
|
|
2316
|
+
cond,
|
|
2317
|
+
actions,
|
|
2318
|
+
guard
|
|
2319
|
+
} = transitionConfig;
|
|
2320
|
+
if (cond !== undefined) {
|
|
2321
|
+
return '"cond"';
|
|
2322
|
+
}
|
|
2323
|
+
if (actions !== undefined) {
|
|
2324
|
+
return '"actions"';
|
|
2325
|
+
}
|
|
2326
|
+
if (guard !== undefined && typeof guard !== 'function') {
|
|
2327
|
+
return 'an object-form "guard"';
|
|
2328
|
+
}
|
|
2329
|
+
return undefined;
|
|
2330
|
+
}
|
|
2264
2331
|
function isStateNodeDescendantOf(stateNode, ancestor) {
|
|
2265
2332
|
for (let current = stateNode.parent; current; current = current.parent) {
|
|
2266
2333
|
if (current === ancestor) {
|
|
@@ -2603,12 +2670,18 @@ function removeConflictingTransitions(enabledTransitions, stateNodeSet, snapshot
|
|
|
2603
2670
|
}
|
|
2604
2671
|
function createTransitionResultResolver(snapshot, event, actorScope, resolveActions, selectionResults) {
|
|
2605
2672
|
let cache;
|
|
2606
|
-
return transition => {
|
|
2607
|
-
if (!transition.to) {
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2673
|
+
return (transition, applied) => {
|
|
2674
|
+
if (!transition.to && !applied) {
|
|
2675
|
+
// An object transition's targets are static, so reading them must not
|
|
2676
|
+
// run its `context` and `input` mappers
|
|
2677
|
+
return {
|
|
2678
|
+
targets: transition.target,
|
|
2679
|
+
context: undefined,
|
|
2680
|
+
reenter: transition.reenter,
|
|
2681
|
+
actions: undefined,
|
|
2682
|
+
internalEvents: undefined,
|
|
2683
|
+
input: undefined
|
|
2684
|
+
};
|
|
2612
2685
|
}
|
|
2613
2686
|
let result = cache?.get(transition);
|
|
2614
2687
|
if (!result) {
|
|
@@ -2836,13 +2909,20 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2836
2909
|
children: args.children,
|
|
2837
2910
|
actions: args.actions,
|
|
2838
2911
|
actors: args.actors,
|
|
2912
|
+
guards: currentSnapshot.machine.sources.guards,
|
|
2913
|
+
delays: currentSnapshot.machine.sources.delays,
|
|
2839
2914
|
input,
|
|
2840
2915
|
stateNode
|
|
2841
2916
|
}, actorScope) : {
|
|
2842
2917
|
...args,
|
|
2918
|
+
guards: currentSnapshot.machine.sources.guards,
|
|
2919
|
+
delays: currentSnapshot.machine.sources.delays,
|
|
2843
2920
|
input,
|
|
2844
2921
|
stateNode
|
|
2845
|
-
},
|
|
2922
|
+
},
|
|
2923
|
+
// This function runs during action resolution, where enqueued
|
|
2924
|
+
// effects are no longer collected.
|
|
2925
|
+
enqueue), '_special' in transitionFn ? {
|
|
2846
2926
|
_special: true
|
|
2847
2927
|
} : {});
|
|
2848
2928
|
return [[wrappedAction], undefined, undefined];
|
|
@@ -2880,7 +2960,7 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2880
2960
|
}
|
|
2881
2961
|
for (const exitStateNode of statesToExit) {
|
|
2882
2962
|
const stateInput = getStateInput(currentSnapshot, exitStateNode.id);
|
|
2883
|
-
const [exitActions, nextContext, internalEvents] = exitStateNode.exit ? getStateActionsAndContext(exitStateNode.exit, nextState.context,
|
|
2963
|
+
const [exitActions, nextContext, internalEvents] = exitStateNode.exit ? getStateActionsAndContext(exitStateNode.exit, nextState.context, nextState.children, stateInput, 'exit', exitStateNode) : [[], undefined, undefined];
|
|
2884
2964
|
if (internalEvents?.length) {
|
|
2885
2965
|
internalQueue.push(...internalEvents);
|
|
2886
2966
|
}
|
|
@@ -2910,11 +2990,20 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2910
2990
|
let context = nextState.context;
|
|
2911
2991
|
const transitionActions = [];
|
|
2912
2992
|
const internalEvents = [];
|
|
2993
|
+
const resolvedTransitions = [];
|
|
2913
2994
|
for (const t of filteredTransitions) {
|
|
2914
|
-
|
|
2915
|
-
|
|
2995
|
+
const res = getCurrentTransitionResult(t, true);
|
|
2996
|
+
if (t.to) {
|
|
2997
|
+
const resolvedTransition = {
|
|
2998
|
+
...t,
|
|
2999
|
+
target: res.targets,
|
|
3000
|
+
definition: t
|
|
3001
|
+
};
|
|
3002
|
+
resolvedTransition.toJSON = () => transitionDefinitionToJSON(resolvedTransition);
|
|
3003
|
+
resolvedTransitions.push(resolvedTransition);
|
|
3004
|
+
} else {
|
|
3005
|
+
resolvedTransitions.push(t);
|
|
2916
3006
|
}
|
|
2917
|
-
const res = getCurrentTransitionResult(t);
|
|
2918
3007
|
if (res.context !== undefined) {
|
|
2919
3008
|
context = mergeContextPatch(context, res.context);
|
|
2920
3009
|
}
|
|
@@ -3070,7 +3159,7 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
3070
3159
|
const {
|
|
3071
3160
|
targets,
|
|
3072
3161
|
input
|
|
3073
|
-
} = getCurrentTransitionResult(transition);
|
|
3162
|
+
} = getCurrentTransitionResult(transition, true);
|
|
3074
3163
|
if (input && targets) {
|
|
3075
3164
|
for (const targetNode of targets.filter(targetNode => enteredTargetsByTransition.get(transition)?.has(targetNode))) {
|
|
3076
3165
|
stateInputMap[targetNode.id] = input;
|
|
@@ -3079,12 +3168,12 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
3079
3168
|
}
|
|
3080
3169
|
}
|
|
3081
3170
|
const completedNodes = new Set();
|
|
3082
|
-
const children = {
|
|
3083
|
-
...nextState.children
|
|
3084
|
-
};
|
|
3085
3171
|
for (const stateNodeToEnter of [...statesToEnter].sort((a, b) => a.order - b.order)) {
|
|
3086
3172
|
mutStateNodeSet.add(stateNodeToEnter);
|
|
3087
3173
|
const actions = [];
|
|
3174
|
+
// Read the children for each state: the entry actions of the states
|
|
3175
|
+
// entered before this one may have spawned or stopped children.
|
|
3176
|
+
let children = nextState.children;
|
|
3088
3177
|
|
|
3089
3178
|
// Final states are inert, so (as in SCXML) their invocations never
|
|
3090
3179
|
// start.
|
|
@@ -3123,7 +3212,10 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
3123
3212
|
args: [actor]
|
|
3124
3213
|
});
|
|
3125
3214
|
if (invokeDef.id) {
|
|
3126
|
-
children
|
|
3215
|
+
children = {
|
|
3216
|
+
...children,
|
|
3217
|
+
[invokeDef.id]: actor
|
|
3218
|
+
};
|
|
3127
3219
|
}
|
|
3128
3220
|
}
|
|
3129
3221
|
if (invoked) {
|
|
@@ -3243,7 +3335,12 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
3243
3335
|
nextStateNodesToExit.forEach(stateNode => {
|
|
3244
3336
|
if (stateNode.exit) {
|
|
3245
3337
|
const stateInput = getStateInput(nextState, stateNode.id);
|
|
3246
|
-
const [exitActions
|
|
3338
|
+
const [exitActions, nextContext, nextInternalEvents] = getStateActionsAndContext(stateNode.exit, nextState.context, nextState.children, stateInput, 'exit', stateNode);
|
|
3339
|
+
if (nextContext) {
|
|
3340
|
+
nextState = cloneMachineSnapshot(nextState, {
|
|
3341
|
+
context: nextContext
|
|
3342
|
+
});
|
|
3343
|
+
}
|
|
3247
3344
|
allExitActions.push(...exitActions);
|
|
3248
3345
|
if (nextInternalEvents?.length) {
|
|
3249
3346
|
internalQueue.push(...nextInternalEvents);
|
|
@@ -3264,14 +3361,14 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
3264
3361
|
// If context was changed (e.g. by entry actions during self-transition),
|
|
3265
3362
|
// clone to ensure reference inequality for eventless transition re-evaluation
|
|
3266
3363
|
if (nextState.context !== originalContext) {
|
|
3267
|
-
return [nextState === currentSnapshot ? cloneMachineSnapshot(nextState) : nextState, executableActions];
|
|
3364
|
+
return [nextState === currentSnapshot ? cloneMachineSnapshot(nextState) : nextState, executableActions, resolvedTransitions];
|
|
3268
3365
|
}
|
|
3269
|
-
return [nextState, executableActions];
|
|
3366
|
+
return [nextState, executableActions, resolvedTransitions];
|
|
3270
3367
|
}
|
|
3271
3368
|
return [cloneMachineSnapshot(nextState, {
|
|
3272
3369
|
_nodes: nextStateNodes,
|
|
3273
3370
|
historyValue
|
|
3274
|
-
}), executableActions];
|
|
3371
|
+
}), executableActions, resolvedTransitions];
|
|
3275
3372
|
}
|
|
3276
3373
|
}
|
|
3277
3374
|
|
|
@@ -3381,6 +3478,15 @@ class InfiniteTransitionError extends Error {
|
|
|
3381
3478
|
}
|
|
3382
3479
|
}
|
|
3383
3480
|
function macrostep(snapshot, event, actorScope, internalQueue, initialMicrosteps = []) {
|
|
3481
|
+
// A done, error or stopped snapshot processes no events, as in an actor:
|
|
3482
|
+
// every event is unhandled. The initial macrostep passes `initialMicrosteps`
|
|
3483
|
+
// and may start from a snapshot that is already done.
|
|
3484
|
+
if (snapshot.status !== 'active' && !initialMicrosteps.length) {
|
|
3485
|
+
return {
|
|
3486
|
+
snapshot,
|
|
3487
|
+
microsteps: [[snapshot, [], []]]
|
|
3488
|
+
};
|
|
3489
|
+
}
|
|
3384
3490
|
let nextSnapshot = snapshot;
|
|
3385
3491
|
const microsteps = initialMicrosteps.slice();
|
|
3386
3492
|
// Whether a transition handled the external event. A handled event always
|
|
@@ -3449,6 +3555,7 @@ function macrostep(snapshot, event, actorScope, internalQueue, initialMicrosteps
|
|
|
3449
3555
|
};
|
|
3450
3556
|
}
|
|
3451
3557
|
function addMicrostep(step, transitions) {
|
|
3558
|
+
transitions = step[2] ?? transitions;
|
|
3452
3559
|
// collect microsteps; their transitions are surfaced on the enclosing
|
|
3453
3560
|
// '@xstate.transition' event via its `microsteps[]` facet (there is no
|
|
3454
3561
|
// standalone microstep event) and returned by `getMicrosteps()`
|
|
@@ -3859,6 +3966,17 @@ function isMachineSnapshot(value) {
|
|
|
3859
3966
|
return !!value && typeof value === 'object' && 'machine' in value && 'value' in value;
|
|
3860
3967
|
}
|
|
3861
3968
|
|
|
3969
|
+
/**
|
|
3970
|
+
* The values that `snapshot.matches(...)` accepts for a state value: a state
|
|
3971
|
+
* key, a dot-delimited path to a descendant state, or a partial state value.
|
|
3972
|
+
* Non-literal state values accept any value.
|
|
3973
|
+
*/
|
|
3974
|
+
|
|
3975
|
+
/**
|
|
3976
|
+
* `unknown` if `matches(...)` accepts `TTestStateValue` for `TStateValue`,
|
|
3977
|
+
* otherwise `never`. Non-literal test values are always accepted.
|
|
3978
|
+
*/
|
|
3979
|
+
|
|
3862
3980
|
/** @public */
|
|
3863
3981
|
|
|
3864
3982
|
const machineSnapshotMatches = function matches(testValue) {
|
|
@@ -4050,7 +4168,7 @@ function getPersistedSnapshot(snapshot, options) {
|
|
|
4050
4168
|
// readings (a simulated clock, a monotonic counter) are meaningless in any
|
|
4051
4169
|
// other process, and restoring them under the wall clock would fire every
|
|
4052
4170
|
// pending delay instantly. Pure-transition snapshots have no local
|
|
4053
|
-
// schedule
|
|
4171
|
+
// schedule; durable executions record an accepted start separately.
|
|
4054
4172
|
const scheduledTimers = snapshotActor?.system?._clock?.now ? undefined : snapshotActor?.system?._snapshot?._scheduledTimers;
|
|
4055
4173
|
for (const id in timers) {
|
|
4056
4174
|
const timer = timers[id];
|
|
@@ -4081,10 +4199,10 @@ function getPersistedSnapshot(snapshot, options) {
|
|
|
4081
4199
|
// deadline. Derived from dueAt, not the scheduling moment, so repeated
|
|
4082
4200
|
// persist/restore cycles keep the same deadline. Without a live schedule
|
|
4083
4201
|
// (a restored-but-never-started actor, a pure-transition snapshot) the
|
|
4084
|
-
// timer's
|
|
4085
|
-
//
|
|
4202
|
+
// timer's accepted durable start or carried-in start passes through,
|
|
4203
|
+
// so re-persisting cannot push the deadline back.
|
|
4086
4204
|
const scheduled = scheduledTimers?.[`${snapshotActor.sessionId}.${id}`];
|
|
4087
|
-
const startedAt = scheduled ? scheduled.dueAt - timer.delay : timer
|
|
4205
|
+
const startedAt = scheduled ? scheduled.dueAt - timer.delay : getTimerStart(timer);
|
|
4088
4206
|
timersJson[id] = {
|
|
4089
4207
|
id: timer.id,
|
|
4090
4208
|
delay: timer.delay,
|
|
@@ -4359,7 +4477,14 @@ function getAllOwnEventDescriptors(snapshot) {
|
|
|
4359
4477
|
return [...new Set([...snapshot.nodes.flatMap(sn => sn.ownEvents)])];
|
|
4360
4478
|
}
|
|
4361
4479
|
|
|
4362
|
-
/**
|
|
4480
|
+
/**
|
|
4481
|
+
* Returns one event per transition of the active state nodes of `snapshot`,
|
|
4482
|
+
* including the internal events for invoked actors (`xstate.done.actor`,
|
|
4483
|
+
* `xstate.error.actor`) and delayed transitions (`xstate.after`). Graph
|
|
4484
|
+
* traversal sends these when the `events` option is not given.
|
|
4485
|
+
*
|
|
4486
|
+
* @public
|
|
4487
|
+
*/
|
|
4363
4488
|
function getAllOwnEvents(snapshot) {
|
|
4364
4489
|
const events = snapshot.nodes.flatMap(stateNode => [...stateNode.transitions.values()].flatMap(transitions => transitions.map(transition => {
|
|
4365
4490
|
const event = {
|
|
@@ -5908,7 +6033,10 @@ class Actor {
|
|
|
5908
6033
|
const [nextSnapshot, effects] = nextState;
|
|
5909
6034
|
if (nextSnapshot === previousSnapshot && !effects.length &&
|
|
5910
6035
|
// State machine snapshots only; other logic may ignore events freely.
|
|
5911
|
-
'machine' in previousSnapshot &&
|
|
6036
|
+
'machine' in previousSnapshot && (
|
|
6037
|
+
// `xstate.route` is sent by users, so a route that matches nothing is
|
|
6038
|
+
// reported like any other unhandled event.
|
|
6039
|
+
!event.type.startsWith('xstate.') || event.type === 'xstate.route')) {
|
|
5912
6040
|
this._reportUnhandledEvent(event);
|
|
5913
6041
|
}
|
|
5914
6042
|
snapshot = nextSnapshot;
|
|
@@ -6228,4 +6356,4 @@ function createActor(logic, ...[options]) {
|
|
|
6228
6356
|
return new Actor(logic, options);
|
|
6229
6357
|
}
|
|
6230
6358
|
|
|
6231
|
-
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,
|
|
6359
|
+
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 };
|