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.
- package/CHANGELOG.md +205 -0
- package/dist/xstate.interpreter.js +1 -1
- package/dist/xstate.js +1 -1
- package/dist/xstate.web.js +2 -2
- package/es/Actor.d.ts +6 -5
- package/es/Actor.js +22 -7
- package/es/Machine.d.ts +10 -5
- package/es/Machine.js +3 -6
- package/es/State.js +3 -5
- package/es/StateNode.d.ts +4 -3
- package/es/StateNode.js +34 -28
- package/es/_virtual/_tslib.js +59 -73
- package/es/actionTypes.js +3 -2
- package/es/actions.d.ts +1 -1
- package/es/actions.js +51 -37
- package/es/behaviors.d.ts +37 -0
- package/es/behaviors.js +65 -0
- package/es/constants.js +2 -1
- package/es/devTools.js +1 -1
- package/es/environment.js +2 -1
- package/es/index.js +3 -1
- package/es/interpreter.d.ts +15 -8
- package/es/interpreter.js +48 -22
- package/es/invokeUtils.js +4 -3
- package/es/mapState.js +1 -1
- package/es/match.js +1 -1
- package/es/model.d.ts +2 -36
- package/es/model.types.d.ts +37 -0
- package/es/registry.js +2 -1
- package/es/scheduler.js +2 -1
- package/es/schema.js +1 -1
- package/es/serviceScope.js +1 -3
- package/es/stateUtils.d.ts +1 -0
- package/es/stateUtils.js +14 -8
- package/es/types.d.ts +35 -9
- package/es/types.js +1 -1
- package/es/utils.d.ts +3 -2
- package/es/utils.js +4 -40
- package/lib/Actor.d.ts +25 -24
- package/lib/Actor.js +87 -53
- package/lib/Machine.d.ts +17 -12
- package/lib/Machine.js +14 -14
- package/lib/SimulatedClock.d.ts +16 -16
- package/lib/State.d.ts +108 -108
- package/lib/State.js +246 -236
- package/lib/StateNode.d.ts +279 -278
- package/lib/StateNode.js +1535 -1350
- package/lib/_virtual/_tslib.js +81 -0
- package/lib/actionTypes.d.ts +19 -19
- package/lib/actionTypes.js +43 -23
- package/lib/actions.d.ts +138 -138
- package/lib/actions.js +465 -387
- package/lib/behaviors.d.ts +37 -0
- package/lib/behaviors.js +69 -0
- package/lib/constants.d.ts +5 -5
- package/lib/constants.js +13 -7
- package/lib/devTools.d.ts +15 -15
- package/lib/devTools.js +37 -26
- package/lib/each.d.ts +3 -3
- package/lib/environment.d.ts +1 -1
- package/lib/environment.js +7 -4
- package/lib/index.d.ts +30 -30
- package/lib/index.js +67 -57
- package/lib/interpreter.d.ts +205 -198
- package/lib/interpreter.js +1307 -1052
- package/lib/invoke.d.ts +10 -10
- package/lib/invokeUtils.d.ts +6 -6
- package/lib/invokeUtils.js +40 -37
- package/lib/json.d.ts +30 -30
- package/lib/mapState.d.ts +3 -3
- package/lib/mapState.js +31 -32
- package/lib/match.d.ts +8 -8
- package/lib/match.js +33 -47
- package/lib/model.d.ts +4 -38
- package/lib/model.js +5 -1
- package/lib/model.types.d.ts +37 -0
- package/lib/model.types.js +2 -0
- package/lib/patterns.d.ts +13 -13
- package/lib/registry.d.ts +8 -8
- package/lib/registry.js +21 -18
- package/lib/scheduler.d.ts +16 -16
- package/lib/scheduler.js +79 -70
- package/lib/schema.d.ts +1 -1
- package/lib/schema.js +6 -4
- package/lib/scxml.d.ts +5 -5
- package/lib/serviceScope.d.ts +3 -3
- package/lib/serviceScope.js +16 -12
- package/lib/stateUtils.d.ts +14 -13
- package/lib/stateUtils.js +232 -190
- package/lib/types.d.ts +928 -902
- package/lib/types.js +29 -29
- package/lib/utils.d.ts +68 -67
- package/lib/utils.js +530 -529
- package/package.json +5 -5
package/lib/scheduler.js
CHANGED
|
@@ -1,74 +1,83 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
8
|
+
deferEvents: false
|
|
17
9
|
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
exports
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
4
5
|
function createSchema(schema) {
|
|
5
|
-
|
|
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
|
package/lib/serviceScope.d.ts
CHANGED
|
@@ -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
|
package/lib/serviceScope.js
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
serviceStack.push(service);
|
|
12
|
+
var result = fn(service);
|
|
13
|
+
serviceStack.pop();
|
|
14
|
+
return result;
|
|
14
15
|
};
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
var consume = function (fn) {
|
|
17
|
+
return fn(serviceStack[serviceStack.length - 1]);
|
|
18
|
+
};
|
|
19
|
+
|
|
17
20
|
exports.consume = consume;
|
|
21
|
+
exports.provide = provide;
|
package/lib/stateUtils.d.ts
CHANGED
|
@@ -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
|