xstate 5.0.0-beta.14 → 5.0.0-beta.16

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 (46) hide show
  1. package/actions/dist/xstate-actions.cjs.js +1 -3
  2. package/actions/dist/xstate-actions.cjs.mjs +0 -2
  3. package/actions/dist/xstate-actions.development.cjs.js +1 -3
  4. package/actions/dist/xstate-actions.development.esm.js +1 -1
  5. package/actions/dist/xstate-actions.esm.js +1 -1
  6. package/actions/dist/xstate-actions.umd.min.js +1 -1
  7. package/actions/dist/xstate-actions.umd.min.js.map +1 -1
  8. package/actors/dist/xstate-actors.cjs.js +1 -1
  9. package/actors/dist/xstate-actors.development.cjs.js +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 +1 -1
  13. package/actors/dist/xstate-actors.umd.min.js.map +1 -1
  14. package/dist/{actions-444a17c3.esm.js → actions-0386b622.esm.js} +934 -997
  15. package/dist/{actions-73b8d456.development.cjs.js → actions-0f903c0d.development.cjs.js} +863 -928
  16. package/dist/{actions-17c3bcfa.cjs.js → actions-6b9073db.cjs.js} +934 -999
  17. package/dist/{actions-60622c0c.development.esm.js → actions-6f7fbc84.development.esm.js} +863 -926
  18. package/dist/declarations/src/State.d.ts +1 -11
  19. package/dist/declarations/src/StateMachine.d.ts +4 -11
  20. package/dist/declarations/src/actionTypes.d.ts +1 -1
  21. package/dist/declarations/src/actions/assign.d.ts +2 -2
  22. package/dist/declarations/src/actions/cancel.d.ts +2 -2
  23. package/dist/declarations/src/actions/send.d.ts +12 -22
  24. package/dist/declarations/src/actions/stop.d.ts +2 -2
  25. package/dist/declarations/src/actions.d.ts +1 -4
  26. package/dist/declarations/src/actors/callback.d.ts +3 -3
  27. package/dist/declarations/src/actors/index.d.ts +1 -1
  28. package/dist/declarations/src/actors/promise.d.ts +13 -3
  29. package/dist/declarations/src/guards.d.ts +1 -1
  30. package/dist/declarations/src/interpreter.d.ts +2 -2
  31. package/dist/declarations/src/stateUtils.d.ts +3 -2
  32. package/dist/declarations/src/types.d.ts +44 -71
  33. package/dist/declarations/src/utils.d.ts +3 -3
  34. package/dist/xstate.cjs.js +44 -59
  35. package/dist/xstate.development.cjs.js +44 -59
  36. package/dist/xstate.development.esm.js +45 -60
  37. package/dist/xstate.esm.js +45 -60
  38. package/dist/xstate.umd.min.js +1 -1
  39. package/dist/xstate.umd.min.js.map +1 -1
  40. package/guards/dist/xstate-guards.cjs.js +1 -1
  41. package/guards/dist/xstate-guards.development.cjs.js +1 -1
  42. package/guards/dist/xstate-guards.development.esm.js +1 -1
  43. package/guards/dist/xstate-guards.esm.js +1 -1
  44. package/guards/dist/xstate-guards.umd.min.js +1 -1
  45. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  46. package/package.json +2 -1
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var actors_dist_xstateActors = require('./actions-73b8d456.development.cjs.js');
5
+ var actors_dist_xstateActors = require('./actions-0f903c0d.development.cjs.js');
6
6
  require('../dev/dist/xstate-dev.development.cjs.js');
7
7
 
8
8
  const EMPTY_OBJECT = {};
@@ -95,7 +95,7 @@ class StateNode {
95
95
  this.key = options._key;
96
96
  this.machine = options._machine;
97
97
  this.path = this.parent ? this.parent.path.concat(this.key) : [];
98
- this.id = this.config.id || [this.machine.id, ...this.path].join(this.machine.delimiter);
98
+ this.id = this.config.id || [this.machine.id, ...this.path].join(actors_dist_xstateActors.STATE_DELIMITER);
99
99
  this.type = this.config.type || (this.config.states && Object.keys(this.config.states).length ? 'compound' : this.config.history ? 'history' : 'atomic');
100
100
  this.description = this.config.description;
101
101
  this.order = this.machine.idMap.size;
@@ -185,9 +185,9 @@ class StateNode {
185
185
  systemId
186
186
  } = invokeConfig;
187
187
  const resolvedSrc = actors_dist_xstateActors.isString(src) ? src : !('type' in src) ? resolvedId : src;
188
- if (!this.machine.options.actors[resolvedId] && typeof src !== 'string' && !('type' in src)) {
189
- this.machine.options.actors = {
190
- ...this.machine.options.actors,
188
+ if (!this.machine.implementations.actors[resolvedId] && typeof src !== 'string' && !('type' in src)) {
189
+ this.machine.implementations.actors = {
190
+ ...this.machine.implementations.actors,
191
191
  // TODO: this should accept `src` as-is
192
192
  [resolvedId]: src
193
193
  };
@@ -318,33 +318,7 @@ class StateNode {
318
318
  }
319
319
 
320
320
  const STATE_IDENTIFIER = '#';
321
- function createDefaultOptions() {
322
- return {
323
- actions: {},
324
- actors: {},
325
- delays: {},
326
- guards: {},
327
- context: {}
328
- };
329
- }
330
321
  class StateMachine {
331
- // TODO: this getter should be removed
332
- getContext(input) {
333
- return this.getContextAndActions(undefined, input)[0];
334
- }
335
- getContextAndActions(actorCtx, input) {
336
- const actions = [];
337
- const {
338
- context
339
- } = this.config;
340
- const resolvedContext = typeof context === 'function' ? context({
341
- spawn: actors_dist_xstateActors.createSpawner(actorCtx?.self, this, undefined,
342
- // TODO: this requires `| undefined` for all referenced dynamic inputs that are spawnable in the context factory,
343
- actors_dist_xstateActors.createInitEvent(input), actions),
344
- input
345
- }) : context;
346
- return [resolvedContext || {}, actions];
347
- }
348
322
  /**
349
323
  * The machine's own version.
350
324
  */
@@ -353,11 +327,10 @@ class StateMachine {
353
327
  /**
354
328
  * The raw config used to create the machine.
355
329
  */
356
- config, options) {
330
+ config, implementations) {
357
331
  this.config = config;
358
332
  this.version = void 0;
359
- this.delimiter = void 0;
360
- this.options = void 0;
333
+ this.implementations = void 0;
361
334
  this.types = void 0;
362
335
  this.__xstatenode = true;
363
336
  this.idMap = new Map();
@@ -371,8 +344,12 @@ class StateMachine {
371
344
  this.__TActorMap = void 0;
372
345
  this.__TResolvedTypesMeta = void 0;
373
346
  this.id = config.id || '(machine)';
374
- this.options = Object.assign(createDefaultOptions(), options);
375
- this.delimiter = this.config.delimiter || actors_dist_xstateActors.STATE_DELIMITER;
347
+ this.implementations = {
348
+ actors: implementations?.actors ?? {},
349
+ actions: implementations?.actions ?? {},
350
+ delays: implementations?.delays ?? {},
351
+ guards: implementations?.guards ?? {}
352
+ };
376
353
  this.version = this.config.version;
377
354
  this.types = this.config.types ?? {};
378
355
  this.transition = this.transition.bind(this);
@@ -400,7 +377,7 @@ class StateMachine {
400
377
  guards,
401
378
  actors,
402
379
  delays
403
- } = this.options;
380
+ } = this.implementations;
404
381
  return new StateMachine(this.config, {
405
382
  actions: {
406
383
  ...actions,
@@ -438,10 +415,9 @@ class StateMachine {
438
415
  done: actors_dist_xstateActors.isInFinalState(configuration)
439
416
  });
440
417
  }
441
- resolveStateValue(stateValue) {
418
+ resolveStateValue(stateValue, ...[context]) {
442
419
  const resolvedStateValue = actors_dist_xstateActors.resolveStateValue(this.root, stateValue);
443
- const resolvedContext = this.getContext();
444
- return this.resolveState(actors_dist_xstateActors.State.from(resolvedStateValue, resolvedContext, this));
420
+ return this.resolveState(actors_dist_xstateActors.State.from(resolvedStateValue, context, this));
445
421
  }
446
422
 
447
423
  /**
@@ -480,22 +456,27 @@ class StateMachine {
480
456
  * The initial state _before_ evaluating any microsteps.
481
457
  * This "pre-initial" state is provided to initial actions executed in the initial state.
482
458
  */
483
- getPreInitialState(actorCtx, input) {
484
- const [context, actions] = this.getContextAndActions(actorCtx, input);
485
- const config = actors_dist_xstateActors.getInitialConfiguration(this.root);
459
+ getPreInitialState(actorCtx, initEvent) {
460
+ const {
461
+ context
462
+ } = this.config;
486
463
  const preInitial = this.resolveState(this.createState({
487
464
  value: {},
488
465
  // TODO: this is computed in state constructor
489
- context,
466
+ context: typeof context !== 'function' && context ? context : {},
490
467
  meta: undefined,
491
- configuration: config,
492
- transitions: [],
468
+ configuration: actors_dist_xstateActors.getInitialConfiguration(this.root),
493
469
  children: {}
494
470
  }));
495
- preInitial._initial = true;
496
- if (actorCtx) {
497
- const [nextState] = actors_dist_xstateActors.resolveActionsAndContext(actions, actors_dist_xstateActors.initEvent, preInitial, actorCtx);
498
- preInitial.children = nextState.children;
471
+ if (typeof context === 'function') {
472
+ const assignment = ({
473
+ spawn,
474
+ event
475
+ }) => context({
476
+ spawn,
477
+ input: event.input
478
+ });
479
+ return actors_dist_xstateActors.resolveActionsAndContext([actors_dist_xstateActors.assign(assignment)], initEvent, preInitial, actorCtx);
499
480
  }
500
481
  return preInitial;
501
482
  }
@@ -506,8 +487,15 @@ class StateMachine {
506
487
  getInitialState(actorCtx, input) {
507
488
  const initEvent = actors_dist_xstateActors.createInitEvent(input); // TODO: fix;
508
489
 
509
- const preInitialState = this.getPreInitialState(actorCtx, input);
510
- const nextState = actors_dist_xstateActors.microstep([], preInitialState, actorCtx, initEvent);
490
+ const preInitialState = this.getPreInitialState(actorCtx, initEvent);
491
+ const nextState = actors_dist_xstateActors.microstep([{
492
+ target: [...preInitialState.configuration].filter(actors_dist_xstateActors.isAtomicStateNode),
493
+ source: this.root,
494
+ reenter: true,
495
+ actions: [],
496
+ eventType: null,
497
+ toJSON: null // TODO: fix
498
+ }], preInitialState, actorCtx, initEvent, true);
511
499
  const {
512
500
  state: macroState
513
501
  } = actors_dist_xstateActors.macrostep(nextState, initEvent, actorCtx);
@@ -526,7 +514,7 @@ class StateMachine {
526
514
  });
527
515
  }
528
516
  getStateNodeById(stateId) {
529
- const fullPath = stateId.split(this.delimiter);
517
+ const fullPath = stateId.split(actors_dist_xstateActors.STATE_DELIMITER);
530
518
  const relativePath = fullPath.slice(1);
531
519
  const resolvedStateId = actors_dist_xstateActors.isStateId(fullPath[0]) ? fullPath[0].slice(STATE_IDENTIFIER.length) : fullPath[0];
532
520
  const stateNode = this.idMap.get(resolvedStateId);
@@ -536,10 +524,7 @@ class StateMachine {
536
524
  return actors_dist_xstateActors.getStateNodeByPath(stateNode, relativePath);
537
525
  }
538
526
  get definition() {
539
- return {
540
- context: this.getContext(),
541
- ...this.root.definition
542
- };
527
+ return this.root.definition;
543
528
  }
544
529
  toJSON() {
545
530
  return this.definition;
@@ -564,7 +549,7 @@ class StateMachine {
564
549
  const actorData = state.children[actorId];
565
550
  const childState = actorData.state;
566
551
  const src = actorData.src;
567
- const logic = src ? actors_dist_xstateActors.resolveReferencedActor(this.options.actors[src])?.src : undefined;
552
+ const logic = src ? actors_dist_xstateActors.resolveReferencedActor(this.implementations.actors[src])?.src : undefined;
568
553
  if (!logic) {
569
554
  return;
570
555
  }
@@ -591,7 +576,7 @@ class StateMachine {
591
576
  if (children[id]) {
592
577
  return;
593
578
  }
594
- const referenced = actors_dist_xstateActors.resolveReferencedActor(this.options.actors[src]);
579
+ const referenced = actors_dist_xstateActors.resolveReferencedActor(this.implementations.actors[src]);
595
580
  if (referenced) {
596
581
  const actorRef = actors_dist_xstateActors.interpret(referenced.src, {
597
582
  id,
@@ -1,5 +1,5 @@
1
- import { m as mapValues, t as toActionObjects, a as toArray, f as formatTransitions, b as toTransitionConfigArray, N as NULL_EVENT, c as formatTransition, d as memo, e as evaluateGuard, g as flatten, h as createInvokeId, i as isString, j as invoke, k as getDelayedTransitions, l as formatInitialTransition, n as getCandidates, o as toInvokeConfig, p as createSpawner, S as STATE_DELIMITER, q as getConfiguration, r as getStateNodes, s as resolveStateValue, u as isInFinalState, v as State, w as isErrorEvent, x as macrostep, y as transitionNode, z as getInitialConfiguration, A as resolveActionsAndContext, B as microstep, C as error, D as isStateId, E as getStateNodeByPath, F as getPersistedState, G as resolveReferencedActor, H as interpret, I as createInitEvent, J as initEvent, K as matchesState } from './actions-60622c0c.development.esm.js';
2
- export { a9 as ActionTypes, P as Interpreter, Q as InterpreterStatus, aa as SpecialTargets, v as State, a7 as and, T as assign, U as cancel, V as choose, R as doneInvoke, O as forwardTo, a2 as fromCallback, a3 as fromEventObservable, a1 as fromObservable, a0 as fromPromise, a4 as fromTransition, r as getStateNodes, H as interpret, W as log, K as matchesState, a6 as not, a8 as or, _ as pathToStateValue, X as pure, Y as raise, M as sendParent, L as sendTo, a5 as stateIn, Z as stop, $ as toObserver } from './actions-60622c0c.development.esm.js';
1
+ import { S as STATE_DELIMITER, m as mapValues, t as toActionObjects, a as toArray, f as formatTransitions, b as toTransitionConfigArray, N as NULL_EVENT, c as formatTransition, d as memo, e as evaluateGuard, g as flatten, h as createInvokeId, i as isString, j as invoke, k as getDelayedTransitions, l as formatInitialTransition, n as getCandidates, o as toInvokeConfig, p as getConfiguration, q as getStateNodes, r as resolveStateValue, s as isInFinalState, u as State, v as isErrorEvent, w as macrostep, x as transitionNode, y as getInitialConfiguration, z as resolveActionsAndContext, A as assign, B as microstep, C as isAtomicStateNode, D as error, E as isStateId, F as getStateNodeByPath, G as getPersistedState, H as resolveReferencedActor, I as interpret, J as createInitEvent, K as matchesState } from './actions-6f7fbc84.development.esm.js';
2
+ export { a8 as ActionTypes, P as Interpreter, Q as InterpreterStatus, a9 as SpecialTargets, u as State, a6 as and, A as assign, T as cancel, U as choose, R as doneInvoke, O as forwardTo, a1 as fromCallback, a2 as fromEventObservable, a0 as fromObservable, $ as fromPromise, a3 as fromTransition, q as getStateNodes, I as interpret, V as log, K as matchesState, a5 as not, a7 as or, Z as pathToStateValue, W as pure, X as raise, M as sendParent, L as sendTo, a4 as stateIn, Y as stop, _ as toObserver } from './actions-6f7fbc84.development.esm.js';
3
3
  import '../dev/dist/xstate-dev.development.esm.js';
4
4
 
5
5
  const EMPTY_OBJECT = {};
@@ -92,7 +92,7 @@ class StateNode {
92
92
  this.key = options._key;
93
93
  this.machine = options._machine;
94
94
  this.path = this.parent ? this.parent.path.concat(this.key) : [];
95
- this.id = this.config.id || [this.machine.id, ...this.path].join(this.machine.delimiter);
95
+ this.id = this.config.id || [this.machine.id, ...this.path].join(STATE_DELIMITER);
96
96
  this.type = this.config.type || (this.config.states && Object.keys(this.config.states).length ? 'compound' : this.config.history ? 'history' : 'atomic');
97
97
  this.description = this.config.description;
98
98
  this.order = this.machine.idMap.size;
@@ -182,9 +182,9 @@ class StateNode {
182
182
  systemId
183
183
  } = invokeConfig;
184
184
  const resolvedSrc = isString(src) ? src : !('type' in src) ? resolvedId : src;
185
- if (!this.machine.options.actors[resolvedId] && typeof src !== 'string' && !('type' in src)) {
186
- this.machine.options.actors = {
187
- ...this.machine.options.actors,
185
+ if (!this.machine.implementations.actors[resolvedId] && typeof src !== 'string' && !('type' in src)) {
186
+ this.machine.implementations.actors = {
187
+ ...this.machine.implementations.actors,
188
188
  // TODO: this should accept `src` as-is
189
189
  [resolvedId]: src
190
190
  };
@@ -315,33 +315,7 @@ class StateNode {
315
315
  }
316
316
 
317
317
  const STATE_IDENTIFIER = '#';
318
- function createDefaultOptions() {
319
- return {
320
- actions: {},
321
- actors: {},
322
- delays: {},
323
- guards: {},
324
- context: {}
325
- };
326
- }
327
318
  class StateMachine {
328
- // TODO: this getter should be removed
329
- getContext(input) {
330
- return this.getContextAndActions(undefined, input)[0];
331
- }
332
- getContextAndActions(actorCtx, input) {
333
- const actions = [];
334
- const {
335
- context
336
- } = this.config;
337
- const resolvedContext = typeof context === 'function' ? context({
338
- spawn: createSpawner(actorCtx?.self, this, undefined,
339
- // TODO: this requires `| undefined` for all referenced dynamic inputs that are spawnable in the context factory,
340
- createInitEvent(input), actions),
341
- input
342
- }) : context;
343
- return [resolvedContext || {}, actions];
344
- }
345
319
  /**
346
320
  * The machine's own version.
347
321
  */
@@ -350,11 +324,10 @@ class StateMachine {
350
324
  /**
351
325
  * The raw config used to create the machine.
352
326
  */
353
- config, options) {
327
+ config, implementations) {
354
328
  this.config = config;
355
329
  this.version = void 0;
356
- this.delimiter = void 0;
357
- this.options = void 0;
330
+ this.implementations = void 0;
358
331
  this.types = void 0;
359
332
  this.__xstatenode = true;
360
333
  this.idMap = new Map();
@@ -368,8 +341,12 @@ class StateMachine {
368
341
  this.__TActorMap = void 0;
369
342
  this.__TResolvedTypesMeta = void 0;
370
343
  this.id = config.id || '(machine)';
371
- this.options = Object.assign(createDefaultOptions(), options);
372
- this.delimiter = this.config.delimiter || STATE_DELIMITER;
344
+ this.implementations = {
345
+ actors: implementations?.actors ?? {},
346
+ actions: implementations?.actions ?? {},
347
+ delays: implementations?.delays ?? {},
348
+ guards: implementations?.guards ?? {}
349
+ };
373
350
  this.version = this.config.version;
374
351
  this.types = this.config.types ?? {};
375
352
  this.transition = this.transition.bind(this);
@@ -397,7 +374,7 @@ class StateMachine {
397
374
  guards,
398
375
  actors,
399
376
  delays
400
- } = this.options;
377
+ } = this.implementations;
401
378
  return new StateMachine(this.config, {
402
379
  actions: {
403
380
  ...actions,
@@ -435,10 +412,9 @@ class StateMachine {
435
412
  done: isInFinalState(configuration)
436
413
  });
437
414
  }
438
- resolveStateValue(stateValue) {
415
+ resolveStateValue(stateValue, ...[context]) {
439
416
  const resolvedStateValue = resolveStateValue(this.root, stateValue);
440
- const resolvedContext = this.getContext();
441
- return this.resolveState(State.from(resolvedStateValue, resolvedContext, this));
417
+ return this.resolveState(State.from(resolvedStateValue, context, this));
442
418
  }
443
419
 
444
420
  /**
@@ -477,22 +453,27 @@ class StateMachine {
477
453
  * The initial state _before_ evaluating any microsteps.
478
454
  * This "pre-initial" state is provided to initial actions executed in the initial state.
479
455
  */
480
- getPreInitialState(actorCtx, input) {
481
- const [context, actions] = this.getContextAndActions(actorCtx, input);
482
- const config = getInitialConfiguration(this.root);
456
+ getPreInitialState(actorCtx, initEvent) {
457
+ const {
458
+ context
459
+ } = this.config;
483
460
  const preInitial = this.resolveState(this.createState({
484
461
  value: {},
485
462
  // TODO: this is computed in state constructor
486
- context,
463
+ context: typeof context !== 'function' && context ? context : {},
487
464
  meta: undefined,
488
- configuration: config,
489
- transitions: [],
465
+ configuration: getInitialConfiguration(this.root),
490
466
  children: {}
491
467
  }));
492
- preInitial._initial = true;
493
- if (actorCtx) {
494
- const [nextState] = resolveActionsAndContext(actions, initEvent, preInitial, actorCtx);
495
- preInitial.children = nextState.children;
468
+ if (typeof context === 'function') {
469
+ const assignment = ({
470
+ spawn,
471
+ event
472
+ }) => context({
473
+ spawn,
474
+ input: event.input
475
+ });
476
+ return resolveActionsAndContext([assign(assignment)], initEvent, preInitial, actorCtx);
496
477
  }
497
478
  return preInitial;
498
479
  }
@@ -503,8 +484,15 @@ class StateMachine {
503
484
  getInitialState(actorCtx, input) {
504
485
  const initEvent = createInitEvent(input); // TODO: fix;
505
486
 
506
- const preInitialState = this.getPreInitialState(actorCtx, input);
507
- const nextState = microstep([], preInitialState, actorCtx, initEvent);
487
+ const preInitialState = this.getPreInitialState(actorCtx, initEvent);
488
+ const nextState = microstep([{
489
+ target: [...preInitialState.configuration].filter(isAtomicStateNode),
490
+ source: this.root,
491
+ reenter: true,
492
+ actions: [],
493
+ eventType: null,
494
+ toJSON: null // TODO: fix
495
+ }], preInitialState, actorCtx, initEvent, true);
508
496
  const {
509
497
  state: macroState
510
498
  } = macrostep(nextState, initEvent, actorCtx);
@@ -523,7 +511,7 @@ class StateMachine {
523
511
  });
524
512
  }
525
513
  getStateNodeById(stateId) {
526
- const fullPath = stateId.split(this.delimiter);
514
+ const fullPath = stateId.split(STATE_DELIMITER);
527
515
  const relativePath = fullPath.slice(1);
528
516
  const resolvedStateId = isStateId(fullPath[0]) ? fullPath[0].slice(STATE_IDENTIFIER.length) : fullPath[0];
529
517
  const stateNode = this.idMap.get(resolvedStateId);
@@ -533,10 +521,7 @@ class StateMachine {
533
521
  return getStateNodeByPath(stateNode, relativePath);
534
522
  }
535
523
  get definition() {
536
- return {
537
- context: this.getContext(),
538
- ...this.root.definition
539
- };
524
+ return this.root.definition;
540
525
  }
541
526
  toJSON() {
542
527
  return this.definition;
@@ -561,7 +546,7 @@ class StateMachine {
561
546
  const actorData = state.children[actorId];
562
547
  const childState = actorData.state;
563
548
  const src = actorData.src;
564
- const logic = src ? resolveReferencedActor(this.options.actors[src])?.src : undefined;
549
+ const logic = src ? resolveReferencedActor(this.implementations.actors[src])?.src : undefined;
565
550
  if (!logic) {
566
551
  return;
567
552
  }
@@ -588,7 +573,7 @@ class StateMachine {
588
573
  if (children[id]) {
589
574
  return;
590
575
  }
591
- const referenced = resolveReferencedActor(this.options.actors[src]);
576
+ const referenced = resolveReferencedActor(this.implementations.actors[src]);
592
577
  if (referenced) {
593
578
  const actorRef = interpret(referenced.src, {
594
579
  id,
@@ -1,5 +1,5 @@
1
- import { m as mapValues, t as toActionObjects, a as toArray, f as formatTransitions, b as toTransitionConfigArray, N as NULL_EVENT, c as formatTransition, d as memo, e as evaluateGuard, g as flatten, h as createInvokeId, i as isString, j as invoke, k as getDelayedTransitions, l as formatInitialTransition, n as getCandidates, o as toInvokeConfig, p as createSpawner, S as STATE_DELIMITER, q as getConfiguration, r as getStateNodes, s as resolveStateValue, u as isInFinalState, v as State, w as isErrorEvent, x as macrostep, y as transitionNode, z as getInitialConfiguration, A as resolveActionsAndContext, B as microstep, C as error, D as isStateId, E as getStateNodeByPath, F as getPersistedState, G as resolveReferencedActor, H as interpret, I as createInitEvent, J as initEvent, K as matchesState } from './actions-444a17c3.esm.js';
2
- export { a9 as ActionTypes, P as Interpreter, Q as InterpreterStatus, aa as SpecialTargets, v as State, a7 as and, T as assign, U as cancel, V as choose, R as doneInvoke, O as forwardTo, a2 as fromCallback, a3 as fromEventObservable, a1 as fromObservable, a0 as fromPromise, a4 as fromTransition, r as getStateNodes, H as interpret, W as log, K as matchesState, a6 as not, a8 as or, _ as pathToStateValue, X as pure, Y as raise, M as sendParent, L as sendTo, a5 as stateIn, Z as stop, $ as toObserver } from './actions-444a17c3.esm.js';
1
+ import { S as STATE_DELIMITER, m as mapValues, t as toActionObjects, a as toArray, f as formatTransitions, b as toTransitionConfigArray, N as NULL_EVENT, c as formatTransition, d as memo, e as evaluateGuard, g as flatten, h as createInvokeId, i as isString, j as invoke, k as getDelayedTransitions, l as formatInitialTransition, n as getCandidates, o as toInvokeConfig, p as getConfiguration, q as getStateNodes, r as resolveStateValue, s as isInFinalState, u as State, v as isErrorEvent, w as macrostep, x as transitionNode, y as getInitialConfiguration, z as resolveActionsAndContext, A as assign, B as microstep, C as isAtomicStateNode, D as error, E as isStateId, F as getStateNodeByPath, G as getPersistedState, H as resolveReferencedActor, I as interpret, J as createInitEvent, K as matchesState } from './actions-0386b622.esm.js';
2
+ export { a8 as ActionTypes, P as Interpreter, Q as InterpreterStatus, a9 as SpecialTargets, u as State, a6 as and, A as assign, T as cancel, U as choose, R as doneInvoke, O as forwardTo, a1 as fromCallback, a2 as fromEventObservable, a0 as fromObservable, $ as fromPromise, a3 as fromTransition, q as getStateNodes, I as interpret, V as log, K as matchesState, a5 as not, a7 as or, Z as pathToStateValue, W as pure, X as raise, M as sendParent, L as sendTo, a4 as stateIn, Y as stop, _ as toObserver } from './actions-0386b622.esm.js';
3
3
  import '../dev/dist/xstate-dev.esm.js';
4
4
 
5
5
  const EMPTY_OBJECT = {};
@@ -92,7 +92,7 @@ class StateNode {
92
92
  this.key = options._key;
93
93
  this.machine = options._machine;
94
94
  this.path = this.parent ? this.parent.path.concat(this.key) : [];
95
- this.id = this.config.id || [this.machine.id, ...this.path].join(this.machine.delimiter);
95
+ this.id = this.config.id || [this.machine.id, ...this.path].join(STATE_DELIMITER);
96
96
  this.type = this.config.type || (this.config.states && Object.keys(this.config.states).length ? 'compound' : this.config.history ? 'history' : 'atomic');
97
97
  this.description = this.config.description;
98
98
  this.order = this.machine.idMap.size;
@@ -182,9 +182,9 @@ class StateNode {
182
182
  systemId
183
183
  } = invokeConfig;
184
184
  const resolvedSrc = isString(src) ? src : !('type' in src) ? resolvedId : src;
185
- if (!this.machine.options.actors[resolvedId] && typeof src !== 'string' && !('type' in src)) {
186
- this.machine.options.actors = {
187
- ...this.machine.options.actors,
185
+ if (!this.machine.implementations.actors[resolvedId] && typeof src !== 'string' && !('type' in src)) {
186
+ this.machine.implementations.actors = {
187
+ ...this.machine.implementations.actors,
188
188
  // TODO: this should accept `src` as-is
189
189
  [resolvedId]: src
190
190
  };
@@ -315,33 +315,7 @@ class StateNode {
315
315
  }
316
316
 
317
317
  const STATE_IDENTIFIER = '#';
318
- function createDefaultOptions() {
319
- return {
320
- actions: {},
321
- actors: {},
322
- delays: {},
323
- guards: {},
324
- context: {}
325
- };
326
- }
327
318
  class StateMachine {
328
- // TODO: this getter should be removed
329
- getContext(input) {
330
- return this.getContextAndActions(undefined, input)[0];
331
- }
332
- getContextAndActions(actorCtx, input) {
333
- const actions = [];
334
- const {
335
- context
336
- } = this.config;
337
- const resolvedContext = typeof context === 'function' ? context({
338
- spawn: createSpawner(actorCtx?.self, this, undefined,
339
- // TODO: this requires `| undefined` for all referenced dynamic inputs that are spawnable in the context factory,
340
- createInitEvent(input), actions),
341
- input
342
- }) : context;
343
- return [resolvedContext || {}, actions];
344
- }
345
319
  /**
346
320
  * The machine's own version.
347
321
  */
@@ -350,11 +324,10 @@ class StateMachine {
350
324
  /**
351
325
  * The raw config used to create the machine.
352
326
  */
353
- config, options) {
327
+ config, implementations) {
354
328
  this.config = config;
355
329
  this.version = void 0;
356
- this.delimiter = void 0;
357
- this.options = void 0;
330
+ this.implementations = void 0;
358
331
  this.types = void 0;
359
332
  this.__xstatenode = true;
360
333
  this.idMap = new Map();
@@ -368,8 +341,12 @@ class StateMachine {
368
341
  this.__TActorMap = void 0;
369
342
  this.__TResolvedTypesMeta = void 0;
370
343
  this.id = config.id || '(machine)';
371
- this.options = Object.assign(createDefaultOptions(), options);
372
- this.delimiter = this.config.delimiter || STATE_DELIMITER;
344
+ this.implementations = {
345
+ actors: implementations?.actors ?? {},
346
+ actions: implementations?.actions ?? {},
347
+ delays: implementations?.delays ?? {},
348
+ guards: implementations?.guards ?? {}
349
+ };
373
350
  this.version = this.config.version;
374
351
  this.types = this.config.types ?? {};
375
352
  this.transition = this.transition.bind(this);
@@ -397,7 +374,7 @@ class StateMachine {
397
374
  guards,
398
375
  actors,
399
376
  delays
400
- } = this.options;
377
+ } = this.implementations;
401
378
  return new StateMachine(this.config, {
402
379
  actions: {
403
380
  ...actions,
@@ -435,10 +412,9 @@ class StateMachine {
435
412
  done: isInFinalState(configuration)
436
413
  });
437
414
  }
438
- resolveStateValue(stateValue) {
415
+ resolveStateValue(stateValue, ...[context]) {
439
416
  const resolvedStateValue = resolveStateValue(this.root, stateValue);
440
- const resolvedContext = this.getContext();
441
- return this.resolveState(State.from(resolvedStateValue, resolvedContext, this));
417
+ return this.resolveState(State.from(resolvedStateValue, context, this));
442
418
  }
443
419
 
444
420
  /**
@@ -477,22 +453,27 @@ class StateMachine {
477
453
  * The initial state _before_ evaluating any microsteps.
478
454
  * This "pre-initial" state is provided to initial actions executed in the initial state.
479
455
  */
480
- getPreInitialState(actorCtx, input) {
481
- const [context, actions] = this.getContextAndActions(actorCtx, input);
482
- const config = getInitialConfiguration(this.root);
456
+ getPreInitialState(actorCtx, initEvent) {
457
+ const {
458
+ context
459
+ } = this.config;
483
460
  const preInitial = this.resolveState(this.createState({
484
461
  value: {},
485
462
  // TODO: this is computed in state constructor
486
- context,
463
+ context: typeof context !== 'function' && context ? context : {},
487
464
  meta: undefined,
488
- configuration: config,
489
- transitions: [],
465
+ configuration: getInitialConfiguration(this.root),
490
466
  children: {}
491
467
  }));
492
- preInitial._initial = true;
493
- if (actorCtx) {
494
- const [nextState] = resolveActionsAndContext(actions, initEvent, preInitial, actorCtx);
495
- preInitial.children = nextState.children;
468
+ if (typeof context === 'function') {
469
+ const assignment = ({
470
+ spawn,
471
+ event
472
+ }) => context({
473
+ spawn,
474
+ input: event.input
475
+ });
476
+ return resolveActionsAndContext([assign(assignment)], initEvent, preInitial, actorCtx);
496
477
  }
497
478
  return preInitial;
498
479
  }
@@ -503,8 +484,15 @@ class StateMachine {
503
484
  getInitialState(actorCtx, input) {
504
485
  const initEvent = createInitEvent(input); // TODO: fix;
505
486
 
506
- const preInitialState = this.getPreInitialState(actorCtx, input);
507
- const nextState = microstep([], preInitialState, actorCtx, initEvent);
487
+ const preInitialState = this.getPreInitialState(actorCtx, initEvent);
488
+ const nextState = microstep([{
489
+ target: [...preInitialState.configuration].filter(isAtomicStateNode),
490
+ source: this.root,
491
+ reenter: true,
492
+ actions: [],
493
+ eventType: null,
494
+ toJSON: null // TODO: fix
495
+ }], preInitialState, actorCtx, initEvent, true);
508
496
  const {
509
497
  state: macroState
510
498
  } = macrostep(nextState, initEvent, actorCtx);
@@ -523,7 +511,7 @@ class StateMachine {
523
511
  });
524
512
  }
525
513
  getStateNodeById(stateId) {
526
- const fullPath = stateId.split(this.delimiter);
514
+ const fullPath = stateId.split(STATE_DELIMITER);
527
515
  const relativePath = fullPath.slice(1);
528
516
  const resolvedStateId = isStateId(fullPath[0]) ? fullPath[0].slice(STATE_IDENTIFIER.length) : fullPath[0];
529
517
  const stateNode = this.idMap.get(resolvedStateId);
@@ -533,10 +521,7 @@ class StateMachine {
533
521
  return getStateNodeByPath(stateNode, relativePath);
534
522
  }
535
523
  get definition() {
536
- return {
537
- context: this.getContext(),
538
- ...this.root.definition
539
- };
524
+ return this.root.definition;
540
525
  }
541
526
  toJSON() {
542
527
  return this.definition;
@@ -561,7 +546,7 @@ class StateMachine {
561
546
  const actorData = state.children[actorId];
562
547
  const childState = actorData.state;
563
548
  const src = actorData.src;
564
- const logic = src ? resolveReferencedActor(this.options.actors[src])?.src : undefined;
549
+ const logic = src ? resolveReferencedActor(this.implementations.actors[src])?.src : undefined;
565
550
  if (!logic) {
566
551
  return;
567
552
  }
@@ -588,7 +573,7 @@ class StateMachine {
588
573
  if (children[id]) {
589
574
  return;
590
575
  }
591
- const referenced = resolveReferencedActor(this.options.actors[src]);
576
+ const referenced = resolveReferencedActor(this.implementations.actors[src]);
592
577
  if (referenced) {
593
578
  const actorRef = interpret(referenced.src, {
594
579
  id,