xstate 4.20.0 → 4.23.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 (94) hide show
  1. package/CHANGELOG.md +205 -0
  2. package/dist/xstate.interpreter.js +1 -1
  3. package/dist/xstate.js +1 -1
  4. package/dist/xstate.web.js +2 -2
  5. package/es/Actor.d.ts +6 -5
  6. package/es/Actor.js +22 -7
  7. package/es/Machine.d.ts +10 -5
  8. package/es/Machine.js +3 -6
  9. package/es/State.js +3 -5
  10. package/es/StateNode.d.ts +4 -3
  11. package/es/StateNode.js +34 -28
  12. package/es/_virtual/_tslib.js +59 -73
  13. package/es/actionTypes.js +3 -2
  14. package/es/actions.d.ts +1 -1
  15. package/es/actions.js +51 -37
  16. package/es/behaviors.d.ts +37 -0
  17. package/es/behaviors.js +65 -0
  18. package/es/constants.js +2 -1
  19. package/es/devTools.js +1 -1
  20. package/es/environment.js +2 -1
  21. package/es/index.js +3 -1
  22. package/es/interpreter.d.ts +15 -8
  23. package/es/interpreter.js +48 -22
  24. package/es/invokeUtils.js +4 -3
  25. package/es/mapState.js +1 -1
  26. package/es/match.js +1 -1
  27. package/es/model.d.ts +2 -36
  28. package/es/model.types.d.ts +37 -0
  29. package/es/registry.js +2 -1
  30. package/es/scheduler.js +2 -1
  31. package/es/schema.js +1 -1
  32. package/es/serviceScope.js +1 -3
  33. package/es/stateUtils.d.ts +1 -0
  34. package/es/stateUtils.js +14 -8
  35. package/es/types.d.ts +35 -9
  36. package/es/types.js +1 -1
  37. package/es/utils.d.ts +3 -2
  38. package/es/utils.js +4 -40
  39. package/lib/Actor.d.ts +25 -24
  40. package/lib/Actor.js +87 -53
  41. package/lib/Machine.d.ts +17 -12
  42. package/lib/Machine.js +14 -14
  43. package/lib/SimulatedClock.d.ts +16 -16
  44. package/lib/State.d.ts +108 -108
  45. package/lib/State.js +246 -236
  46. package/lib/StateNode.d.ts +279 -278
  47. package/lib/StateNode.js +1535 -1350
  48. package/lib/_virtual/_tslib.js +81 -0
  49. package/lib/actionTypes.d.ts +19 -19
  50. package/lib/actionTypes.js +43 -23
  51. package/lib/actions.d.ts +138 -138
  52. package/lib/actions.js +465 -387
  53. package/lib/behaviors.d.ts +37 -0
  54. package/lib/behaviors.js +69 -0
  55. package/lib/constants.d.ts +5 -5
  56. package/lib/constants.js +13 -7
  57. package/lib/devTools.d.ts +15 -15
  58. package/lib/devTools.js +37 -26
  59. package/lib/each.d.ts +3 -3
  60. package/lib/environment.d.ts +1 -1
  61. package/lib/environment.js +7 -4
  62. package/lib/index.d.ts +30 -30
  63. package/lib/index.js +67 -57
  64. package/lib/interpreter.d.ts +205 -198
  65. package/lib/interpreter.js +1307 -1052
  66. package/lib/invoke.d.ts +10 -10
  67. package/lib/invokeUtils.d.ts +6 -6
  68. package/lib/invokeUtils.js +40 -37
  69. package/lib/json.d.ts +30 -30
  70. package/lib/mapState.d.ts +3 -3
  71. package/lib/mapState.js +31 -32
  72. package/lib/match.d.ts +8 -8
  73. package/lib/match.js +33 -47
  74. package/lib/model.d.ts +4 -38
  75. package/lib/model.js +5 -1
  76. package/lib/model.types.d.ts +37 -0
  77. package/lib/model.types.js +2 -0
  78. package/lib/patterns.d.ts +13 -13
  79. package/lib/registry.d.ts +8 -8
  80. package/lib/registry.js +21 -18
  81. package/lib/scheduler.d.ts +16 -16
  82. package/lib/scheduler.js +79 -70
  83. package/lib/schema.d.ts +1 -1
  84. package/lib/schema.js +6 -4
  85. package/lib/scxml.d.ts +5 -5
  86. package/lib/serviceScope.d.ts +3 -3
  87. package/lib/serviceScope.js +16 -12
  88. package/lib/stateUtils.d.ts +14 -13
  89. package/lib/stateUtils.js +232 -190
  90. package/lib/types.d.ts +928 -902
  91. package/lib/types.js +29 -29
  92. package/lib/utils.d.ts +68 -67
  93. package/lib/utils.js +530 -529
  94. package/package.json +5 -5
package/lib/scheduler.js CHANGED
@@ -1,74 +1,83 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.Scheduler = void 0;
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _tslib = require('./_virtual/_tslib.js');
6
+
15
7
  var defaultOptions = {
16
- deferEvents: false
8
+ deferEvents: false
17
9
  };
18
- var Scheduler = /** @class */ (function () {
19
- function Scheduler(options) {
20
- this.processingEvent = false;
21
- this.queue = [];
22
- this.initialized = false;
23
- this.options = __assign(__assign({}, defaultOptions), options);
10
+
11
+ var Scheduler =
12
+ /*#__PURE__*/
13
+
14
+ /** @class */
15
+ function () {
16
+ function Scheduler(options) {
17
+ this.processingEvent = false;
18
+ this.queue = [];
19
+ this.initialized = false;
20
+ this.options = _tslib.__assign(_tslib.__assign({}, defaultOptions), options);
21
+ }
22
+
23
+ Scheduler.prototype.initialize = function (callback) {
24
+ this.initialized = true;
25
+
26
+ if (callback) {
27
+ if (!this.options.deferEvents) {
28
+ this.schedule(callback);
29
+ return;
30
+ }
31
+
32
+ this.process(callback);
33
+ }
34
+
35
+ this.flushEvents();
36
+ };
37
+
38
+ Scheduler.prototype.schedule = function (task) {
39
+ if (!this.initialized || this.processingEvent) {
40
+ this.queue.push(task);
41
+ return;
42
+ }
43
+
44
+ if (this.queue.length !== 0) {
45
+ throw new Error('Event queue should be empty when it is not processing events');
46
+ }
47
+
48
+ this.process(task);
49
+ this.flushEvents();
50
+ };
51
+
52
+ Scheduler.prototype.clear = function () {
53
+ this.queue = [];
54
+ };
55
+
56
+ Scheduler.prototype.flushEvents = function () {
57
+ var nextCallback = this.queue.shift();
58
+
59
+ while (nextCallback) {
60
+ this.process(nextCallback);
61
+ nextCallback = this.queue.shift();
62
+ }
63
+ };
64
+
65
+ Scheduler.prototype.process = function (callback) {
66
+ this.processingEvent = true;
67
+
68
+ try {
69
+ callback();
70
+ } catch (e) {
71
+ // there is no use to keep the future events
72
+ // as the situation is not anymore the same
73
+ this.clear();
74
+ throw e;
75
+ } finally {
76
+ this.processingEvent = false;
24
77
  }
25
- Scheduler.prototype.initialize = function (callback) {
26
- this.initialized = true;
27
- if (callback) {
28
- if (!this.options.deferEvents) {
29
- this.schedule(callback);
30
- return;
31
- }
32
- this.process(callback);
33
- }
34
- this.flushEvents();
35
- };
36
- Scheduler.prototype.schedule = function (task) {
37
- if (!this.initialized || this.processingEvent) {
38
- this.queue.push(task);
39
- return;
40
- }
41
- if (this.queue.length !== 0) {
42
- throw new Error('Event queue should be empty when it is not processing events');
43
- }
44
- this.process(task);
45
- this.flushEvents();
46
- };
47
- Scheduler.prototype.clear = function () {
48
- this.queue = [];
49
- };
50
- Scheduler.prototype.flushEvents = function () {
51
- var nextCallback = this.queue.shift();
52
- while (nextCallback) {
53
- this.process(nextCallback);
54
- nextCallback = this.queue.shift();
55
- }
56
- };
57
- Scheduler.prototype.process = function (callback) {
58
- this.processingEvent = true;
59
- try {
60
- callback();
61
- }
62
- catch (e) {
63
- // there is no use to keep the future events
64
- // as the situation is not anymore the same
65
- this.clear();
66
- throw e;
67
- }
68
- finally {
69
- this.processingEvent = false;
70
- }
71
- };
72
- return Scheduler;
73
- }());
78
+ };
79
+
80
+ return Scheduler;
81
+ }();
82
+
74
83
  exports.Scheduler = Scheduler;
package/lib/schema.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare function createSchema<T>(schema?: any): T;
1
+ export declare function createSchema<T>(schema?: any): T;
2
2
  //# sourceMappingURL=schema.d.ts.map
package/lib/schema.js CHANGED
@@ -1,7 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createSchema = void 0;
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
4
5
  function createSchema(schema) {
5
- return schema;
6
+ return schema;
6
7
  }
8
+
7
9
  exports.createSchema = createSchema;
package/lib/scxml.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { StateNode } from './index';
2
- export interface ScxmlToMachineOptions {
3
- delimiter?: string;
4
- }
5
- export declare function toMachine(xml: string, options: ScxmlToMachineOptions): StateNode;
1
+ import { StateNode } from './index';
2
+ export interface ScxmlToMachineOptions {
3
+ delimiter?: string;
4
+ }
5
+ export declare function toMachine(xml: string, options: ScxmlToMachineOptions): StateNode;
6
6
  //# sourceMappingURL=scxml.d.ts.map
@@ -1,4 +1,4 @@
1
- import { AnyInterpreter } from './types';
2
- export declare const provide: <T, TService extends AnyInterpreter>(service: TService | undefined, fn: (service: TService | undefined) => T) => T;
3
- export declare const consume: <T, TService extends AnyInterpreter>(fn: (service: TService) => T) => T;
1
+ import { AnyInterpreter } from './types';
2
+ export declare const provide: <T, TService extends AnyInterpreter>(service: TService | undefined, fn: (service: TService | undefined) => T) => T;
3
+ export declare const consume: <T, TService extends AnyInterpreter>(fn: (service: TService) => T) => T;
4
4
  //# sourceMappingURL=serviceScope.d.ts.map
@@ -1,17 +1,21 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.consume = exports.provide = void 0;
4
- /**
5
- * Maintains a stack of the current service in scope.
6
- * This is used to provide the correct service to spawn().
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ /**
6
+ * Maintains a stack of the current service in scope.
7
+ * This is used to provide the correct service to spawn().
7
8
  */
8
9
  var serviceStack = [];
9
10
  var provide = function (service, fn) {
10
- serviceStack.push(service);
11
- var result = fn(service);
12
- serviceStack.pop();
13
- return result;
11
+ serviceStack.push(service);
12
+ var result = fn(service);
13
+ serviceStack.pop();
14
+ return result;
14
15
  };
15
- exports.provide = provide;
16
- var consume = function (fn) { return fn(serviceStack[serviceStack.length - 1]); };
16
+ var consume = function (fn) {
17
+ return fn(serviceStack[serviceStack.length - 1]);
18
+ };
19
+
17
20
  exports.consume = consume;
21
+ exports.provide = provide;
@@ -1,14 +1,15 @@
1
- import { EventObject, StateNode, StateValue } from '.';
2
- declare type Configuration<TC, TE extends EventObject> = Iterable<StateNode<TC, any, TE>>;
3
- declare type AdjList<TC, TE extends EventObject> = Map<StateNode<TC, any, TE>, Array<StateNode<TC, any, TE>>>;
4
- export declare const isLeafNode: (stateNode: StateNode<any, any, any, any>) => boolean;
5
- export declare function getChildren<TC, TE extends EventObject>(stateNode: StateNode<TC, any, TE>): Array<StateNode<TC, any, TE>>;
6
- export declare function getAllStateNodes<TC, TE extends EventObject>(stateNode: StateNode<TC, any, TE, any>): Array<StateNode<TC, any, TE, any>>;
7
- export declare function getConfiguration<TC, TE extends EventObject>(prevStateNodes: Iterable<StateNode<TC, any, TE, any>>, stateNodes: Iterable<StateNode<TC, any, TE, any>>): Iterable<StateNode<TC, any, TE, any>>;
8
- export declare function getAdjList<TC, TE extends EventObject>(configuration: Configuration<TC, TE>): AdjList<TC, TE>;
9
- export declare function getValue<TC, TE extends EventObject>(rootNode: StateNode<TC, any, TE, any>, configuration: Configuration<TC, TE>): StateValue;
10
- export declare function has<T>(iterable: Iterable<T>, item: T): boolean;
11
- export declare function nextEvents<TC, TE extends EventObject>(configuration: Array<StateNode<TC, any, TE>>): Array<TE['type']>;
12
- export declare function isInFinalState<TC, TE extends EventObject>(configuration: Array<StateNode<TC, any, TE, any>>, stateNode: StateNode<TC, any, TE, any>): boolean;
13
- export {};
1
+ import { EventObject, StateNode, StateValue } from '.';
2
+ declare type Configuration<TC, TE extends EventObject> = Iterable<StateNode<TC, any, TE>>;
3
+ declare type AdjList<TC, TE extends EventObject> = Map<StateNode<TC, any, TE>, Array<StateNode<TC, any, TE>>>;
4
+ export declare const isLeafNode: (stateNode: StateNode<any, any, any, any>) => boolean;
5
+ export declare function getChildren<TC, TE extends EventObject>(stateNode: StateNode<TC, any, TE>): Array<StateNode<TC, any, TE>>;
6
+ export declare function getAllStateNodes<TC, TE extends EventObject>(stateNode: StateNode<TC, any, TE, any>): Array<StateNode<TC, any, TE, any>>;
7
+ export declare function getConfiguration<TC, TE extends EventObject>(prevStateNodes: Iterable<StateNode<TC, any, TE, any>>, stateNodes: Iterable<StateNode<TC, any, TE, any>>): Iterable<StateNode<TC, any, TE, any>>;
8
+ export declare function getAdjList<TC, TE extends EventObject>(configuration: Configuration<TC, TE>): AdjList<TC, TE>;
9
+ export declare function getValue<TC, TE extends EventObject>(rootNode: StateNode<TC, any, TE, any>, configuration: Configuration<TC, TE>): StateValue;
10
+ export declare function has<T>(iterable: Iterable<T>, item: T): boolean;
11
+ export declare function nextEvents<TC, TE extends EventObject>(configuration: Array<StateNode<TC, any, TE>>): Array<TE['type']>;
12
+ export declare function isInFinalState<TC, TE extends EventObject>(configuration: Array<StateNode<TC, any, TE, any>>, stateNode: StateNode<TC, any, TE, any>): boolean;
13
+ export declare function getMeta(configuration?: StateNode[]): Record<string, any>;
14
+ export {};
14
15
  //# sourceMappingURL=stateUtils.d.ts.map