xstate 4.32.1 → 5.0.0-alpha.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 +483 -0
- package/actions/ExecutableAction.ts +58 -0
- package/actions/dist/xstate-actions.cjs.d.ts +1 -0
- package/actions/dist/xstate-actions.cjs.dev.js +32 -0
- package/actions/dist/xstate-actions.cjs.js +7 -0
- package/actions/dist/xstate-actions.cjs.prod.js +32 -0
- package/actions/dist/xstate-actions.esm.js +2 -0
- package/actions/dynamicAction.ts +34 -0
- package/actions/package.json +4 -0
- package/actors/dist/xstate-actors.cjs.d.ts +1 -0
- package/actors/dist/xstate-actors.cjs.dev.js +21 -0
- package/actors/dist/xstate-actors.cjs.js +7 -0
- package/actors/dist/xstate-actors.cjs.prod.js +21 -0
- package/actors/dist/xstate-actors.esm.js +2 -0
- package/actors/package.json +4 -0
- package/dev/dist/xstate-dev.cjs.d.ts +1 -0
- package/dev/dist/xstate-dev.cjs.dev.js +11 -0
- package/dev/dist/xstate-dev.cjs.js +7 -0
- package/{lib/devTools.js → dev/dist/xstate-dev.cjs.prod.js} +17 -10
- package/dev/dist/xstate-dev.esm.js +1 -0
- package/dev/package.json +4 -0
- package/dist/Machine-9ce74c11.cjs.dev.js +755 -0
- package/dist/Machine-dca041dc.cjs.prod.js +749 -0
- package/dist/Machine-fb2f47f5.esm.js +751 -0
- package/dist/actions-6b86876d.cjs.dev.js +4815 -0
- package/dist/actions-70094c93.cjs.prod.js +4765 -0
- package/dist/actions-ff512f16.esm.js +4757 -0
- package/dist/declarations/actions/ExecutableAction.d.ts +23 -0
- package/dist/declarations/actions/dynamicAction.d.ts +3 -0
- package/dist/declarations/src/Machine.d.ts +4 -0
- package/dist/declarations/src/Mailbox.d.ts +12 -0
- package/dist/declarations/src/ObservableActorRef.d.ts +25 -0
- package/{lib → dist/declarations/src}/SimulatedClock.d.ts +0 -1
- package/dist/declarations/src/State.d.ts +104 -0
- package/dist/declarations/src/StateMachine.d.ts +112 -0
- package/dist/declarations/src/StateNode.d.ts +127 -0
- package/{es → dist/declarations/src}/actionTypes.d.ts +0 -3
- package/dist/declarations/src/actions/assign.d.ts +7 -0
- package/dist/declarations/src/actions/cancel.d.ts +10 -0
- package/dist/declarations/src/actions/choose.d.ts +3 -0
- package/dist/declarations/src/actions/invoke.d.ts +3 -0
- package/dist/declarations/src/actions/log.d.ts +11 -0
- package/dist/declarations/src/actions/pure.d.ts +3 -0
- package/dist/declarations/src/actions/raise.d.ts +9 -0
- package/dist/declarations/src/actions/send.d.ts +55 -0
- package/dist/declarations/src/actions/stop.d.ts +8 -0
- package/dist/declarations/src/actions.d.ts +44 -0
- package/dist/declarations/src/actors.d.ts +38 -0
- package/dist/declarations/src/constants.d.ts +5 -0
- package/{lib/devTools.d.ts → dist/declarations/src/dev/index.d.ts} +2 -2
- package/{es → dist/declarations/src}/environment.d.ts +0 -1
- package/dist/declarations/src/guards.d.ts +9 -0
- package/dist/declarations/src/index.d.ts +47 -0
- package/dist/declarations/src/interpreter.d.ts +147 -0
- package/{es → dist/declarations/src}/mapState.d.ts +0 -1
- package/dist/declarations/src/match.d.ts +5 -0
- package/dist/declarations/src/memo.d.ts +1 -0
- package/dist/declarations/src/model.d.ts +5 -0
- package/{lib → dist/declarations/src}/model.types.d.ts +6 -9
- package/dist/declarations/src/registry.d.ts +8 -0
- package/{es → dist/declarations/src}/schema.d.ts +0 -1
- package/dist/declarations/src/spawn.d.ts +2 -0
- package/dist/declarations/src/stateUtils.d.ts +85 -0
- package/{lib → dist/declarations/src}/typegenTypes.d.ts +16 -17
- package/dist/declarations/src/types.d.ts +1026 -0
- package/dist/declarations/src/utils.d.ts +56 -0
- package/{es/devTools.js → dist/index-20b364c4.esm.js} +18 -6
- package/dist/index-2a564d03.cjs.dev.js +64 -0
- package/dist/xstate.cjs.d.ts +1 -0
- package/dist/xstate.cjs.dev.js +217 -0
- package/dist/xstate.cjs.js +7 -0
- package/dist/xstate.cjs.prod.js +217 -0
- package/dist/xstate.esm.js +172 -0
- package/guards/dist/xstate-guards.cjs.d.ts +1 -0
- package/guards/dist/xstate-guards.cjs.dev.js +15 -0
- package/guards/dist/xstate-guards.cjs.js +7 -0
- package/guards/dist/xstate-guards.cjs.prod.js +15 -0
- package/guards/dist/xstate-guards.esm.js +2 -0
- package/guards/package.json +4 -0
- package/invoke/package.json +4 -0
- package/model/dist/xstate-model.cjs.d.ts +1 -0
- package/model/dist/xstate-model.cjs.dev.js +41 -0
- package/model/dist/xstate-model.cjs.js +7 -0
- package/model/dist/xstate-model.cjs.prod.js +41 -0
- package/model/dist/xstate-model.esm.js +37 -0
- package/model/package.json +4 -0
- package/package.json +21 -30
- package/dist/xstate.interpreter.js +0 -15
- package/dist/xstate.js +0 -15
- package/dist/xstate.web.js +0 -15
- package/es/Actor.d.ts +0 -25
- package/es/Actor.js +0 -99
- package/es/Machine.d.ts +0 -12
- package/es/Machine.js +0 -14
- package/es/SimulatedClock.d.ts +0 -17
- package/es/SimulatedClock.js +0 -81
- package/es/State.d.ts +0 -123
- package/es/State.js +0 -274
- package/es/StateNode.d.ts +0 -287
- package/es/StateNode.js +0 -1566
- package/es/_virtual/_tslib.js +0 -78
- package/es/actionTypes.js +0 -22
- package/es/actions.d.ts +0 -154
- package/es/actions.js +0 -520
- package/es/behaviors.d.ts +0 -37
- package/es/behaviors.js +0 -131
- package/es/constants.d.ts +0 -6
- package/es/constants.js +0 -6
- package/es/devTools.d.ts +0 -14
- package/es/each.d.ts +0 -4
- package/es/each.js +0 -13
- package/es/environment.js +0 -3
- package/es/index.d.ts +0 -22
- package/es/index.js +0 -23
- package/es/interpreter.d.ts +0 -209
- package/es/interpreter.js +0 -1402
- package/es/invoke.d.ts +0 -11
- package/es/invokeUtils.d.ts +0 -7
- package/es/invokeUtils.js +0 -40
- package/es/json.d.ts +0 -31
- package/es/json.js +0 -86
- package/es/mapState.js +0 -32
- package/es/match.d.ts +0 -9
- package/es/match.js +0 -34
- package/es/model.d.ts +0 -5
- package/es/model.js +0 -50
- package/es/model.types.d.ts +0 -56
- package/es/patterns.d.ts +0 -14
- package/es/patterns.js +0 -48
- package/es/registry.d.ts +0 -9
- package/es/registry.js +0 -19
- package/es/scheduler.d.ts +0 -17
- package/es/scheduler.js +0 -79
- package/es/schema.js +0 -6
- package/es/scxml.d.ts +0 -6
- package/es/serviceScope.d.ts +0 -4
- package/es/serviceScope.js +0 -16
- package/es/stateUtils.d.ts +0 -17
- package/es/stateUtils.js +0 -259
- package/es/typegenTypes.d.ts +0 -133
- package/es/types.d.ts +0 -1031
- package/es/types.js +0 -33
- package/es/utils.d.ts +0 -72
- package/es/utils.js +0 -626
- package/es/waitFor.d.ts +0 -32
- package/es/waitFor.js +0 -71
- package/lib/Actor.d.ts +0 -25
- package/lib/Actor.js +0 -108
- package/lib/Machine.d.ts +0 -12
- package/lib/Machine.js +0 -19
- package/lib/SimulatedClock.js +0 -85
- package/lib/State.d.ts +0 -123
- package/lib/State.js +0 -282
- package/lib/StateNode.d.ts +0 -287
- package/lib/StateNode.js +0 -1570
- package/lib/_virtual/_tslib.js +0 -85
- package/lib/actionTypes.d.ts +0 -20
- package/lib/actionTypes.js +0 -43
- package/lib/actions.d.ts +0 -154
- package/lib/actions.js +0 -552
- package/lib/behaviors.d.ts +0 -37
- package/lib/behaviors.js +0 -137
- package/lib/constants.d.ts +0 -6
- package/lib/constants.js +0 -13
- package/lib/each.d.ts +0 -4
- package/lib/each.js +0 -17
- package/lib/environment.d.ts +0 -2
- package/lib/environment.js +0 -7
- package/lib/index.d.ts +0 -22
- package/lib/index.js +0 -60
- package/lib/interpreter.d.ts +0 -209
- package/lib/interpreter.js +0 -1408
- package/lib/invoke.d.ts +0 -11
- package/lib/invoke.js +0 -20
- package/lib/invokeUtils.d.ts +0 -7
- package/lib/invokeUtils.js +0 -45
- package/lib/json.d.ts +0 -31
- package/lib/json.js +0 -94
- package/lib/mapState.d.ts +0 -4
- package/lib/mapState.js +0 -36
- package/lib/match.d.ts +0 -9
- package/lib/match.js +0 -38
- package/lib/model.d.ts +0 -5
- package/lib/model.js +0 -54
- package/lib/model.types.js +0 -2
- package/lib/patterns.d.ts +0 -14
- package/lib/patterns.js +0 -53
- package/lib/registry.d.ts +0 -9
- package/lib/registry.js +0 -23
- package/lib/scheduler.d.ts +0 -17
- package/lib/scheduler.js +0 -83
- package/lib/schema.d.ts +0 -3
- package/lib/schema.js +0 -11
- package/lib/scxml.d.ts +0 -6
- package/lib/scxml.js +0 -350
- package/lib/serviceScope.d.ts +0 -4
- package/lib/serviceScope.js +0 -21
- package/lib/stateUtils.d.ts +0 -17
- package/lib/stateUtils.js +0 -273
- package/lib/typegenTypes.js +0 -2
- package/lib/types.d.ts +0 -1031
- package/lib/types.js +0 -35
- package/lib/utils.d.ts +0 -72
- package/lib/utils.js +0 -673
- package/lib/waitFor.d.ts +0 -32
- package/lib/waitFor.js +0 -75
package/lib/invoke.d.ts
DELETED
package/lib/invoke.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
// export function fromPromise<T>(
|
|
4
|
-
// promise: Promise<T>,
|
|
5
|
-
// options?: InvokedPromiseOptions
|
|
6
|
-
// ): any {
|
|
7
|
-
// const optionsWithDefaults = {
|
|
8
|
-
// id: 'promise',
|
|
9
|
-
// ...options
|
|
10
|
-
// };
|
|
11
|
-
// return Machine<T, PromiseMachineSchema>({
|
|
12
|
-
// id: optionsWithDefaults.id,
|
|
13
|
-
// initial: 'pending',
|
|
14
|
-
// states: {
|
|
15
|
-
// pending: {},
|
|
16
|
-
// resolved: {},
|
|
17
|
-
// rejected: {}
|
|
18
|
-
// }
|
|
19
|
-
// });
|
|
20
|
-
// }
|
package/lib/invokeUtils.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
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
|
-
//# sourceMappingURL=invokeUtils.d.ts.map
|
package/lib/invokeUtils.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var _tslib = require('./_virtual/_tslib.js');
|
|
6
|
-
require('./types.js');
|
|
7
|
-
var actionTypes = require('./actionTypes.js');
|
|
8
|
-
require('./utils.js');
|
|
9
|
-
require('./environment.js');
|
|
10
|
-
|
|
11
|
-
function toInvokeSource(src) {
|
|
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;
|
|
26
|
-
}
|
|
27
|
-
function toInvokeDefinition(invokeConfig) {
|
|
28
|
-
return _tslib.__assign(_tslib.__assign({
|
|
29
|
-
type: actionTypes.invoke
|
|
30
|
-
}, invokeConfig), {
|
|
31
|
-
toJSON: function () {
|
|
32
|
-
invokeConfig.onDone;
|
|
33
|
-
invokeConfig.onError;
|
|
34
|
-
var 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
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
exports.toInvokeDefinition = toInvokeDefinition;
|
|
45
|
-
exports.toInvokeSource = toInvokeSource;
|
package/lib/json.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
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
|
-
//# sourceMappingURL=json.d.ts.map
|
package/lib/json.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var utils = require('./utils.js');
|
|
6
|
-
|
|
7
|
-
function stringifyFunction(fn) {
|
|
8
|
-
return {
|
|
9
|
-
$function: fn.toString()
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function getStateNodeId(stateNode) {
|
|
14
|
-
return "#".concat(stateNode.id);
|
|
15
|
-
} // derive config from machine
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
function machineToJSON(stateNode) {
|
|
19
|
-
var config = {
|
|
20
|
-
type: stateNode.type,
|
|
21
|
-
initial: stateNode.initial === undefined ? undefined : String(stateNode.initial),
|
|
22
|
-
id: stateNode.id,
|
|
23
|
-
key: stateNode.key,
|
|
24
|
-
entry: stateNode.onEntry,
|
|
25
|
-
exit: stateNode.onExit,
|
|
26
|
-
on: utils.mapValues(stateNode.on, function (transition) {
|
|
27
|
-
return transition.map(function (t) {
|
|
28
|
-
return {
|
|
29
|
-
target: t.target ? t.target.map(getStateNodeId) : [],
|
|
30
|
-
source: getStateNodeId(t.source),
|
|
31
|
-
actions: t.actions,
|
|
32
|
-
cond: t.cond,
|
|
33
|
-
eventType: t.eventType
|
|
34
|
-
};
|
|
35
|
-
});
|
|
36
|
-
}),
|
|
37
|
-
invoke: stateNode.invoke,
|
|
38
|
-
states: {}
|
|
39
|
-
};
|
|
40
|
-
Object.values(stateNode.states).forEach(function (sn) {
|
|
41
|
-
config.states[sn.key] = machineToJSON(sn);
|
|
42
|
-
});
|
|
43
|
-
return config;
|
|
44
|
-
}
|
|
45
|
-
function stringify(machine) {
|
|
46
|
-
return JSON.stringify(machineToJSON(machine), function (_, value) {
|
|
47
|
-
if (utils.isFunction(value)) {
|
|
48
|
-
return {
|
|
49
|
-
$function: value.toString()
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return value;
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
function parse(machineString) {
|
|
57
|
-
var config = JSON.parse(machineString, function (_, value) {
|
|
58
|
-
if (typeof value === 'object' && '$function' in value) {
|
|
59
|
-
return new Function(value.value);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return value;
|
|
63
|
-
});
|
|
64
|
-
return config;
|
|
65
|
-
}
|
|
66
|
-
function jsonify(value) {
|
|
67
|
-
Object.defineProperty(value, 'toJSON', {
|
|
68
|
-
value: function () {
|
|
69
|
-
return utils.mapValues(value, function (subValue) {
|
|
70
|
-
if (utils.isFunction(subValue)) {
|
|
71
|
-
return stringifyFunction(subValue);
|
|
72
|
-
} else if (typeof subValue === 'object' && !Array.isArray(subValue)) {
|
|
73
|
-
// mostly for assignments
|
|
74
|
-
return utils.mapValues(subValue, function (subSubValue) {
|
|
75
|
-
if (utils.isFunction(subSubValue)) {
|
|
76
|
-
return stringifyFunction(subSubValue);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return subSubValue;
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return subValue;
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
return value;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
exports.jsonify = jsonify;
|
|
91
|
-
exports.machineToJSON = machineToJSON;
|
|
92
|
-
exports.parse = parse;
|
|
93
|
-
exports.stringify = stringify;
|
|
94
|
-
exports.stringifyFunction = stringifyFunction;
|
package/lib/mapState.d.ts
DELETED
package/lib/mapState.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
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
|
-
|
|
8
|
-
function mapState(stateMap, stateId) {
|
|
9
|
-
var e_1, _a;
|
|
10
|
-
|
|
11
|
-
var foundStateId;
|
|
12
|
-
|
|
13
|
-
try {
|
|
14
|
-
for (var _b = _tslib.__values(Object.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
|
-
}
|
|
20
|
-
}
|
|
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;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return stateMap[foundStateId];
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
exports.mapState = mapState;
|
package/lib/match.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
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
|
-
//# sourceMappingURL=match.d.ts.map
|
package/lib/match.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
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
|
-
|
|
8
|
-
function matchState(state, patterns, defaultValue) {
|
|
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
|
-
}
|
|
22
|
-
}
|
|
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;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return defaultValue(resolvedState);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
exports.matchState = matchState;
|
package/lib/model.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { Cast, EventObject, BaseActionObject, Prop, IsNever } from './types';
|
|
2
|
-
import { UnionFromCreatorsReturnTypes, FinalModelCreators, Model, ModelCreators } from './model.types';
|
|
3
|
-
export declare function createModel<TContext, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject>(initialContext: TContext): Model<TContext, TEvent, TAction, void>;
|
|
4
|
-
export declare function createModel<TContext, TModelCreators extends ModelCreators<TModelCreators>, TFinalModelCreators = FinalModelCreators<TModelCreators>, TComputedEvent = UnionFromCreatorsReturnTypes<Prop<TFinalModelCreators, 'events'>>, TComputedAction = UnionFromCreatorsReturnTypes<Prop<TFinalModelCreators, 'actions'>>>(initialContext: TContext, creators: TModelCreators): Model<TContext, Cast<TComputedEvent, EventObject>, IsNever<TComputedAction> extends true ? BaseActionObject : Cast<TComputedAction, BaseActionObject>, TFinalModelCreators>;
|
|
5
|
-
//# sourceMappingURL=model.d.ts.map
|
package/lib/model.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var _tslib = require('./_virtual/_tslib.js');
|
|
6
|
-
var actions = require('./actions.js');
|
|
7
|
-
var Machine = require('./Machine.js');
|
|
8
|
-
var utils = require('./utils.js');
|
|
9
|
-
|
|
10
|
-
function createModel(initialContext, creators) {
|
|
11
|
-
var eventCreators = creators === null || creators === void 0 ? void 0 : creators.events;
|
|
12
|
-
var actionCreators = creators === null || creators === void 0 ? void 0 : creators.actions;
|
|
13
|
-
var model = {
|
|
14
|
-
initialContext: initialContext,
|
|
15
|
-
assign: actions.assign,
|
|
16
|
-
events: eventCreators ? utils.mapValues(eventCreators, function (fn, eventType) {
|
|
17
|
-
return function () {
|
|
18
|
-
var args = [];
|
|
19
|
-
|
|
20
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
21
|
-
args[_i] = arguments[_i];
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return _tslib.__assign(_tslib.__assign({}, fn.apply(void 0, _tslib.__spreadArray([], _tslib.__read(args), false))), {
|
|
25
|
-
type: eventType
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
}) : undefined,
|
|
29
|
-
actions: actionCreators ? utils.mapValues(actionCreators, function (fn, actionType) {
|
|
30
|
-
return function () {
|
|
31
|
-
var args = [];
|
|
32
|
-
|
|
33
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
34
|
-
args[_i] = arguments[_i];
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return _tslib.__assign(_tslib.__assign({}, fn.apply(void 0, _tslib.__spreadArray([], _tslib.__read(args), false))), {
|
|
38
|
-
type: actionType
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
}) : undefined,
|
|
42
|
-
reset: function () {
|
|
43
|
-
return actions.assign(initialContext);
|
|
44
|
-
},
|
|
45
|
-
createMachine: function (config, implementations) {
|
|
46
|
-
return Machine.createMachine('context' in config ? config : _tslib.__assign(_tslib.__assign({}, config), {
|
|
47
|
-
context: initialContext
|
|
48
|
-
}), implementations);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
return model;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
exports.createModel = createModel;
|
package/lib/model.types.js
DELETED
package/lib/patterns.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
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
|
-
//# sourceMappingURL=patterns.d.ts.map
|
package/lib/patterns.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
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
|
-
|
|
8
|
-
function toggle(onState, offState, eventType) {
|
|
9
|
-
var _a, _b, _c;
|
|
10
|
-
|
|
11
|
-
return _a = {}, _a[onState] = {
|
|
12
|
-
on: (_b = {}, _b[eventType] = offState, _b)
|
|
13
|
-
}, _a[offState] = {
|
|
14
|
-
on: (_c = {}, _c[eventType] = onState, _c)
|
|
15
|
-
}, _a;
|
|
16
|
-
}
|
|
17
|
-
var defaultSequencePatternOptions = {
|
|
18
|
-
nextEvent: 'NEXT',
|
|
19
|
-
prevEvent: 'PREV'
|
|
20
|
-
};
|
|
21
|
-
function sequence(items, options) {
|
|
22
|
-
var resolvedOptions = _tslib.__assign(_tslib.__assign({}, defaultSequencePatternOptions), options);
|
|
23
|
-
|
|
24
|
-
var states = {};
|
|
25
|
-
var nextEventObject = resolvedOptions.nextEvent === undefined ? undefined : utils.toEventObject(resolvedOptions.nextEvent);
|
|
26
|
-
var prevEventObject = resolvedOptions.prevEvent === undefined ? undefined : utils.toEventObject(resolvedOptions.prevEvent);
|
|
27
|
-
items.forEach(function (item, i) {
|
|
28
|
-
var state = {
|
|
29
|
-
on: {}
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
if (i + 1 === items.length) {
|
|
33
|
-
state.type = 'final';
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (nextEventObject && i + 1 < items.length) {
|
|
37
|
-
state.on[nextEventObject.type] = items[i + 1];
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (prevEventObject && i > 0) {
|
|
41
|
-
state.on[prevEventObject.type] = items[i - 1];
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
states[item] = state;
|
|
45
|
-
});
|
|
46
|
-
return {
|
|
47
|
-
initial: items[0],
|
|
48
|
-
states: states
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
exports.sequence = sequence;
|
|
53
|
-
exports.toggle = toggle;
|
package/lib/registry.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
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
|
-
//# sourceMappingURL=registry.d.ts.map
|
package/lib/registry.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var children = /*#__PURE__*/new Map();
|
|
6
|
-
var sessionIdIndex = 0;
|
|
7
|
-
var registry = {
|
|
8
|
-
bookId: function () {
|
|
9
|
-
return "x:".concat(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
|
-
}
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
exports.registry = registry;
|
package/lib/scheduler.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
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
|
-
//# sourceMappingURL=scheduler.d.ts.map
|
package/lib/scheduler.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var _tslib = require('./_virtual/_tslib.js');
|
|
6
|
-
|
|
7
|
-
var defaultOptions = {
|
|
8
|
-
deferEvents: false
|
|
9
|
-
};
|
|
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;
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
return Scheduler;
|
|
81
|
-
}();
|
|
82
|
-
|
|
83
|
-
exports.Scheduler = Scheduler;
|
package/lib/schema.d.ts
DELETED
package/lib/schema.js
DELETED
package/lib/scxml.d.ts
DELETED