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