xstate 4.22.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 +58 -4
- package/dist/xstate.interpreter.js +1 -1
- package/dist/xstate.js +1 -1
- package/dist/xstate.web.js +2 -2
- package/es/Actor.js +1 -6
- package/es/Machine.d.ts +3 -3
- package/es/Machine.js +1 -2
- package/es/State.js +1 -3
- package/es/StateNode.js +3 -2
- 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.js +4 -2
- 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 +8 -2
- package/es/interpreter.js +8 -6
- package/es/invokeUtils.js +4 -3
- package/es/mapState.js +1 -1
- package/es/match.js +1 -1
- package/es/model.d.ts +2 -37
- 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.js +1 -9
- package/es/types.d.ts +12 -2
- package/es/types.js +1 -1
- package/es/utils.js +1 -41
- package/lib/Actor.d.ts +25 -25
- package/lib/Actor.js +85 -66
- package/lib/Machine.d.ts +17 -17
- package/lib/Machine.js +14 -8
- 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 -279
- package/lib/StateNode.js +1535 -1357
- 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 +36 -36
- package/lib/behaviors.js +65 -106
- 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 -199
- package/lib/interpreter.js +1306 -1060
- 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 -39
- 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 -14
- package/lib/stateUtils.js +231 -199
- package/lib/types.d.ts +928 -918
- package/lib/types.js +29 -29
- package/lib/utils.d.ts +68 -68
- package/lib/utils.js +528 -534
- package/package.json +5 -5
package/lib/invoke.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export interface InvokedPromiseOptions {
|
|
2
|
-
id?: string;
|
|
3
|
-
}
|
|
4
|
-
export interface PromiseMachineSchema {
|
|
5
|
-
states: {
|
|
6
|
-
pending: {};
|
|
7
|
-
resolved: {};
|
|
8
|
-
rejected: {};
|
|
9
|
-
};
|
|
10
|
-
}
|
|
1
|
+
export interface InvokedPromiseOptions {
|
|
2
|
+
id?: string;
|
|
3
|
+
}
|
|
4
|
+
export interface PromiseMachineSchema {
|
|
5
|
+
states: {
|
|
6
|
+
pending: {};
|
|
7
|
+
resolved: {};
|
|
8
|
+
rejected: {};
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
11
|
//# sourceMappingURL=invoke.d.ts.map
|
package/lib/invokeUtils.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { EventObject, InvokeConfig, InvokeDefinition, InvokeSourceDefinition } from './types';
|
|
2
|
-
export declare function toInvokeSource(src: string | InvokeSourceDefinition): InvokeSourceDefinition;
|
|
3
|
-
export declare function toInvokeDefinition<TContext, TEvent extends EventObject>(invokeConfig: InvokeConfig<TContext, TEvent> & {
|
|
4
|
-
src: string | InvokeSourceDefinition;
|
|
5
|
-
id: string;
|
|
6
|
-
}): InvokeDefinition<TContext, TEvent>;
|
|
1
|
+
import { EventObject, InvokeConfig, InvokeDefinition, InvokeSourceDefinition } from './types';
|
|
2
|
+
export declare function toInvokeSource(src: string | InvokeSourceDefinition): InvokeSourceDefinition;
|
|
3
|
+
export declare function toInvokeDefinition<TContext, TEvent extends EventObject>(invokeConfig: InvokeConfig<TContext, TEvent> & {
|
|
4
|
+
src: string | InvokeSourceDefinition;
|
|
5
|
+
id: string;
|
|
6
|
+
}): InvokeDefinition<TContext, TEvent>;
|
|
7
7
|
//# sourceMappingURL=invokeUtils.d.ts.map
|
package/lib/invokeUtils.js
CHANGED
|
@@ -1,42 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
14
|
-
var t = {};
|
|
15
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
16
|
-
t[p] = s[p];
|
|
17
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
18
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
19
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
20
|
-
t[p[i]] = s[p[i]];
|
|
21
|
-
}
|
|
22
|
-
return t;
|
|
23
|
-
};
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.toInvokeDefinition = exports.toInvokeSource = void 0;
|
|
26
|
-
var actions_1 = require("./actions");
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _tslib = require('./_virtual/_tslib.js');
|
|
6
|
+
require('./environment.js');
|
|
7
|
+
require('./utils.js');
|
|
8
|
+
require('./types.js');
|
|
9
|
+
var actionTypes = require('./actionTypes.js');
|
|
10
|
+
|
|
27
11
|
function toInvokeSource(src) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
12
|
+
if (typeof src === 'string') {
|
|
13
|
+
var simpleSrc = {
|
|
14
|
+
type: src
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
simpleSrc.toString = function () {
|
|
18
|
+
return src;
|
|
19
|
+
}; // v4 compat - TODO: remove in v5
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
return simpleSrc;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return src;
|
|
34
26
|
}
|
|
35
|
-
exports.toInvokeSource = toInvokeSource;
|
|
36
27
|
function toInvokeDefinition(invokeConfig) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
28
|
+
return _tslib.__assign(_tslib.__assign({
|
|
29
|
+
type: actionTypes.invoke
|
|
30
|
+
}, invokeConfig), {
|
|
31
|
+
toJSON: function () {
|
|
32
|
+
var onDone = invokeConfig.onDone,
|
|
33
|
+
onError = invokeConfig.onError,
|
|
34
|
+
invokeDef = _tslib.__rest(invokeConfig, ["onDone", "onError"]);
|
|
35
|
+
|
|
36
|
+
return _tslib.__assign(_tslib.__assign({}, invokeDef), {
|
|
37
|
+
type: actionTypes.invoke,
|
|
38
|
+
src: toInvokeSource(invokeConfig.src)
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
});
|
|
41
42
|
}
|
|
43
|
+
|
|
42
44
|
exports.toInvokeDefinition = toInvokeDefinition;
|
|
45
|
+
exports.toInvokeSource = toInvokeSource;
|
package/lib/json.d.ts
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { StateNode, ActionObject, Guard, InvokeDefinition } from './';
|
|
2
|
-
interface JSONFunction {
|
|
3
|
-
$function: string;
|
|
4
|
-
}
|
|
5
|
-
export declare function stringifyFunction(fn: Function): JSONFunction;
|
|
6
|
-
interface TransitionConfig {
|
|
7
|
-
target: string[];
|
|
8
|
-
source: string;
|
|
9
|
-
actions: Array<ActionObject<any, any>>;
|
|
10
|
-
cond: Guard<any, any> | undefined;
|
|
11
|
-
eventType: string;
|
|
12
|
-
}
|
|
13
|
-
interface StateNodeConfig {
|
|
14
|
-
type: StateNode['type'];
|
|
15
|
-
id: string;
|
|
16
|
-
key: string;
|
|
17
|
-
initial?: string;
|
|
18
|
-
entry: Array<ActionObject<any, any>>;
|
|
19
|
-
exit: Array<ActionObject<any, any>>;
|
|
20
|
-
on: {
|
|
21
|
-
[key: string]: TransitionConfig[];
|
|
22
|
-
};
|
|
23
|
-
invoke: Array<InvokeDefinition<any, any>>;
|
|
24
|
-
states: Record<string, StateNodeConfig>;
|
|
25
|
-
}
|
|
26
|
-
export declare function machineToJSON(stateNode: StateNode): StateNodeConfig;
|
|
27
|
-
export declare function stringify(machine: StateNode): string;
|
|
28
|
-
export declare function parse(machineString: string): StateNodeConfig;
|
|
29
|
-
export declare function jsonify<T extends Record<string, any>>(value: T): T;
|
|
30
|
-
export {};
|
|
1
|
+
import { StateNode, ActionObject, Guard, InvokeDefinition } from './';
|
|
2
|
+
interface JSONFunction {
|
|
3
|
+
$function: string;
|
|
4
|
+
}
|
|
5
|
+
export declare function stringifyFunction(fn: Function): JSONFunction;
|
|
6
|
+
interface TransitionConfig {
|
|
7
|
+
target: string[];
|
|
8
|
+
source: string;
|
|
9
|
+
actions: Array<ActionObject<any, any>>;
|
|
10
|
+
cond: Guard<any, any> | undefined;
|
|
11
|
+
eventType: string;
|
|
12
|
+
}
|
|
13
|
+
interface StateNodeConfig {
|
|
14
|
+
type: StateNode['type'];
|
|
15
|
+
id: string;
|
|
16
|
+
key: string;
|
|
17
|
+
initial?: string;
|
|
18
|
+
entry: Array<ActionObject<any, any>>;
|
|
19
|
+
exit: Array<ActionObject<any, any>>;
|
|
20
|
+
on: {
|
|
21
|
+
[key: string]: TransitionConfig[];
|
|
22
|
+
};
|
|
23
|
+
invoke: Array<InvokeDefinition<any, any>>;
|
|
24
|
+
states: Record<string, StateNodeConfig>;
|
|
25
|
+
}
|
|
26
|
+
export declare function machineToJSON(stateNode: StateNode): StateNodeConfig;
|
|
27
|
+
export declare function stringify(machine: StateNode): string;
|
|
28
|
+
export declare function parse(machineString: string): StateNodeConfig;
|
|
29
|
+
export declare function jsonify<T extends Record<string, any>>(value: T): T;
|
|
30
|
+
export {};
|
|
31
31
|
//# sourceMappingURL=json.d.ts.map
|
package/lib/mapState.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare function mapState(stateMap: {
|
|
2
|
-
[stateId: string]: any;
|
|
3
|
-
}, stateId: string): any;
|
|
1
|
+
export declare function mapState(stateMap: {
|
|
2
|
+
[stateId: string]: any;
|
|
3
|
+
}, stateId: string): any;
|
|
4
4
|
//# sourceMappingURL=mapState.d.ts.map
|
package/lib/mapState.js
CHANGED
|
@@ -1,37 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return { value: o && o[i++], done: !o };
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.mapState = void 0;
|
|
15
|
-
var utils_1 = require("./utils");
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _tslib = require('./_virtual/_tslib.js');
|
|
6
|
+
var utils = require('./utils.js');
|
|
7
|
+
|
|
16
8
|
function mapState(stateMap, stateId) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
9
|
+
var e_1, _a;
|
|
10
|
+
|
|
11
|
+
var foundStateId;
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
for (var _b = _tslib.__values(utils.keys(stateMap)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
15
|
+
var mappedStateId = _c.value;
|
|
16
|
+
|
|
17
|
+
if (utils.matchesState(mappedStateId, stateId) && (!foundStateId || stateId.length > foundStateId.length)) {
|
|
18
|
+
foundStateId = mappedStateId;
|
|
19
|
+
}
|
|
27
20
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
21
|
+
} catch (e_1_1) {
|
|
22
|
+
e_1 = {
|
|
23
|
+
error: e_1_1
|
|
24
|
+
};
|
|
25
|
+
} finally {
|
|
26
|
+
try {
|
|
27
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
28
|
+
} finally {
|
|
29
|
+
if (e_1) throw e_1.error;
|
|
34
30
|
}
|
|
35
|
-
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return stateMap[foundStateId];
|
|
36
34
|
}
|
|
35
|
+
|
|
37
36
|
exports.mapState = mapState;
|
package/lib/match.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { State } from './State';
|
|
2
|
-
import { StateValue, EventObject } from './types';
|
|
3
|
-
export declare type ValueFromStateGetter<T, TContext, TEvent extends EventObject> = (state: State<TContext, TEvent>) => T;
|
|
4
|
-
export declare type StatePatternTuple<T, TContext, TEvent extends EventObject> = [
|
|
5
|
-
StateValue,
|
|
6
|
-
ValueFromStateGetter<T, TContext, TEvent>
|
|
7
|
-
];
|
|
8
|
-
export declare function matchState<T, TContext, TEvent extends EventObject>(state: State<TContext, TEvent> | StateValue, patterns: Array<StatePatternTuple<T, TContext, TEvent>>, defaultValue: ValueFromStateGetter<T, TContext, TEvent>): T;
|
|
1
|
+
import { State } from './State';
|
|
2
|
+
import { StateValue, EventObject } from './types';
|
|
3
|
+
export declare type ValueFromStateGetter<T, TContext, TEvent extends EventObject> = (state: State<TContext, TEvent>) => T;
|
|
4
|
+
export declare type StatePatternTuple<T, TContext, TEvent extends EventObject> = [
|
|
5
|
+
StateValue,
|
|
6
|
+
ValueFromStateGetter<T, TContext, TEvent>
|
|
7
|
+
];
|
|
8
|
+
export declare function matchState<T, TContext, TEvent extends EventObject>(state: State<TContext, TEvent> | StateValue, patterns: Array<StatePatternTuple<T, TContext, TEvent>>, defaultValue: ValueFromStateGetter<T, TContext, TEvent>): T;
|
|
9
9
|
//# sourceMappingURL=match.d.ts.map
|
package/lib/match.js
CHANGED
|
@@ -1,52 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return { value: o && o[i++], done: !o };
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
12
|
-
};
|
|
13
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
14
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
|
-
if (!m) return o;
|
|
16
|
-
var i = m.call(o), r, ar = [], e;
|
|
17
|
-
try {
|
|
18
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
19
|
-
}
|
|
20
|
-
catch (error) { e = { error: error }; }
|
|
21
|
-
finally {
|
|
22
|
-
try {
|
|
23
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
24
|
-
}
|
|
25
|
-
finally { if (e) throw e.error; }
|
|
26
|
-
}
|
|
27
|
-
return ar;
|
|
28
|
-
};
|
|
29
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.matchState = void 0;
|
|
31
|
-
var State_1 = require("./State");
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _tslib = require('./_virtual/_tslib.js');
|
|
6
|
+
var State = require('./State.js');
|
|
7
|
+
|
|
32
8
|
function matchState(state, patterns, defaultValue) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
9
|
+
var e_1, _a;
|
|
10
|
+
|
|
11
|
+
var resolvedState = State.State.from(state, state instanceof State.State ? state.context : undefined);
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
for (var patterns_1 = _tslib.__values(patterns), patterns_1_1 = patterns_1.next(); !patterns_1_1.done; patterns_1_1 = patterns_1.next()) {
|
|
15
|
+
var _b = _tslib.__read(patterns_1_1.value, 2),
|
|
16
|
+
stateValue = _b[0],
|
|
17
|
+
getValue = _b[1];
|
|
18
|
+
|
|
19
|
+
if (resolvedState.matches(stateValue)) {
|
|
20
|
+
return getValue(resolvedState);
|
|
21
|
+
}
|
|
42
22
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
23
|
+
} catch (e_1_1) {
|
|
24
|
+
e_1 = {
|
|
25
|
+
error: e_1_1
|
|
26
|
+
};
|
|
27
|
+
} finally {
|
|
28
|
+
try {
|
|
29
|
+
if (patterns_1_1 && !patterns_1_1.done && (_a = patterns_1.return)) _a.call(patterns_1);
|
|
30
|
+
} finally {
|
|
31
|
+
if (e_1) throw e_1.error;
|
|
49
32
|
}
|
|
50
|
-
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return defaultValue(resolvedState);
|
|
51
36
|
}
|
|
37
|
+
|
|
52
38
|
exports.matchState = matchState;
|
package/lib/model.d.ts
CHANGED
|
@@ -1,40 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
declare
|
|
4
|
-
declare
|
|
5
|
-
[K in keyof A]: A[K];
|
|
6
|
-
} & unknown;
|
|
7
|
-
declare type Prop<T, K> = K extends keyof T ? T[K] : never;
|
|
8
|
-
export interface Model<TContext, TEvent extends EventObject, TModelCreators = void> {
|
|
9
|
-
initialContext: TContext;
|
|
10
|
-
assign: <TEventType extends TEvent['type'] = TEvent['type']>(assigner: Assigner<TContext, ExtractEvent<TEvent, TEventType>> | PropertyAssigner<TContext, ExtractEvent<TEvent, TEventType>>, eventType?: TEventType) => AssignAction<TContext, ExtractEvent<TEvent, TEventType>>;
|
|
11
|
-
events: Prop<TModelCreators, 'events'>;
|
|
12
|
-
reset: () => AssignAction<TContext, any>;
|
|
13
|
-
createMachine: (config: MachineConfig<TContext, any, TEvent>, implementations?: Partial<MachineOptions<TContext, TEvent>>) => StateMachine<TContext, any, TEvent, any>;
|
|
14
|
-
}
|
|
15
|
-
export declare type ModelContextFrom<TModel extends Model<any, any, any>> = TModel extends Model<infer TContext, any, any> ? TContext : never;
|
|
16
|
-
export declare type ModelEventsFrom<TModel extends Model<any, any, any>> = TModel extends Model<any, infer TEvent, any> ? TEvent : never;
|
|
17
|
-
declare type EventCreator<Self extends AnyFunction, Return = ReturnType<Self>> = Return extends object ? Return extends {
|
|
18
|
-
type: any;
|
|
19
|
-
} ? "An event creator can't return an object with a type property" : Self : 'An event creator must return an object';
|
|
20
|
-
declare type EventCreators<Self> = {
|
|
21
|
-
[K in keyof Self]: Self[K] extends AnyFunction ? EventCreator<Self[K]> : 'An event creator must be a function';
|
|
22
|
-
};
|
|
23
|
-
declare type ModelCreators<Self> = {
|
|
24
|
-
events: EventCreators<Prop<Self, 'events'>>;
|
|
25
|
-
};
|
|
26
|
-
declare type FinalEventCreators<Self> = {
|
|
27
|
-
[K in keyof Self]: Self[K] extends AnyFunction ? (...args: Parameters<Self[K]>) => Compute<ReturnType<Self[K]> & {
|
|
28
|
-
type: K;
|
|
29
|
-
}> : never;
|
|
30
|
-
};
|
|
31
|
-
declare type FinalModelCreators<Self> = {
|
|
32
|
-
events: FinalEventCreators<Prop<Self, 'events'>>;
|
|
33
|
-
};
|
|
34
|
-
declare type EventFromEventCreators<EventCreators> = {
|
|
35
|
-
[K in keyof EventCreators]: EventCreators[K] extends AnyFunction ? ReturnType<EventCreators[K]> : never;
|
|
36
|
-
}[keyof EventCreators];
|
|
37
|
-
export declare function createModel<TContext, TEvent extends EventObject>(initialContext: TContext): Model<TContext, TEvent, void>;
|
|
38
|
-
export declare function createModel<TContext, TModelCreators extends ModelCreators<TModelCreators>, TFinalModelCreators = FinalModelCreators<TModelCreators>>(initialContext: TContext, creators: TModelCreators): Model<TContext, Cast<EventFromEventCreators<Prop<TFinalModelCreators, 'events'>>, EventObject>, TFinalModelCreators>;
|
|
39
|
-
export {};
|
|
1
|
+
import type { EventObject } from './types';
|
|
2
|
+
import { Cast, EventFromEventCreators, FinalModelCreators, Model, ModelCreators, Prop } from './model.types';
|
|
3
|
+
export declare function createModel<TContext, TEvent extends EventObject>(initialContext: TContext): Model<TContext, TEvent, void>;
|
|
4
|
+
export declare function createModel<TContext, TModelCreators extends ModelCreators<TModelCreators>, TFinalModelCreators = FinalModelCreators<TModelCreators>>(initialContext: TContext, creators: TModelCreators): Model<TContext, Cast<EventFromEventCreators<Prop<TFinalModelCreators, 'events'>>, EventObject>, TFinalModelCreators>;
|
|
40
5
|
//# sourceMappingURL=model.d.ts.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { EventObject, Assigner, ExtractEvent, PropertyAssigner, AssignAction, MachineConfig, MachineOptions, StateMachine } from './types';
|
|
2
|
+
export declare type AnyFunction = (...args: any[]) => any;
|
|
3
|
+
export declare type Cast<A1 extends any, A2 extends any> = A1 extends A2 ? A1 : A2;
|
|
4
|
+
export declare type Compute<A extends any> = {
|
|
5
|
+
[K in keyof A]: A[K];
|
|
6
|
+
} & unknown;
|
|
7
|
+
export declare type Prop<T, K> = K extends keyof T ? T[K] : never;
|
|
8
|
+
export interface Model<TContext, TEvent extends EventObject, TModelCreators = void> {
|
|
9
|
+
initialContext: TContext;
|
|
10
|
+
assign: <TEventType extends TEvent['type'] = TEvent['type']>(assigner: Assigner<TContext, ExtractEvent<TEvent, TEventType>> | PropertyAssigner<TContext, ExtractEvent<TEvent, TEventType>>, eventType?: TEventType) => AssignAction<TContext, ExtractEvent<TEvent, TEventType>>;
|
|
11
|
+
events: Prop<TModelCreators, 'events'>;
|
|
12
|
+
reset: () => AssignAction<TContext, any>;
|
|
13
|
+
createMachine: (config: MachineConfig<TContext, any, TEvent>, implementations?: Partial<MachineOptions<TContext, TEvent>>) => StateMachine<TContext, any, TEvent, any>;
|
|
14
|
+
}
|
|
15
|
+
export declare type ModelContextFrom<TModel extends Model<any, any, any>> = TModel extends Model<infer TContext, any, any> ? TContext : never;
|
|
16
|
+
export declare type ModelEventsFrom<TModel extends Model<any, any, any>> = TModel extends Model<any, infer TEvent, any> ? TEvent : never;
|
|
17
|
+
export declare type EventCreator<Self extends AnyFunction, Return = ReturnType<Self>> = Return extends object ? Return extends {
|
|
18
|
+
type: any;
|
|
19
|
+
} ? "An event creator can't return an object with a type property" : Self : 'An event creator must return an object';
|
|
20
|
+
export declare type EventCreators<Self> = {
|
|
21
|
+
[K in keyof Self]: Self[K] extends AnyFunction ? EventCreator<Self[K]> : 'An event creator must be a function';
|
|
22
|
+
};
|
|
23
|
+
export declare type ModelCreators<Self> = {
|
|
24
|
+
events: EventCreators<Prop<Self, 'events'>>;
|
|
25
|
+
};
|
|
26
|
+
export declare type FinalEventCreators<Self> = {
|
|
27
|
+
[K in keyof Self]: Self[K] extends AnyFunction ? (...args: Parameters<Self[K]>) => Compute<ReturnType<Self[K]> & {
|
|
28
|
+
type: K;
|
|
29
|
+
}> : never;
|
|
30
|
+
};
|
|
31
|
+
export declare type FinalModelCreators<Self> = {
|
|
32
|
+
events: FinalEventCreators<Prop<Self, 'events'>>;
|
|
33
|
+
};
|
|
34
|
+
export declare type EventFromEventCreators<EventCreators> = {
|
|
35
|
+
[K in keyof EventCreators]: EventCreators[K] extends AnyFunction ? ReturnType<EventCreators[K]> : never;
|
|
36
|
+
}[keyof EventCreators];
|
|
37
|
+
//# sourceMappingURL=model.types.d.ts.map
|
package/lib/patterns.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { AtomicStateNodeConfig, StatesConfig, Event, EventObject, StateSchema } from './types';
|
|
2
|
-
export declare function toggle<TEventType extends string = string>(onState: string, offState: string, eventType: TEventType): Record<string, AtomicStateNodeConfig<any, {
|
|
3
|
-
type: TEventType;
|
|
4
|
-
}>>;
|
|
5
|
-
interface SequencePatternOptions<TEvent extends EventObject> {
|
|
6
|
-
nextEvent: Event<TEvent> | undefined;
|
|
7
|
-
prevEvent: Event<TEvent> | undefined;
|
|
8
|
-
}
|
|
9
|
-
export declare function sequence<TStateSchema extends StateSchema, TEvent extends EventObject>(items: Array<keyof TStateSchema['states']>, options?: Partial<SequencePatternOptions<TEvent>>): {
|
|
10
|
-
initial: keyof TStateSchema['states'];
|
|
11
|
-
states: StatesConfig<any, TStateSchema, TEvent>;
|
|
12
|
-
};
|
|
13
|
-
export {};
|
|
1
|
+
import { AtomicStateNodeConfig, StatesConfig, Event, EventObject, StateSchema } from './types';
|
|
2
|
+
export declare function toggle<TEventType extends string = string>(onState: string, offState: string, eventType: TEventType): Record<string, AtomicStateNodeConfig<any, {
|
|
3
|
+
type: TEventType;
|
|
4
|
+
}>>;
|
|
5
|
+
interface SequencePatternOptions<TEvent extends EventObject> {
|
|
6
|
+
nextEvent: Event<TEvent> | undefined;
|
|
7
|
+
prevEvent: Event<TEvent> | undefined;
|
|
8
|
+
}
|
|
9
|
+
export declare function sequence<TStateSchema extends StateSchema, TEvent extends EventObject>(items: Array<keyof TStateSchema['states']>, options?: Partial<SequencePatternOptions<TEvent>>): {
|
|
10
|
+
initial: keyof TStateSchema['states'];
|
|
11
|
+
states: StatesConfig<any, TStateSchema, TEvent>;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
14
14
|
//# sourceMappingURL=patterns.d.ts.map
|
package/lib/registry.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Actor } from './Actor';
|
|
2
|
-
export interface Registry {
|
|
3
|
-
bookId(): string;
|
|
4
|
-
register(id: string, actor: Actor): string;
|
|
5
|
-
get(id: string): Actor | undefined;
|
|
6
|
-
free(id: string): void;
|
|
7
|
-
}
|
|
8
|
-
export declare const registry: Registry;
|
|
1
|
+
import { Actor } from './Actor';
|
|
2
|
+
export interface Registry {
|
|
3
|
+
bookId(): string;
|
|
4
|
+
register(id: string, actor: Actor): string;
|
|
5
|
+
get(id: string): Actor | undefined;
|
|
6
|
+
free(id: string): void;
|
|
7
|
+
}
|
|
8
|
+
export declare const registry: Registry;
|
|
9
9
|
//# sourceMappingURL=registry.d.ts.map
|
package/lib/registry.js
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports
|
|
4
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var children = /*#__PURE__*/new Map();
|
|
5
6
|
var sessionIdIndex = 0;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
7
|
+
var registry = {
|
|
8
|
+
bookId: function () {
|
|
9
|
+
return "x:" + sessionIdIndex++;
|
|
10
|
+
},
|
|
11
|
+
register: function (id, actor) {
|
|
12
|
+
children.set(id, actor);
|
|
13
|
+
return id;
|
|
14
|
+
},
|
|
15
|
+
get: function (id) {
|
|
16
|
+
return children.get(id);
|
|
17
|
+
},
|
|
18
|
+
free: function (id) {
|
|
19
|
+
children.delete(id);
|
|
20
|
+
}
|
|
20
21
|
};
|
|
22
|
+
|
|
23
|
+
exports.registry = registry;
|
package/lib/scheduler.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
interface SchedulerOptions {
|
|
2
|
-
deferEvents: boolean;
|
|
3
|
-
}
|
|
4
|
-
export declare class Scheduler {
|
|
5
|
-
private processingEvent;
|
|
6
|
-
private queue;
|
|
7
|
-
private initialized;
|
|
8
|
-
private options;
|
|
9
|
-
constructor(options?: Partial<SchedulerOptions>);
|
|
10
|
-
initialize(callback?: () => void): void;
|
|
11
|
-
schedule(task: () => void): void;
|
|
12
|
-
clear(): void;
|
|
13
|
-
private flushEvents;
|
|
14
|
-
private process;
|
|
15
|
-
}
|
|
16
|
-
export {};
|
|
1
|
+
interface SchedulerOptions {
|
|
2
|
+
deferEvents: boolean;
|
|
3
|
+
}
|
|
4
|
+
export declare class Scheduler {
|
|
5
|
+
private processingEvent;
|
|
6
|
+
private queue;
|
|
7
|
+
private initialized;
|
|
8
|
+
private options;
|
|
9
|
+
constructor(options?: Partial<SchedulerOptions>);
|
|
10
|
+
initialize(callback?: () => void): void;
|
|
11
|
+
schedule(task: () => void): void;
|
|
12
|
+
clear(): void;
|
|
13
|
+
private flushEvents;
|
|
14
|
+
private process;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
17
17
|
//# sourceMappingURL=scheduler.d.ts.map
|