xstate 4.20.1 → 4.23.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/CHANGELOG.md +134 -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.js +17 -5
  6. package/es/Machine.d.ts +6 -3
  7. package/es/Machine.js +3 -6
  8. package/es/State.js +1 -3
  9. package/es/StateNode.d.ts +4 -3
  10. package/es/StateNode.js +34 -20
  11. package/es/_virtual/_tslib.js +59 -73
  12. package/es/actionTypes.js +3 -2
  13. package/es/actions.d.ts +1 -1
  14. package/es/actions.js +51 -37
  15. package/es/behaviors.d.ts +37 -0
  16. package/es/behaviors.js +65 -0
  17. package/es/constants.js +2 -1
  18. package/es/devTools.js +1 -1
  19. package/es/environment.js +2 -1
  20. package/es/index.js +3 -1
  21. package/es/interpreter.d.ts +10 -3
  22. package/es/interpreter.js +44 -22
  23. package/es/invokeUtils.js +4 -3
  24. package/es/mapState.js +1 -1
  25. package/es/match.js +1 -1
  26. package/es/model.d.ts +2 -36
  27. package/es/model.types.d.ts +37 -0
  28. package/es/registry.js +2 -1
  29. package/es/scheduler.js +2 -1
  30. package/es/schema.js +1 -1
  31. package/es/serviceScope.js +1 -3
  32. package/es/stateUtils.js +1 -9
  33. package/es/types.d.ts +26 -5
  34. package/es/types.js +1 -1
  35. package/es/utils.d.ts +3 -2
  36. package/es/utils.js +4 -40
  37. package/lib/Actor.d.ts +25 -25
  38. package/lib/Actor.js +85 -66
  39. package/lib/Machine.d.ts +17 -14
  40. package/lib/Machine.js +14 -14
  41. package/lib/SimulatedClock.d.ts +16 -16
  42. package/lib/State.d.ts +108 -108
  43. package/lib/State.js +246 -236
  44. package/lib/StateNode.d.ts +279 -278
  45. package/lib/StateNode.js +1535 -1339
  46. package/lib/_virtual/_tslib.js +81 -0
  47. package/lib/actionTypes.d.ts +19 -19
  48. package/lib/actionTypes.js +43 -23
  49. package/lib/actions.d.ts +138 -138
  50. package/lib/actions.js +465 -387
  51. package/lib/behaviors.d.ts +37 -0
  52. package/lib/behaviors.js +69 -0
  53. package/lib/constants.d.ts +5 -5
  54. package/lib/constants.js +13 -7
  55. package/lib/devTools.d.ts +15 -15
  56. package/lib/devTools.js +37 -26
  57. package/lib/each.d.ts +3 -3
  58. package/lib/environment.d.ts +1 -1
  59. package/lib/environment.js +7 -4
  60. package/lib/index.d.ts +30 -30
  61. package/lib/index.js +67 -57
  62. package/lib/interpreter.d.ts +205 -198
  63. package/lib/interpreter.js +1306 -1054
  64. package/lib/invoke.d.ts +10 -10
  65. package/lib/invokeUtils.d.ts +6 -6
  66. package/lib/invokeUtils.js +40 -37
  67. package/lib/json.d.ts +30 -30
  68. package/lib/mapState.d.ts +3 -3
  69. package/lib/mapState.js +31 -32
  70. package/lib/match.d.ts +8 -8
  71. package/lib/match.js +33 -47
  72. package/lib/model.d.ts +4 -38
  73. package/lib/model.js +5 -1
  74. package/lib/model.types.d.ts +37 -0
  75. package/lib/model.types.js +2 -0
  76. package/lib/patterns.d.ts +13 -13
  77. package/lib/registry.d.ts +8 -8
  78. package/lib/registry.js +21 -18
  79. package/lib/scheduler.d.ts +16 -16
  80. package/lib/scheduler.js +79 -70
  81. package/lib/schema.d.ts +1 -1
  82. package/lib/schema.js +6 -4
  83. package/lib/scxml.d.ts +5 -5
  84. package/lib/serviceScope.d.ts +3 -3
  85. package/lib/serviceScope.js +16 -12
  86. package/lib/stateUtils.d.ts +14 -14
  87. package/lib/stateUtils.js +231 -199
  88. package/lib/types.d.ts +928 -907
  89. package/lib/types.js +29 -29
  90. package/lib/utils.d.ts +68 -67
  91. package/lib/utils.js +530 -529
  92. package/package.json +6 -6
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,15 +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 declare function getMeta(configuration?: StateNode[]): Record<string, any>;
14
- 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 {};
15
15
  //# sourceMappingURL=stateUtils.d.ts.map