xstate 5.19.4 → 5.20.1

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.
Files changed (65) hide show
  1. package/README.md +0 -1
  2. package/actions/dist/xstate-actions.cjs.d.ts +1 -1
  3. package/actions/dist/xstate-actions.cjs.js +8 -7
  4. package/actions/dist/xstate-actions.development.cjs.js +8 -7
  5. package/actions/dist/xstate-actions.development.esm.js +3 -2
  6. package/actions/dist/xstate-actions.esm.js +3 -2
  7. package/actions/dist/xstate-actions.umd.min.js +1 -1
  8. package/actions/dist/xstate-actions.umd.min.js.map +1 -1
  9. package/actors/dist/xstate-actors.cjs.d.ts +1 -1
  10. package/actors/dist/xstate-actors.development.esm.js +1 -1
  11. package/actors/dist/xstate-actors.esm.js +1 -1
  12. package/actors/dist/xstate-actors.umd.min.js.map +1 -1
  13. package/dev/dist/xstate-dev.cjs.d.ts +1 -1
  14. package/dev/dist/xstate-dev.umd.min.js.map +1 -1
  15. package/dist/StateMachine-1cda96d3.cjs.js +560 -0
  16. package/dist/StateMachine-38b5bb3f.development.cjs.js +566 -0
  17. package/dist/StateMachine-b4e94439.development.esm.js +563 -0
  18. package/dist/StateMachine-c88ea5dd.esm.js +557 -0
  19. package/dist/assign-6313ccb3.development.esm.js +133 -0
  20. package/dist/assign-c3259787.esm.js +127 -0
  21. package/dist/assign-c84786ab.development.cjs.js +135 -0
  22. package/dist/assign-e9c344ea.cjs.js +129 -0
  23. package/dist/declarations/src/StateMachine.d.ts +2 -2
  24. package/dist/declarations/src/createMachine.d.ts +1 -2
  25. package/dist/declarations/src/graph/TestModel.d.ts +70 -0
  26. package/dist/declarations/src/graph/adjacency.d.ts +8 -0
  27. package/dist/declarations/src/graph/graph.d.ts +14 -0
  28. package/dist/declarations/src/graph/index.d.ts +9 -0
  29. package/dist/declarations/src/graph/pathFromEvents.d.ts +3 -0
  30. package/dist/declarations/src/graph/pathGenerators.d.ts +4 -0
  31. package/dist/declarations/src/graph/shortestPaths.d.ts +3 -0
  32. package/dist/declarations/src/graph/simplePaths.d.ts +3 -0
  33. package/dist/declarations/src/graph/types.d.ts +159 -0
  34. package/dist/declarations/src/index.d.ts +1 -1
  35. package/dist/declarations/src/inspection.d.ts +1 -1
  36. package/dist/{log-655aa404.esm.js → log-1c257a58.esm.js} +3 -126
  37. package/dist/{log-fa2e731a.cjs.js → log-215998b6.cjs.js} +2 -126
  38. package/dist/{log-fadc8808.development.cjs.js → log-2c8d7f98.development.cjs.js} +2 -132
  39. package/dist/{log-5a7b5528.development.esm.js → log-ef959da6.development.esm.js} +3 -132
  40. package/dist/{raise-59549771.development.esm.js → raise-78b8dcb8.development.esm.js} +1 -1
  41. package/dist/{raise-3e01e82a.esm.js → raise-b0a4e862.esm.js} +1 -1
  42. package/dist/xstate.cjs.d.ts +1 -1
  43. package/dist/xstate.cjs.js +7 -558
  44. package/dist/xstate.development.cjs.js +7 -564
  45. package/dist/xstate.development.esm.js +7 -564
  46. package/dist/xstate.esm.js +7 -558
  47. package/dist/xstate.umd.min.js +1 -1
  48. package/dist/xstate.umd.min.js.map +1 -1
  49. package/graph/dist/xstate-graph.cjs.d.mts +2 -0
  50. package/graph/dist/xstate-graph.cjs.d.ts +2 -0
  51. package/graph/dist/xstate-graph.cjs.js +901 -0
  52. package/graph/dist/xstate-graph.cjs.mjs +15 -0
  53. package/graph/dist/xstate-graph.development.cjs.js +901 -0
  54. package/graph/dist/xstate-graph.development.cjs.mjs +15 -0
  55. package/graph/dist/xstate-graph.development.esm.js +885 -0
  56. package/graph/dist/xstate-graph.esm.js +885 -0
  57. package/graph/dist/xstate-graph.umd.min.js +2 -0
  58. package/graph/dist/xstate-graph.umd.min.js.map +1 -0
  59. package/graph/package.json +8 -0
  60. package/guards/dist/xstate-guards.cjs.d.ts +1 -1
  61. package/guards/dist/xstate-guards.development.esm.js +1 -1
  62. package/guards/dist/xstate-guards.esm.js +1 -1
  63. package/guards/dist/xstate-guards.umd.min.js +1 -1
  64. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  65. package/package.json +22 -6
@@ -1,8 +1,10 @@
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-3e01e82a.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-3e01e82a.esm.js';
4
- import { a as assign } from './log-655aa404.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-655aa404.esm.js';
2
+ import { t as toArray, c as createActor } from './raise-b0a4e862.esm.js';
3
+ export { A as Actor, d as __unsafe_getAllOwnEventDescriptors, a as and, f as cancel, c as createActor, g as getStateNodes, i as interpret, b as isMachineSnapshot, m as matchesState, n as not, o as or, p as pathToStateValue, r as raise, h as spawnChild, s as stateIn, j as stop, k as stopChild, e as toObserver } from './raise-b0a4e862.esm.js';
4
+ import { S as StateMachine } from './StateMachine-c88ea5dd.esm.js';
5
+ export { S as StateMachine, a as StateNode } from './StateMachine-c88ea5dd.esm.js';
6
+ export { S as SpecialTargets, e as emit, a as enqueueActions, f as forwardTo, l as log, s as sendParent, b as sendTo } from './log-1c257a58.esm.js';
7
+ export { a as assign } from './assign-c3259787.esm.js';
6
8
  import '../dev/dist/xstate-dev.esm.js';
7
9
 
8
10
  /**
@@ -36,559 +38,6 @@ function assertEvent(event, type) {
36
38
  }
37
39
  }
38
40
 
39
- const cache = new WeakMap();
40
- function memo(object, key, fn) {
41
- let memoizedData = cache.get(object);
42
- if (!memoizedData) {
43
- memoizedData = {
44
- [key]: fn()
45
- };
46
- cache.set(object, memoizedData);
47
- } else if (!(key in memoizedData)) {
48
- memoizedData[key] = fn();
49
- }
50
- return memoizedData[key];
51
- }
52
-
53
- const EMPTY_OBJECT = {};
54
- const toSerializableAction = action => {
55
- if (typeof action === 'string') {
56
- return {
57
- type: action
58
- };
59
- }
60
- if (typeof action === 'function') {
61
- if ('resolve' in action) {
62
- return {
63
- type: action.type
64
- };
65
- }
66
- return {
67
- type: action.name
68
- };
69
- }
70
- return action;
71
- };
72
- class StateNode {
73
- constructor(/** The raw config used to create the machine. */
74
- config, options) {
75
- this.config = config;
76
- /**
77
- * The relative key of the state node, which represents its location in the
78
- * overall state value.
79
- */
80
- this.key = void 0;
81
- /** The unique ID of the state node. */
82
- this.id = void 0;
83
- /**
84
- * The type of this state node:
85
- *
86
- * - `'atomic'` - no child state nodes
87
- * - `'compound'` - nested child state nodes (XOR)
88
- * - `'parallel'` - orthogonal nested child state nodes (AND)
89
- * - `'history'` - history state node
90
- * - `'final'` - final state node
91
- */
92
- this.type = void 0;
93
- /** The string path from the root machine node to this node. */
94
- this.path = void 0;
95
- /** The child state nodes. */
96
- this.states = void 0;
97
- /**
98
- * The type of history on this state node. Can be:
99
- *
100
- * - `'shallow'` - recalls only top-level historical state value
101
- * - `'deep'` - recalls historical state value at all levels
102
- */
103
- this.history = void 0;
104
- /** The action(s) to be executed upon entering the state node. */
105
- this.entry = void 0;
106
- /** The action(s) to be executed upon exiting the state node. */
107
- this.exit = void 0;
108
- /** The parent state node. */
109
- this.parent = void 0;
110
- /** The root machine node. */
111
- this.machine = void 0;
112
- /**
113
- * The meta data associated with this state node, which will be returned in
114
- * State instances.
115
- */
116
- this.meta = void 0;
117
- /**
118
- * The output data sent with the "xstate.done.state._id_" event if this is a
119
- * final state node.
120
- */
121
- this.output = void 0;
122
- /**
123
- * The order this state node appears. Corresponds to the implicit document
124
- * order.
125
- */
126
- this.order = -1;
127
- this.description = void 0;
128
- this.tags = [];
129
- this.transitions = void 0;
130
- this.always = void 0;
131
- this.parent = options._parent;
132
- this.key = options._key;
133
- this.machine = options._machine;
134
- this.path = this.parent ? this.parent.path.concat(this.key) : [];
135
- this.id = this.config.id || [this.machine.id, ...this.path].join(STATE_DELIMITER);
136
- this.type = this.config.type || (this.config.states && Object.keys(this.config.states).length ? 'compound' : this.config.history ? 'history' : 'atomic');
137
- this.description = this.config.description;
138
- this.order = this.machine.idMap.size;
139
- this.machine.idMap.set(this.id, this);
140
- this.states = this.config.states ? mapValues(this.config.states, (stateConfig, key) => {
141
- const stateNode = new StateNode(stateConfig, {
142
- _parent: this,
143
- _key: key,
144
- _machine: this.machine
145
- });
146
- return stateNode;
147
- }) : EMPTY_OBJECT;
148
- if (this.type === 'compound' && !this.config.initial) {
149
- throw new Error(`No initial state specified for compound state node "#${this.id}". Try adding { initial: "${Object.keys(this.states)[0]}" } to the state config.`);
150
- }
151
-
152
- // History config
153
- this.history = this.config.history === true ? 'shallow' : this.config.history || false;
154
- this.entry = toArray(this.config.entry).slice();
155
- this.exit = toArray(this.config.exit).slice();
156
- this.meta = this.config.meta;
157
- this.output = this.type === 'final' || !this.parent ? this.config.output : undefined;
158
- this.tags = toArray(config.tags).slice();
159
- }
160
-
161
- /** @internal */
162
- _initialize() {
163
- this.transitions = formatTransitions(this);
164
- if (this.config.always) {
165
- this.always = toTransitionConfigArray(this.config.always).map(t => formatTransition(this, NULL_EVENT, t));
166
- }
167
- Object.keys(this.states).forEach(key => {
168
- this.states[key]._initialize();
169
- });
170
- }
171
-
172
- /** The well-structured state node definition. */
173
- get definition() {
174
- return {
175
- id: this.id,
176
- key: this.key,
177
- version: this.machine.version,
178
- type: this.type,
179
- initial: this.initial ? {
180
- target: this.initial.target,
181
- source: this,
182
- actions: this.initial.actions.map(toSerializableAction),
183
- eventType: null,
184
- reenter: false,
185
- toJSON: () => ({
186
- target: this.initial.target.map(t => `#${t.id}`),
187
- source: `#${this.id}`,
188
- actions: this.initial.actions.map(toSerializableAction),
189
- eventType: null
190
- })
191
- } : undefined,
192
- history: this.history,
193
- states: mapValues(this.states, state => {
194
- return state.definition;
195
- }),
196
- on: this.on,
197
- transitions: [...this.transitions.values()].flat().map(t => ({
198
- ...t,
199
- actions: t.actions.map(toSerializableAction)
200
- })),
201
- entry: this.entry.map(toSerializableAction),
202
- exit: this.exit.map(toSerializableAction),
203
- meta: this.meta,
204
- order: this.order || -1,
205
- output: this.output,
206
- invoke: this.invoke,
207
- description: this.description,
208
- tags: this.tags
209
- };
210
- }
211
-
212
- /** @internal */
213
- toJSON() {
214
- return this.definition;
215
- }
216
-
217
- /** The logic invoked as actors by this state node. */
218
- get invoke() {
219
- return memo(this, 'invoke', () => toArray(this.config.invoke).map((invokeConfig, i) => {
220
- const {
221
- src,
222
- systemId
223
- } = invokeConfig;
224
- const resolvedId = invokeConfig.id ?? createInvokeId(this.id, i);
225
- const sourceName = typeof src === 'string' ? src : `xstate.invoke.${createInvokeId(this.id, i)}`;
226
- return {
227
- ...invokeConfig,
228
- src: sourceName,
229
- id: resolvedId,
230
- systemId: systemId,
231
- toJSON() {
232
- const {
233
- onDone,
234
- onError,
235
- ...invokeDefValues
236
- } = invokeConfig;
237
- return {
238
- ...invokeDefValues,
239
- type: 'xstate.invoke',
240
- src: sourceName,
241
- id: resolvedId
242
- };
243
- }
244
- };
245
- }));
246
- }
247
-
248
- /** The mapping of events to transitions. */
249
- get on() {
250
- return memo(this, 'on', () => {
251
- const transitions = this.transitions;
252
- return [...transitions].flatMap(([descriptor, t]) => t.map(t => [descriptor, t])).reduce((map, [descriptor, transition]) => {
253
- map[descriptor] = map[descriptor] || [];
254
- map[descriptor].push(transition);
255
- return map;
256
- }, {});
257
- });
258
- }
259
- get after() {
260
- return memo(this, 'delayedTransitions', () => getDelayedTransitions(this));
261
- }
262
- get initial() {
263
- return memo(this, 'initial', () => formatInitialTransition(this, this.config.initial));
264
- }
265
-
266
- /** @internal */
267
- next(snapshot, event) {
268
- const eventType = event.type;
269
- const actions = [];
270
- let selectedTransition;
271
- const candidates = memo(this, `candidates-${eventType}`, () => getCandidates(this, eventType));
272
- for (const candidate of candidates) {
273
- const {
274
- guard
275
- } = candidate;
276
- const resolvedContext = snapshot.context;
277
- let guardPassed = false;
278
- try {
279
- guardPassed = !guard || evaluateGuard(guard, resolvedContext, event, snapshot);
280
- } catch (err) {
281
- const guardType = typeof guard === 'string' ? guard : typeof guard === 'object' ? guard.type : undefined;
282
- throw new Error(`Unable to evaluate guard ${guardType ? `'${guardType}' ` : ''}in transition for event '${eventType}' in state node '${this.id}':\n${err.message}`);
283
- }
284
- if (guardPassed) {
285
- actions.push(...candidate.actions);
286
- selectedTransition = candidate;
287
- break;
288
- }
289
- }
290
- return selectedTransition ? [selectedTransition] : undefined;
291
- }
292
-
293
- /** All the event types accepted by this state node and its descendants. */
294
- get events() {
295
- return memo(this, 'events', () => {
296
- const {
297
- states
298
- } = this;
299
- const events = new Set(this.ownEvents);
300
- if (states) {
301
- for (const stateId of Object.keys(states)) {
302
- const state = states[stateId];
303
- if (state.states) {
304
- for (const event of state.events) {
305
- events.add(`${event}`);
306
- }
307
- }
308
- }
309
- }
310
- return Array.from(events);
311
- });
312
- }
313
-
314
- /**
315
- * All the events that have transitions directly from this state node.
316
- *
317
- * Excludes any inert events.
318
- */
319
- get ownEvents() {
320
- const events = new Set([...this.transitions.keys()].filter(descriptor => {
321
- return this.transitions.get(descriptor).some(transition => !(!transition.target && !transition.actions.length && !transition.reenter));
322
- }));
323
- return Array.from(events);
324
- }
325
- }
326
-
327
- const STATE_IDENTIFIER = '#';
328
- class StateMachine {
329
- constructor(/** The raw config used to create the machine. */
330
- config, implementations) {
331
- this.config = config;
332
- /** The machine's own version. */
333
- this.version = void 0;
334
- this.schemas = void 0;
335
- this.implementations = void 0;
336
- /** @internal */
337
- this.__xstatenode = true;
338
- /** @internal */
339
- this.idMap = new Map();
340
- this.root = void 0;
341
- this.id = void 0;
342
- this.states = void 0;
343
- this.events = void 0;
344
- this.id = config.id || '(machine)';
345
- this.implementations = {
346
- actors: implementations?.actors ?? {},
347
- actions: implementations?.actions ?? {},
348
- delays: implementations?.delays ?? {},
349
- guards: implementations?.guards ?? {}
350
- };
351
- this.version = this.config.version;
352
- this.schemas = this.config.schemas;
353
- this.transition = this.transition.bind(this);
354
- this.getInitialSnapshot = this.getInitialSnapshot.bind(this);
355
- this.getPersistedSnapshot = this.getPersistedSnapshot.bind(this);
356
- this.restoreSnapshot = this.restoreSnapshot.bind(this);
357
- this.start = this.start.bind(this);
358
- this.root = new StateNode(config, {
359
- _key: this.id,
360
- _machine: this
361
- });
362
- this.root._initialize();
363
- this.states = this.root.states; // TODO: remove!
364
- this.events = this.root.events;
365
- }
366
-
367
- /**
368
- * Clones this state machine with the provided implementations.
369
- *
370
- * @param implementations Options (`actions`, `guards`, `actors`, `delays`)
371
- * to recursively merge with the existing options.
372
- * @returns A new `StateMachine` instance with the provided implementations.
373
- */
374
- provide(implementations) {
375
- const {
376
- actions,
377
- guards,
378
- actors,
379
- delays
380
- } = this.implementations;
381
- return new StateMachine(this.config, {
382
- actions: {
383
- ...actions,
384
- ...implementations.actions
385
- },
386
- guards: {
387
- ...guards,
388
- ...implementations.guards
389
- },
390
- actors: {
391
- ...actors,
392
- ...implementations.actors
393
- },
394
- delays: {
395
- ...delays,
396
- ...implementations.delays
397
- }
398
- });
399
- }
400
- resolveState(config) {
401
- const resolvedStateValue = resolveStateValue(this.root, config.value);
402
- const nodeSet = getAllStateNodes(getStateNodes(this.root, resolvedStateValue));
403
- return createMachineSnapshot({
404
- _nodes: [...nodeSet],
405
- context: config.context || {},
406
- children: {},
407
- status: isInFinalState(nodeSet, this.root) ? 'done' : config.status || 'active',
408
- output: config.output,
409
- error: config.error,
410
- historyValue: config.historyValue
411
- }, this);
412
- }
413
-
414
- /**
415
- * Determines the next snapshot given the current `snapshot` and received
416
- * `event`. Calculates a full macrostep from all microsteps.
417
- *
418
- * @param snapshot The current snapshot
419
- * @param event The received event
420
- */
421
- transition(snapshot, event, actorScope) {
422
- return macrostep(snapshot, event, actorScope, []).snapshot;
423
- }
424
-
425
- /**
426
- * Determines the next state given the current `state` and `event`. Calculates
427
- * a microstep.
428
- *
429
- * @param state The current state
430
- * @param event The received event
431
- */
432
- microstep(snapshot, event, actorScope) {
433
- return macrostep(snapshot, event, actorScope, []).microstates;
434
- }
435
- getTransitionData(snapshot, event) {
436
- return transitionNode(this.root, snapshot.value, snapshot, event) || [];
437
- }
438
-
439
- /**
440
- * The initial state _before_ evaluating any microsteps. This "pre-initial"
441
- * state is provided to initial actions executed in the initial state.
442
- */
443
- getPreInitialState(actorScope, initEvent, internalQueue) {
444
- const {
445
- context
446
- } = this.config;
447
- const preInitial = createMachineSnapshot({
448
- context: typeof context !== 'function' && context ? context : {},
449
- _nodes: [this.root],
450
- children: {},
451
- status: 'active'
452
- }, this);
453
- if (typeof context === 'function') {
454
- const assignment = ({
455
- spawn,
456
- event,
457
- self
458
- }) => context({
459
- spawn,
460
- input: event.input,
461
- self
462
- });
463
- return resolveActionsAndContext(preInitial, initEvent, actorScope, [assign(assignment)], internalQueue, undefined);
464
- }
465
- return preInitial;
466
- }
467
-
468
- /**
469
- * Returns the initial `State` instance, with reference to `self` as an
470
- * `ActorRef`.
471
- */
472
- getInitialSnapshot(actorScope, input) {
473
- const initEvent = createInitEvent(input); // TODO: fix;
474
- const internalQueue = [];
475
- const preInitialState = this.getPreInitialState(actorScope, initEvent, internalQueue);
476
- const nextState = microstep([{
477
- target: [...getInitialStateNodes(this.root)],
478
- source: this.root,
479
- reenter: true,
480
- actions: [],
481
- eventType: null,
482
- toJSON: null // TODO: fix
483
- }], preInitialState, actorScope, initEvent, true, internalQueue);
484
- const {
485
- snapshot: macroState
486
- } = macrostep(nextState, initEvent, actorScope, internalQueue);
487
- return macroState;
488
- }
489
- start(snapshot) {
490
- Object.values(snapshot.children).forEach(child => {
491
- if (child.getSnapshot().status === 'active') {
492
- child.start();
493
- }
494
- });
495
- }
496
- getStateNodeById(stateId) {
497
- const fullPath = toStatePath(stateId);
498
- const relativePath = fullPath.slice(1);
499
- const resolvedStateId = isStateId(fullPath[0]) ? fullPath[0].slice(STATE_IDENTIFIER.length) : fullPath[0];
500
- const stateNode = this.idMap.get(resolvedStateId);
501
- if (!stateNode) {
502
- throw new Error(`Child state node '#${resolvedStateId}' does not exist on machine '${this.id}'`);
503
- }
504
- return getStateNodeByPath(stateNode, relativePath);
505
- }
506
- get definition() {
507
- return this.root.definition;
508
- }
509
- toJSON() {
510
- return this.definition;
511
- }
512
- getPersistedSnapshot(snapshot, options) {
513
- return getPersistedSnapshot(snapshot, options);
514
- }
515
- restoreSnapshot(snapshot, _actorScope) {
516
- const children = {};
517
- const snapshotChildren = snapshot.children;
518
- Object.keys(snapshotChildren).forEach(actorId => {
519
- const actorData = snapshotChildren[actorId];
520
- const childState = actorData.snapshot;
521
- const src = actorData.src;
522
- const logic = typeof src === 'string' ? resolveReferencedActor(this, src) : src;
523
- if (!logic) {
524
- return;
525
- }
526
- const actorRef = createActor(logic, {
527
- id: actorId,
528
- parent: _actorScope.self,
529
- syncSnapshot: actorData.syncSnapshot,
530
- snapshot: childState,
531
- src,
532
- systemId: actorData.systemId
533
- });
534
- children[actorId] = actorRef;
535
- });
536
- function resolveHistoryReferencedState(root, referenced) {
537
- if (referenced instanceof StateNode) {
538
- return referenced;
539
- }
540
- try {
541
- return root.machine.getStateNodeById(referenced.id);
542
- } catch {
543
- }
544
- }
545
- function reviveHistoryValue(root, historyValue) {
546
- if (!historyValue || typeof historyValue !== 'object') {
547
- return {};
548
- }
549
- const revived = {};
550
- for (const key in historyValue) {
551
- const arr = historyValue[key];
552
- for (const item of arr) {
553
- const resolved = resolveHistoryReferencedState(root, item);
554
- if (!resolved) {
555
- continue;
556
- }
557
- revived[key] ??= [];
558
- revived[key].push(resolved);
559
- }
560
- }
561
- return revived;
562
- }
563
- const revivedHistoryValue = reviveHistoryValue(this.root, snapshot.historyValue);
564
- const restoredSnapshot = createMachineSnapshot({
565
- ...snapshot,
566
- children,
567
- _nodes: Array.from(getAllStateNodes(getStateNodes(this.root, snapshot.value))),
568
- historyValue: revivedHistoryValue
569
- }, this);
570
- const seen = new Set();
571
- function reviveContext(contextPart, children) {
572
- if (seen.has(contextPart)) {
573
- return;
574
- }
575
- seen.add(contextPart);
576
- for (const key in contextPart) {
577
- const value = contextPart[key];
578
- if (value && typeof value === 'object') {
579
- if ('xstate$$type' in value && value.xstate$$type === $$ACTOR_TYPE) {
580
- contextPart[key] = children[value.id];
581
- continue;
582
- }
583
- reviveContext(value, children);
584
- }
585
- }
586
- }
587
- reviveContext(restoredSnapshot.context, children);
588
- return restoredSnapshot;
589
- }
590
- }
591
-
592
41
  /**
593
42
  * Creates a state machine (statechart) with the given configuration.
594
43
  *
@@ -957,4 +406,4 @@ function waitFor(actorRef, predicate, options) {
957
406
  });
958
407
  }
959
408
 
960
- export { SimulatedClock, StateMachine, StateNode, assertEvent, createMachine, getInitialSnapshot, getNextSnapshot, initialTransition, setup, toPromise, transition, waitFor };
409
+ export { SimulatedClock, assertEvent, createMachine, getInitialSnapshot, getNextSnapshot, initialTransition, setup, toPromise, transition, waitFor };