xstate 5.19.4 → 5.20.0

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 (62) 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/graph/TestModel.d.ts +71 -0
  25. package/dist/declarations/src/graph/adjacency.d.ts +8 -0
  26. package/dist/declarations/src/graph/graph.d.ts +14 -0
  27. package/dist/declarations/src/graph/index.d.ts +9 -0
  28. package/dist/declarations/src/graph/pathFromEvents.d.ts +3 -0
  29. package/dist/declarations/src/graph/pathGenerators.d.ts +4 -0
  30. package/dist/declarations/src/graph/shortestPaths.d.ts +3 -0
  31. package/dist/declarations/src/graph/simplePaths.d.ts +3 -0
  32. package/dist/declarations/src/graph/types.d.ts +159 -0
  33. package/dist/{log-655aa404.esm.js → log-1c257a58.esm.js} +3 -126
  34. package/dist/{log-fa2e731a.cjs.js → log-215998b6.cjs.js} +2 -126
  35. package/dist/{log-fadc8808.development.cjs.js → log-2c8d7f98.development.cjs.js} +2 -132
  36. package/dist/{log-5a7b5528.development.esm.js → log-ef959da6.development.esm.js} +3 -132
  37. package/dist/{raise-59549771.development.esm.js → raise-78b8dcb8.development.esm.js} +1 -1
  38. package/dist/{raise-3e01e82a.esm.js → raise-b0a4e862.esm.js} +1 -1
  39. package/dist/xstate.cjs.d.ts +1 -1
  40. package/dist/xstate.cjs.js +7 -558
  41. package/dist/xstate.development.cjs.js +7 -564
  42. package/dist/xstate.development.esm.js +7 -564
  43. package/dist/xstate.esm.js +7 -558
  44. package/dist/xstate.umd.min.js +1 -1
  45. package/dist/xstate.umd.min.js.map +1 -1
  46. package/graph/dist/xstate-graph.cjs.d.mts +2 -0
  47. package/graph/dist/xstate-graph.cjs.d.ts +2 -0
  48. package/graph/dist/xstate-graph.cjs.js +901 -0
  49. package/graph/dist/xstate-graph.cjs.mjs +15 -0
  50. package/graph/dist/xstate-graph.development.cjs.js +901 -0
  51. package/graph/dist/xstate-graph.development.cjs.mjs +15 -0
  52. package/graph/dist/xstate-graph.development.esm.js +885 -0
  53. package/graph/dist/xstate-graph.esm.js +885 -0
  54. package/graph/dist/xstate-graph.umd.min.js +2 -0
  55. package/graph/dist/xstate-graph.umd.min.js.map +1 -0
  56. package/graph/package.json +8 -0
  57. package/guards/dist/xstate-guards.cjs.d.ts +1 -1
  58. package/guards/dist/xstate-guards.development.esm.js +1 -1
  59. package/guards/dist/xstate-guards.esm.js +1 -1
  60. package/guards/dist/xstate-guards.umd.min.js +1 -1
  61. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  62. 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.cjs.js');
6
6
  var guards_dist_xstateGuards = require('./raise-5872b9e8.cjs.js');
7
- var log = require('./log-fa2e731a.cjs.js');
7
+ var StateMachine = require('./StateMachine-1cda96d3.cjs.js');
8
+ var log = require('./log-215998b6.cjs.js');
9
+ var assign = require('./assign-e9c344ea.cjs.js');
8
10
  require('../dev/dist/xstate-dev.cjs.js');
9
11
 
10
12
  /**
@@ -38,559 +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
- }
368
-
369
- /**
370
- * Clones this state machine with the provided implementations.
371
- *
372
- * @param implementations Options (`actions`, `guards`, `actors`, `delays`)
373
- * to recursively merge with the existing options.
374
- * @returns A new `StateMachine` instance with the provided implementations.
375
- */
376
- provide(implementations) {
377
- const {
378
- actions,
379
- guards,
380
- actors,
381
- delays
382
- } = this.implementations;
383
- return new StateMachine(this.config, {
384
- actions: {
385
- ...actions,
386
- ...implementations.actions
387
- },
388
- guards: {
389
- ...guards,
390
- ...implementations.guards
391
- },
392
- actors: {
393
- ...actors,
394
- ...implementations.actors
395
- },
396
- delays: {
397
- ...delays,
398
- ...implementations.delays
399
- }
400
- });
401
- }
402
- resolveState(config) {
403
- const resolvedStateValue = guards_dist_xstateGuards.resolveStateValue(this.root, config.value);
404
- const nodeSet = guards_dist_xstateGuards.getAllStateNodes(guards_dist_xstateGuards.getStateNodes(this.root, resolvedStateValue));
405
- return guards_dist_xstateGuards.createMachineSnapshot({
406
- _nodes: [...nodeSet],
407
- context: config.context || {},
408
- children: {},
409
- status: guards_dist_xstateGuards.isInFinalState(nodeSet, this.root) ? 'done' : config.status || 'active',
410
- output: config.output,
411
- error: config.error,
412
- historyValue: config.historyValue
413
- }, this);
414
- }
415
-
416
- /**
417
- * Determines the next snapshot given the current `snapshot` and received
418
- * `event`. Calculates a full macrostep from all microsteps.
419
- *
420
- * @param snapshot The current snapshot
421
- * @param event The received event
422
- */
423
- transition(snapshot, event, actorScope) {
424
- return guards_dist_xstateGuards.macrostep(snapshot, event, actorScope, []).snapshot;
425
- }
426
-
427
- /**
428
- * Determines the next state given the current `state` and `event`. Calculates
429
- * a microstep.
430
- *
431
- * @param state The current state
432
- * @param event The received event
433
- */
434
- microstep(snapshot, event, actorScope) {
435
- return guards_dist_xstateGuards.macrostep(snapshot, event, actorScope, []).microstates;
436
- }
437
- getTransitionData(snapshot, event) {
438
- return guards_dist_xstateGuards.transitionNode(this.root, snapshot.value, snapshot, event) || [];
439
- }
440
-
441
- /**
442
- * The initial state _before_ evaluating any microsteps. This "pre-initial"
443
- * state is provided to initial actions executed in the initial state.
444
- */
445
- getPreInitialState(actorScope, initEvent, internalQueue) {
446
- const {
447
- context
448
- } = this.config;
449
- const preInitial = guards_dist_xstateGuards.createMachineSnapshot({
450
- context: typeof context !== 'function' && context ? context : {},
451
- _nodes: [this.root],
452
- children: {},
453
- status: 'active'
454
- }, this);
455
- if (typeof context === 'function') {
456
- const assignment = ({
457
- spawn,
458
- event,
459
- self
460
- }) => context({
461
- spawn,
462
- input: event.input,
463
- self
464
- });
465
- return guards_dist_xstateGuards.resolveActionsAndContext(preInitial, initEvent, actorScope, [log.assign(assignment)], internalQueue, undefined);
466
- }
467
- return preInitial;
468
- }
469
-
470
- /**
471
- * Returns the initial `State` instance, with reference to `self` as an
472
- * `ActorRef`.
473
- */
474
- getInitialSnapshot(actorScope, input) {
475
- const initEvent = guards_dist_xstateGuards.createInitEvent(input); // TODO: fix;
476
- const internalQueue = [];
477
- const preInitialState = this.getPreInitialState(actorScope, initEvent, internalQueue);
478
- const nextState = guards_dist_xstateGuards.microstep([{
479
- target: [...guards_dist_xstateGuards.getInitialStateNodes(this.root)],
480
- source: this.root,
481
- reenter: true,
482
- actions: [],
483
- eventType: null,
484
- toJSON: null // TODO: fix
485
- }], preInitialState, actorScope, initEvent, true, internalQueue);
486
- const {
487
- snapshot: macroState
488
- } = guards_dist_xstateGuards.macrostep(nextState, initEvent, actorScope, internalQueue);
489
- return macroState;
490
- }
491
- start(snapshot) {
492
- Object.values(snapshot.children).forEach(child => {
493
- if (child.getSnapshot().status === 'active') {
494
- child.start();
495
- }
496
- });
497
- }
498
- getStateNodeById(stateId) {
499
- const fullPath = guards_dist_xstateGuards.toStatePath(stateId);
500
- const relativePath = fullPath.slice(1);
501
- const resolvedStateId = guards_dist_xstateGuards.isStateId(fullPath[0]) ? fullPath[0].slice(STATE_IDENTIFIER.length) : fullPath[0];
502
- const stateNode = this.idMap.get(resolvedStateId);
503
- if (!stateNode) {
504
- throw new Error(`Child state node '#${resolvedStateId}' does not exist on machine '${this.id}'`);
505
- }
506
- return guards_dist_xstateGuards.getStateNodeByPath(stateNode, relativePath);
507
- }
508
- get definition() {
509
- return this.root.definition;
510
- }
511
- toJSON() {
512
- return this.definition;
513
- }
514
- getPersistedSnapshot(snapshot, options) {
515
- return guards_dist_xstateGuards.getPersistedSnapshot(snapshot, options);
516
- }
517
- restoreSnapshot(snapshot, _actorScope) {
518
- const children = {};
519
- const snapshotChildren = snapshot.children;
520
- Object.keys(snapshotChildren).forEach(actorId => {
521
- const actorData = snapshotChildren[actorId];
522
- const childState = actorData.snapshot;
523
- const src = actorData.src;
524
- const logic = typeof src === 'string' ? guards_dist_xstateGuards.resolveReferencedActor(this, src) : src;
525
- if (!logic) {
526
- return;
527
- }
528
- const actorRef = guards_dist_xstateGuards.createActor(logic, {
529
- id: actorId,
530
- parent: _actorScope.self,
531
- syncSnapshot: actorData.syncSnapshot,
532
- snapshot: childState,
533
- src,
534
- systemId: actorData.systemId
535
- });
536
- children[actorId] = actorRef;
537
- });
538
- function resolveHistoryReferencedState(root, referenced) {
539
- if (referenced instanceof StateNode) {
540
- return referenced;
541
- }
542
- try {
543
- return root.machine.getStateNodeById(referenced.id);
544
- } catch {
545
- }
546
- }
547
- function reviveHistoryValue(root, historyValue) {
548
- if (!historyValue || typeof historyValue !== 'object') {
549
- return {};
550
- }
551
- const revived = {};
552
- for (const key in historyValue) {
553
- const arr = historyValue[key];
554
- for (const item of arr) {
555
- const resolved = resolveHistoryReferencedState(root, item);
556
- if (!resolved) {
557
- continue;
558
- }
559
- revived[key] ??= [];
560
- revived[key].push(resolved);
561
- }
562
- }
563
- return revived;
564
- }
565
- const revivedHistoryValue = reviveHistoryValue(this.root, snapshot.historyValue);
566
- const restoredSnapshot = guards_dist_xstateGuards.createMachineSnapshot({
567
- ...snapshot,
568
- children,
569
- _nodes: Array.from(guards_dist_xstateGuards.getAllStateNodes(guards_dist_xstateGuards.getStateNodes(this.root, snapshot.value))),
570
- historyValue: revivedHistoryValue
571
- }, this);
572
- const seen = new Set();
573
- function reviveContext(contextPart, children) {
574
- if (seen.has(contextPart)) {
575
- return;
576
- }
577
- seen.add(contextPart);
578
- for (const key in contextPart) {
579
- const value = contextPart[key];
580
- if (value && typeof value === 'object') {
581
- if ('xstate$$type' in value && value.xstate$$type === guards_dist_xstateGuards.$$ACTOR_TYPE) {
582
- contextPart[key] = children[value.id];
583
- continue;
584
- }
585
- reviveContext(value, children);
586
- }
587
- }
588
- }
589
- reviveContext(restoredSnapshot.context, children);
590
- return restoredSnapshot;
591
- }
592
- }
593
-
594
43
  /**
595
44
  * Creates a state machine (statechart) with the given configuration.
596
45
  *
@@ -634,7 +83,7 @@ class StateMachine {
634
83
  * to provide machine implementations instead.
635
84
  */
636
85
  function createMachine(config, implementations) {
637
- return new StateMachine(config, implementations);
86
+ return new StateMachine.StateMachine(config, implementations);
638
87
  }
639
88
 
640
89
  /** @internal */
@@ -983,17 +432,17 @@ exports.stateIn = guards_dist_xstateGuards.stateIn;
983
432
  exports.stop = guards_dist_xstateGuards.stop;
984
433
  exports.stopChild = guards_dist_xstateGuards.stopChild;
985
434
  exports.toObserver = guards_dist_xstateGuards.toObserver;
435
+ exports.StateMachine = StateMachine.StateMachine;
436
+ exports.StateNode = StateMachine.StateNode;
986
437
  exports.SpecialTargets = log.SpecialTargets;
987
- exports.assign = log.assign;
988
438
  exports.emit = log.emit;
989
439
  exports.enqueueActions = log.enqueueActions;
990
440
  exports.forwardTo = log.forwardTo;
991
441
  exports.log = log.log;
992
442
  exports.sendParent = log.sendParent;
993
443
  exports.sendTo = log.sendTo;
444
+ exports.assign = assign.assign;
994
445
  exports.SimulatedClock = SimulatedClock;
995
- exports.StateMachine = StateMachine;
996
- exports.StateNode = StateNode;
997
446
  exports.assertEvent = assertEvent;
998
447
  exports.createMachine = createMachine;
999
448
  exports.getInitialSnapshot = getInitialSnapshot;