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