xstate 4.31.0 → 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 +526 -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 +10 -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 +28 -26
- 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 -52
- 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 -130
- package/es/types.d.ts +0 -1037
- 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 -66
- 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 -1037
- 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 -70
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { c as createDynamicAction, p as pure$1, t as toArray, m as matchesState, S as State, _ as _createForOfIteratorHelper, a as _slicedToArray, b as _createClass, d as _toConsumableArray, e as _classCallCheck, f as _defineProperty, r as raise, s as send, g as sendParent, h as sendTo, i as sendUpdate, l as log, j as cancel, k as stop, n as assign, o as after, q as done, u as respond, v as forwardTo, w as escalate, x as choose } from './actions-ff512f16.esm.js';
|
|
2
|
+
export { G as ActionTypes, I as Interpreter, z as InterpreterStatus, O as ObservableActorRef, H as SpecialTargets, S as State, n as assign, A as doneInvoke, v as forwardTo, B as getStateNodes, y as interpret, m as matchesState, C as pathToStateValue, s as send, g as sendParent, i as sendUpdate, D as toEventObject, E as toObserver, F as toSCXMLEvent } from './actions-ff512f16.esm.js';
|
|
3
|
+
import './index-20b364c4.esm.js';
|
|
4
|
+
export { a as StateMachine, S as StateNode, c as createMachine } from './Machine-fb2f47f5.esm.js';
|
|
5
|
+
|
|
6
|
+
function pure(getActions) {
|
|
7
|
+
return createDynamicAction(pure$1, {
|
|
8
|
+
get: getActions
|
|
9
|
+
}, function (_ref, ctx, _event) {
|
|
10
|
+
var _toArray;
|
|
11
|
+
|
|
12
|
+
var params = _ref.params;
|
|
13
|
+
return {
|
|
14
|
+
type: pure$1,
|
|
15
|
+
params: {
|
|
16
|
+
actions: (_toArray = toArray(params.get(ctx, _event.data))) !== null && _toArray !== void 0 ? _toArray : []
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function mapState(stateMap, stateId) {
|
|
23
|
+
var foundStateId;
|
|
24
|
+
|
|
25
|
+
for (var _i = 0, _Object$keys = Object.keys(stateMap); _i < _Object$keys.length; _i++) {
|
|
26
|
+
var mappedStateId = _Object$keys[_i];
|
|
27
|
+
|
|
28
|
+
if (matchesState(mappedStateId, stateId) && (!foundStateId || stateId.length > foundStateId.length)) {
|
|
29
|
+
foundStateId = mappedStateId;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return stateMap[foundStateId];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function matchState(state, patterns, defaultValue) {
|
|
37
|
+
var resolvedState = State.from(state, state instanceof State ? state.context : undefined);
|
|
38
|
+
|
|
39
|
+
var _iterator = _createForOfIteratorHelper(patterns),
|
|
40
|
+
_step;
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
44
|
+
var _step$value = _slicedToArray(_step.value, 2),
|
|
45
|
+
stateValue = _step$value[0],
|
|
46
|
+
getValue = _step$value[1];
|
|
47
|
+
|
|
48
|
+
if (resolvedState.matches(stateValue)) {
|
|
49
|
+
return getValue(resolvedState);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
} catch (err) {
|
|
53
|
+
_iterator.e(err);
|
|
54
|
+
} finally {
|
|
55
|
+
_iterator.f();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return defaultValue(resolvedState);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function createSchema(schema) {
|
|
62
|
+
return schema;
|
|
63
|
+
}
|
|
64
|
+
var t = createSchema;
|
|
65
|
+
|
|
66
|
+
var SimulatedClock = /*#__PURE__*/function () {
|
|
67
|
+
function SimulatedClock() {
|
|
68
|
+
_classCallCheck(this, SimulatedClock);
|
|
69
|
+
|
|
70
|
+
_defineProperty(this, "timeouts", new Map());
|
|
71
|
+
|
|
72
|
+
_defineProperty(this, "_now", 0);
|
|
73
|
+
|
|
74
|
+
_defineProperty(this, "_id", 0);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
_createClass(SimulatedClock, [{
|
|
78
|
+
key: "now",
|
|
79
|
+
value: function now() {
|
|
80
|
+
return this._now;
|
|
81
|
+
}
|
|
82
|
+
}, {
|
|
83
|
+
key: "getId",
|
|
84
|
+
value: function getId() {
|
|
85
|
+
return this._id++;
|
|
86
|
+
}
|
|
87
|
+
}, {
|
|
88
|
+
key: "setTimeout",
|
|
89
|
+
value: function setTimeout(fn, timeout) {
|
|
90
|
+
var id = this.getId();
|
|
91
|
+
this.timeouts.set(id, {
|
|
92
|
+
start: this.now(),
|
|
93
|
+
timeout: timeout,
|
|
94
|
+
fn: fn
|
|
95
|
+
});
|
|
96
|
+
return id;
|
|
97
|
+
}
|
|
98
|
+
}, {
|
|
99
|
+
key: "clearTimeout",
|
|
100
|
+
value: function clearTimeout(id) {
|
|
101
|
+
this.timeouts["delete"](id);
|
|
102
|
+
}
|
|
103
|
+
}, {
|
|
104
|
+
key: "set",
|
|
105
|
+
value: function set(time) {
|
|
106
|
+
if (this._now > time) {
|
|
107
|
+
throw new Error('Unable to travel back in time');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
this._now = time;
|
|
111
|
+
this.flushTimeouts();
|
|
112
|
+
}
|
|
113
|
+
}, {
|
|
114
|
+
key: "flushTimeouts",
|
|
115
|
+
value: function flushTimeouts() {
|
|
116
|
+
var _this = this;
|
|
117
|
+
|
|
118
|
+
_toConsumableArray(this.timeouts).sort(function (_ref, _ref2) {
|
|
119
|
+
var _ref3 = _slicedToArray(_ref, 2),
|
|
120
|
+
_idA = _ref3[0],
|
|
121
|
+
timeoutA = _ref3[1];
|
|
122
|
+
|
|
123
|
+
var _ref4 = _slicedToArray(_ref2, 2),
|
|
124
|
+
_idB = _ref4[0],
|
|
125
|
+
timeoutB = _ref4[1];
|
|
126
|
+
|
|
127
|
+
var endA = timeoutA.start + timeoutA.timeout;
|
|
128
|
+
var endB = timeoutB.start + timeoutB.timeout;
|
|
129
|
+
return endB > endA ? -1 : 1;
|
|
130
|
+
}).forEach(function (_ref5) {
|
|
131
|
+
var _ref6 = _slicedToArray(_ref5, 2),
|
|
132
|
+
id = _ref6[0],
|
|
133
|
+
timeout = _ref6[1];
|
|
134
|
+
|
|
135
|
+
if (_this.now() - timeout.start >= timeout.timeout) {
|
|
136
|
+
_this.timeouts["delete"](id);
|
|
137
|
+
|
|
138
|
+
timeout.fn.call(null);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}, {
|
|
143
|
+
key: "increment",
|
|
144
|
+
value: function increment(ms) {
|
|
145
|
+
this._now += ms;
|
|
146
|
+
this.flushTimeouts();
|
|
147
|
+
}
|
|
148
|
+
}]);
|
|
149
|
+
|
|
150
|
+
return SimulatedClock;
|
|
151
|
+
}();
|
|
152
|
+
|
|
153
|
+
var actions = {
|
|
154
|
+
raise: raise,
|
|
155
|
+
send: send,
|
|
156
|
+
sendParent: sendParent,
|
|
157
|
+
sendTo: sendTo,
|
|
158
|
+
sendUpdate: sendUpdate,
|
|
159
|
+
log: log,
|
|
160
|
+
cancel: cancel,
|
|
161
|
+
stop: stop,
|
|
162
|
+
assign: assign,
|
|
163
|
+
after: after,
|
|
164
|
+
done: done,
|
|
165
|
+
respond: respond,
|
|
166
|
+
forwardTo: forwardTo,
|
|
167
|
+
escalate: escalate,
|
|
168
|
+
choose: choose,
|
|
169
|
+
pure: pure
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
export { SimulatedClock, actions, createSchema, mapState, matchState, t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../../dist/declarations/src/guards";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var guards_dist_xstateGuards = require('../../dist/actions-6b86876d.cjs.dev.js');
|
|
6
|
+
require('../../dist/index-2a564d03.cjs.dev.js');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
exports.and = guards_dist_xstateGuards.and;
|
|
11
|
+
exports.evaluateGuard = guards_dist_xstateGuards.evaluateGuard;
|
|
12
|
+
exports.not = guards_dist_xstateGuards.not;
|
|
13
|
+
exports.or = guards_dist_xstateGuards.or;
|
|
14
|
+
exports.stateIn = guards_dist_xstateGuards.stateIn;
|
|
15
|
+
exports.toGuardDefinition = guards_dist_xstateGuards.toGuardDefinition;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var guards_dist_xstateGuards = require('../../dist/actions-70094c93.cjs.prod.js');
|
|
6
|
+
require('../../dev/dist/xstate-dev.cjs.prod.js');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
exports.and = guards_dist_xstateGuards.and;
|
|
11
|
+
exports.evaluateGuard = guards_dist_xstateGuards.evaluateGuard;
|
|
12
|
+
exports.not = guards_dist_xstateGuards.not;
|
|
13
|
+
exports.or = guards_dist_xstateGuards.or;
|
|
14
|
+
exports.stateIn = guards_dist_xstateGuards.stateIn;
|
|
15
|
+
exports.toGuardDefinition = guards_dist_xstateGuards.toGuardDefinition;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../../dist/declarations/src/model";
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var guards_dist_xstateGuards = require('../../dist/actions-6b86876d.cjs.dev.js');
|
|
6
|
+
require('../../dist/index-2a564d03.cjs.dev.js');
|
|
7
|
+
var Machine = require('../../dist/Machine-9ce74c11.cjs.dev.js');
|
|
8
|
+
|
|
9
|
+
function createModel(initialContext, creators) {
|
|
10
|
+
var eventCreators = creators === null || creators === void 0 ? void 0 : creators.events;
|
|
11
|
+
var actionCreators = creators === null || creators === void 0 ? void 0 : creators.actions;
|
|
12
|
+
var model = {
|
|
13
|
+
initialContext: initialContext,
|
|
14
|
+
assign: guards_dist_xstateGuards.assign,
|
|
15
|
+
events: eventCreators ? guards_dist_xstateGuards.mapValues(eventCreators, function (fn, eventType) {
|
|
16
|
+
return function () {
|
|
17
|
+
return guards_dist_xstateGuards._objectSpread2(guards_dist_xstateGuards._objectSpread2({}, fn.apply(void 0, arguments)), {}, {
|
|
18
|
+
type: eventType
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
}) : undefined,
|
|
22
|
+
actions: actionCreators ? guards_dist_xstateGuards.mapValues(actionCreators, function (fn, actionType) {
|
|
23
|
+
return function () {
|
|
24
|
+
return guards_dist_xstateGuards._objectSpread2(guards_dist_xstateGuards._objectSpread2({}, fn.apply(void 0, arguments)), {}, {
|
|
25
|
+
type: actionType
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
}) : undefined,
|
|
29
|
+
reset: function reset() {
|
|
30
|
+
return guards_dist_xstateGuards.assign(initialContext);
|
|
31
|
+
},
|
|
32
|
+
createMachine: function createMachine(config, implementations) {
|
|
33
|
+
return Machine.createMachine('context' in config ? config : guards_dist_xstateGuards._objectSpread2(guards_dist_xstateGuards._objectSpread2({}, config), {}, {
|
|
34
|
+
context: initialContext
|
|
35
|
+
}), implementations);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
return model;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
exports.createModel = createModel;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var guards_dist_xstateGuards = require('../../dist/actions-70094c93.cjs.prod.js');
|
|
6
|
+
require('../../dev/dist/xstate-dev.cjs.prod.js');
|
|
7
|
+
var Machine = require('../../dist/Machine-dca041dc.cjs.prod.js');
|
|
8
|
+
|
|
9
|
+
function createModel(initialContext, creators) {
|
|
10
|
+
var eventCreators = creators === null || creators === void 0 ? void 0 : creators.events;
|
|
11
|
+
var actionCreators = creators === null || creators === void 0 ? void 0 : creators.actions;
|
|
12
|
+
var model = {
|
|
13
|
+
initialContext: initialContext,
|
|
14
|
+
assign: guards_dist_xstateGuards.assign,
|
|
15
|
+
events: eventCreators ? guards_dist_xstateGuards.mapValues(eventCreators, function (fn, eventType) {
|
|
16
|
+
return function () {
|
|
17
|
+
return guards_dist_xstateGuards._objectSpread2(guards_dist_xstateGuards._objectSpread2({}, fn.apply(void 0, arguments)), {}, {
|
|
18
|
+
type: eventType
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
}) : undefined,
|
|
22
|
+
actions: actionCreators ? guards_dist_xstateGuards.mapValues(actionCreators, function (fn, actionType) {
|
|
23
|
+
return function () {
|
|
24
|
+
return guards_dist_xstateGuards._objectSpread2(guards_dist_xstateGuards._objectSpread2({}, fn.apply(void 0, arguments)), {}, {
|
|
25
|
+
type: actionType
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
}) : undefined,
|
|
29
|
+
reset: function reset() {
|
|
30
|
+
return guards_dist_xstateGuards.assign(initialContext);
|
|
31
|
+
},
|
|
32
|
+
createMachine: function createMachine(config, implementations) {
|
|
33
|
+
return Machine.createMachine('context' in config ? config : guards_dist_xstateGuards._objectSpread2(guards_dist_xstateGuards._objectSpread2({}, config), {}, {
|
|
34
|
+
context: initialContext
|
|
35
|
+
}), implementations);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
return model;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
exports.createModel = createModel;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { n as assign, M as mapValues, X as _objectSpread2 } from '../../dist/actions-ff512f16.esm.js';
|
|
2
|
+
import '../../dist/index-20b364c4.esm.js';
|
|
3
|
+
import { c as createMachine } from '../../dist/Machine-fb2f47f5.esm.js';
|
|
4
|
+
|
|
5
|
+
function createModel(initialContext, creators) {
|
|
6
|
+
var eventCreators = creators === null || creators === void 0 ? void 0 : creators.events;
|
|
7
|
+
var actionCreators = creators === null || creators === void 0 ? void 0 : creators.actions;
|
|
8
|
+
var model = {
|
|
9
|
+
initialContext: initialContext,
|
|
10
|
+
assign: assign,
|
|
11
|
+
events: eventCreators ? mapValues(eventCreators, function (fn, eventType) {
|
|
12
|
+
return function () {
|
|
13
|
+
return _objectSpread2(_objectSpread2({}, fn.apply(void 0, arguments)), {}, {
|
|
14
|
+
type: eventType
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
}) : undefined,
|
|
18
|
+
actions: actionCreators ? mapValues(actionCreators, function (fn, actionType) {
|
|
19
|
+
return function () {
|
|
20
|
+
return _objectSpread2(_objectSpread2({}, fn.apply(void 0, arguments)), {}, {
|
|
21
|
+
type: actionType
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
}) : undefined,
|
|
25
|
+
reset: function reset() {
|
|
26
|
+
return assign(initialContext);
|
|
27
|
+
},
|
|
28
|
+
createMachine: function createMachine$1(config, implementations) {
|
|
29
|
+
return createMachine('context' in config ? config : _objectSpread2(_objectSpread2({}, config), {}, {
|
|
30
|
+
context: initialContext
|
|
31
|
+
}), implementations);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
return model;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { createModel };
|
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xstate",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0-alpha.0",
|
|
4
4
|
"description": "Finite State Machines and Statecharts for the Modern Web.",
|
|
5
|
-
"main": "
|
|
6
|
-
"module": "
|
|
7
|
-
"types": "lib/index.d.ts",
|
|
5
|
+
"main": "dist/xstate.cjs.js",
|
|
6
|
+
"module": "dist/xstate.esm.js",
|
|
8
7
|
"sideEffects": false,
|
|
9
8
|
"funding": {
|
|
10
9
|
"type": "opencollective",
|
|
@@ -12,10 +11,12 @@
|
|
|
12
11
|
},
|
|
13
12
|
"files": [
|
|
14
13
|
"dist",
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
14
|
+
"actors",
|
|
15
|
+
"actions",
|
|
16
|
+
"invoke",
|
|
17
|
+
"guards",
|
|
18
|
+
"dev",
|
|
19
|
+
"model"
|
|
19
20
|
],
|
|
20
21
|
"keywords": [
|
|
21
22
|
"statechart",
|
|
@@ -26,12 +27,7 @@
|
|
|
26
27
|
"state",
|
|
27
28
|
"interpreter"
|
|
28
29
|
],
|
|
29
|
-
"scripts": {
|
|
30
|
-
"clean": "rm -rf lib es dist tsconfig.tsbuildinfo",
|
|
31
|
-
"test": "jest",
|
|
32
|
-
"build": "rollup -c",
|
|
33
|
-
"prepare": "npm run build"
|
|
34
|
-
},
|
|
30
|
+
"scripts": {},
|
|
35
31
|
"repository": {
|
|
36
32
|
"type": "git",
|
|
37
33
|
"url": "git+https://github.com/statelyai/xstate.git"
|
|
@@ -43,27 +39,22 @@
|
|
|
43
39
|
},
|
|
44
40
|
"homepage": "https://github.com/statelyai/xstate/tree/main/packages/core#readme",
|
|
45
41
|
"devDependencies": {
|
|
46
|
-
"@babel/cli": "^7.10.5",
|
|
47
|
-
"@babel/core": "^7.10.5",
|
|
48
|
-
"@rollup/plugin-babel": "^5.3.0",
|
|
49
42
|
"@scion-scxml/test-framework": "^2.0.15",
|
|
50
|
-
"babel-plugin-annotate-pure-calls": "^0.4.0",
|
|
51
|
-
"fast-glob": "^3.2.11",
|
|
52
|
-
"jest": "^26.6.3",
|
|
53
43
|
"jsdom": "^14.0.0",
|
|
54
44
|
"jsdom-global": "^3.0.2",
|
|
55
|
-
"lerna-alias": "3.0.3-0",
|
|
56
45
|
"pkg-up": "^3.1.0",
|
|
57
|
-
"rollup": "^2.69.0",
|
|
58
|
-
"rollup-plugin-filesize": "^6.2.1",
|
|
59
|
-
"rollup-plugin-replace": "^2.2.0",
|
|
60
|
-
"rollup-plugin-terser": "^5.1.2",
|
|
61
|
-
"rollup-plugin-typescript2": "^0.30.0",
|
|
62
|
-
"rollup-plugin-uglify": "^6.0.2",
|
|
63
46
|
"rxjs": "^7.1.0",
|
|
64
|
-
"ts-jest": "^26.5.6",
|
|
65
|
-
"tslib": "^2.3.1",
|
|
66
|
-
"typescript": "^4.5.2",
|
|
67
47
|
"xml-js": "^1.6.11"
|
|
48
|
+
},
|
|
49
|
+
"preconstruct": {
|
|
50
|
+
"umdName": "XState",
|
|
51
|
+
"entrypoints": [
|
|
52
|
+
"./index.ts",
|
|
53
|
+
"./actions.ts",
|
|
54
|
+
"./actors.ts",
|
|
55
|
+
"./model.ts",
|
|
56
|
+
"./guards.ts",
|
|
57
|
+
"./dev/index.ts"
|
|
58
|
+
]
|
|
68
59
|
}
|
|
69
60
|
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XStateInterpreter={})}(this,(function(t){"use strict";
|
|
2
|
-
/*! *****************************************************************************
|
|
3
|
-
Copyright (c) Microsoft Corporation.
|
|
4
|
-
|
|
5
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
-
purpose with or without fee is hereby granted.
|
|
7
|
-
|
|
8
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
9
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
10
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
11
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
12
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
13
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
14
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
15
|
-
***************************************************************************** */var e,n,r=function(){return(r=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function i(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function o(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,i,o=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=o.next()).done;)s.push(r.value)}catch(t){i={error:t}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return s}function s(t,e,n){if(n||2===arguments.length)for(var r,i=0,o=e.length;i<o;i++)!r&&i in e||(r||(r=Array.prototype.slice.call(e,0,i)),r[i]=e[i]);return t.concat(r||Array.prototype.slice.call(e))}!function(t){t.Start="xstate.start",t.Stop="xstate.stop",t.Raise="xstate.raise",t.Send="xstate.send",t.Cancel="xstate.cancel",t.NullEvent="",t.Assign="xstate.assign",t.After="xstate.after",t.DoneState="done.state",t.DoneInvoke="done.invoke",t.Log="xstate.log",t.Init="xstate.init",t.Invoke="xstate.invoke",t.ErrorExecution="error.execution",t.ErrorCommunication="error.communication",t.ErrorPlatform="error.platform",t.ErrorCustom="xstate.error",t.Update="xstate.update",t.Pure="xstate.pure",t.Choose="xstate.choose"}(e||(e={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(n||(n={}));var a,u={};function c(t,e){return"object"==typeof(n=t)&&"value"in n&&"context"in n&&"event"in n&&"_event"in n?t.value:d(t)?h(t):"string"!=typeof t?t:h(function(t,e){try{return d(t)?t:t.toString().split(e)}catch(e){throw new Error("'".concat(t,"' is not a valid state path."))}}(t,e));var n}function h(t){if(1===t.length)return t[0];for(var e={},n=e,r=0;r<t.length-1;r++)r===t.length-2?n[t[r]]=t[r+1]:(n[t[r]]={},n=n[t[r]]);return e}function f(t,e,n){var r,o;if(p(t))return t(e,n.data);var s={};try{for(var a=i(Object.keys(t)),u=a.next();!u.done;u=a.next()){var c=u.value,h=t[c];p(h)?s[c]=h(e,n.data):s[c]=h}}catch(t){r={error:t}}finally{try{u&&!u.done&&(o=a.return)&&o.call(a)}finally{if(r)throw r.error}}return s}function l(t){return t instanceof Promise||!(null===t||!p(t)&&"object"!=typeof t||!p(t.then))}function d(t){return Array.isArray(t)}function p(t){return"function"==typeof t}function v(t){return"string"==typeof t}var y=function(){return"function"==typeof Symbol&&Symbol.observable||"@@observable"}();function g(t){return!!t&&"__xstatenode"in t}(a={})[y]=function(){return this},a[Symbol.observable]=function(){return this};var b=function(){var t=0;return function(){return(++t).toString(16)}}();function m(t,e){return v(t)||"number"==typeof t?r({type:t},e):t}function x(t,e){if(!v(t)&&"$$type"in t&&"scxml"===t.$$type)return t;var n=m(t);return r({name:n.type,data:n,$$type:"scxml",type:"external"},e)}function w(t,e,n){if("object"==typeof t)return t;var r=function(){};return{next:t,error:e||r,complete:n||r}}function S(t){return Object.keys(t.states).map((function(e){return t.states[e]})).filter((function(t){return"history"!==t.type}))}function E(t){return s([],o(new Set(function(t){var e;return(e=[]).concat.apply(e,s([],o(t),!1))}(s([],o(t.map((function(t){return t.ownEvents}))),!1)))),!1)}function _(t,e){return"compound"===e.type?S(e).some((function(e){return"final"===e.type&&(n=t,r=e,Array.isArray(n)?n.some((function(t){return t===r})):n instanceof Set&&n.has(r));var n,r})):"parallel"===e.type&&S(e).every((function(e){return _(t,e)}))}var O=e.Start,T=e.Stop;e.Raise;var I=e.Send,L=e.Cancel;e.NullEvent,e.Assign,e.After,e.DoneState;var k=e.Log,j=e.Init;e.Invoke,e.ErrorExecution;var C=e.ErrorPlatform,P=e.ErrorCustom,N=e.Update;e.Choose,e.Pure;var A=x({type:j});function D(t,n){var r="".concat(e.DoneInvoke,".").concat(t),i={type:r,data:n,toString:function(){return r}};return i}function M(t,n){var r="".concat(e.ErrorPlatform,".").concat(t),i={type:r,data:n,toString:function(){return r}};return i}var z=function(){function t(t){var e,n,r=this;this.actions=[],this.activities=u,this.meta={},this.events=[],this.value=t.value,this.context=t.context,this._event=t._event,this._sessionid=t._sessionid,this.event=this._event.data,this.historyValue=t.historyValue,this.history=t.history,this.actions=t.actions||[],this.activities=t.activities||u,this.meta=(void 0===(n=t.configuration)&&(n=[]),n.reduce((function(t,e){return void 0!==e.meta&&(t[e.id]=e.meta),t}),{})),this.events=t.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=t.configuration,this.transitions=t.transitions,this.children=t.children,this.done=!!t.done,this.tags=null!==(e=Array.isArray(t.tags)?new Set(t.tags):t.tags)&&void 0!==e?e:new Set,this.machine=t.machine,Object.defineProperty(this,"nextEvents",{get:function(){return E(r.configuration)}})}return t.from=function(e,n){return e instanceof t?e.context!==n?new t({value:e.value,context:n,_event:e._event,_sessionid:null,historyValue:e.historyValue,history:e.history,actions:[],activities:e.activities,meta:{},events:[],configuration:[],transitions:[],children:{}}):e:new t({value:e,context:n,_event:A,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})},t.create=function(e){return new t(e)},t.inert=function(e,n){if(e instanceof t){if(!e.actions.length)return e;var r=A;return new t({value:e.value,context:n,_event:r,_sessionid:null,historyValue:e.historyValue,history:e.history,activities:e.activities,configuration:e.configuration,transitions:[],children:{}})}return t.from(e,n)},t.prototype.toStrings=function(t,e){var n=this;if(void 0===t&&(t=this.value),void 0===e&&(e="."),v(t))return[t];var r=Object.keys(t);return r.concat.apply(r,s([],o(r.map((function(r){return n.toStrings(t[r],e).map((function(t){return r+e+t}))}))),!1))},t.prototype.toJSON=function(){var t=this;t.configuration,t.transitions;var e=t.tags;t.machine;var n=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]])}return n}(t,["configuration","transitions","tags","machine"]);return r(r({},n),{tags:Array.from(e)})},t.prototype.matches=function(t){return function t(e,n,r){void 0===r&&(r=".");var i=c(e,r),o=c(n,r);return v(o)?!!v(i)&&o===i:v(i)?i in o:Object.keys(i).every((function(e){return e in o&&t(i[e],o[e])}))}(t,this.value)},t.prototype.hasTag=function(t){return this.tags.has(t)},t.prototype.can=function(t){var e;this.machine;var n=null===(e=this.machine)||void 0===e?void 0:e.getTransitionData(this,t);return!!(null==n?void 0:n.transitions.length)&&n.transitions.some((function(t){return void 0!==t.target||t.actions.length}))},t}(),R={deferEvents:!1},V=function(){function t(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=r(r({},R),t)}return t.prototype.initialize=function(t){if(this.initialized=!0,t){if(!this.options.deferEvents)return void this.schedule(t);this.process(t)}this.flushEvents()},t.prototype.schedule=function(t){if(this.initialized&&!this.processingEvent){if(0!==this.queue.length)throw new Error("Event queue should be empty when it is not processing events");this.process(t),this.flushEvents()}else this.queue.push(t)},t.prototype.clear=function(){this.queue=[]},t.prototype.flushEvents=function(){for(var t=this.queue.shift();t;)this.process(t),t=this.queue.shift()},t.prototype.process=function(t){this.processingEvent=!0;try{t()}catch(t){throw this.clear(),t}finally{this.processingEvent=!1}},t}(),J=[],q=function(t,e){J.push(t);var n=e(t);return J.pop(),n};function U(t,e,n){var r=function(t){var e;return(e={id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},getSnapshot:function(){},toJSON:function(){return{id:t}}})[y]=function(){return this},e}(e);if(r.deferred=!0,g(t)){var i=r.state=q(void 0,(function(){return(n?t.withContext(n):t).initialState}));r.getSnapshot=function(){return i}}return r}var $=new Map,F=0,X=function(){return"x:".concat(F++)},B=function(t,e){return $.set(t,e),t},G=function(t){return $.get(t)},H=function(t){$.delete(t)};function K(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function Q(t){if(K()){var e=function(){var t=K();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}}function W(t,e){void 0===e&&(e={});var n=t.initialState,i=new Set,o=[],s=!1,a=function(t){var e;return r(((e={subscribe:function(){return{unsubscribe:function(){}}},id:"anonymous",getSnapshot:function(){}})[y]=function(){return this},e),t)}({id:e.id,send:function(e){o.push(e),function(){if(!s){for(s=!0;o.length>0;){var e=o.shift();n=t.transition(n,e,u),i.forEach((function(t){return t.next(n)}))}s=!1}}()},getSnapshot:function(){return n},subscribe:function(t,e,r){var o=w(t,e,r);return i.add(o),o.next(n),{unsubscribe:function(){i.delete(o)}}}}),u={parent:e.parent,self:a,id:e.id||"anonymous",observers:i};return n=t.start?t.start(u):n,a}var Y,Z={sync:!1,autoForward:!1};t.InterpreterStatus=void 0,(Y=t.InterpreterStatus||(t.InterpreterStatus={}))[Y.NotStarted=0]="NotStarted",Y[Y.Running=1]="Running",Y[Y.Stopped=2]="Stopped";var tt=function(){function a(e,i){var o=this;void 0===i&&(i=a.defaultOptions),this.machine=e,this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.sendListeners=new Set,this.initialized=!1,this.status=t.InterpreterStatus.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=function(e,n){if(d(e))return o.batch(e),o.state;var r=x(m(e,n));if(o.status===t.InterpreterStatus.Stopped)return o.state;if(o.status!==t.InterpreterStatus.Running&&!o.options.deferEvents)throw new Error('Event "'.concat(r.name,'" was sent to uninitialized service "').concat(o.machine.id,'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: ').concat(JSON.stringify(r.data)));return o.scheduler.schedule((function(){o.forward(r);var t=o.nextState(r);o.update(t,r)})),o._state},this.sendTo=function(t,e){var i,s=o.parent&&(e===n.Parent||o.parent.id===e),a=s?o.parent:v(e)?o.children.get(e)||G(e):(i=e)&&"function"==typeof i.send?e:void 0;if(a)"machine"in a?a.send(r(r({},t),{name:t.name===P?"".concat(M(o.id)):t.name,origin:o.sessionId})):a.send(t.data);else if(!s)throw new Error("Unable to send event to child '".concat(e,"' from service '").concat(o.id,"'."))};var s=r(r({},a.defaultOptions),i),u=s.clock,c=s.logger,h=s.parent,f=s.id,l=void 0!==f?f:e.id;this.id=l,this.logger=c,this.clock=u,this.parent=h,this.options=s,this.scheduler=new V({deferEvents:this.options.deferEvents}),this.sessionId=X()}return Object.defineProperty(a.prototype,"initialState",{get:function(){var t=this;return this._initialState?this._initialState:q(this,(function(){return t._initialState=t.machine.initialState,t._initialState}))},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"state",{get:function(){return this._state},enumerable:!1,configurable:!0}),a.prototype.execute=function(t,e){var n,r;try{for(var o=i(t.actions),s=o.next();!s.done;s=o.next()){var a=s.value;this.exec(a,t,e)}}catch(t){n={error:t}}finally{try{s&&!s.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}},a.prototype.update=function(t,e){var n,r,o,s,a,u,c,h,l=this;if(t._sessionid=this.sessionId,this._state=t,this.options.execute&&this.execute(this.state),this.children.forEach((function(t){l.state.children[t.id]=t})),this.devTools&&this.devTools.send(e.data,t),t.event)try{for(var d=i(this.eventListeners),p=d.next();!p.done;p=d.next()){(0,p.value)(t.event)}}catch(t){n={error:t}}finally{try{p&&!p.done&&(r=d.return)&&r.call(d)}finally{if(n)throw n.error}}try{for(var v=i(this.listeners),y=v.next();!y.done;y=v.next()){(0,y.value)(t,t.event)}}catch(t){o={error:t}}finally{try{y&&!y.done&&(s=v.return)&&s.call(v)}finally{if(o)throw o.error}}try{for(var g=i(this.contextListeners),b=g.next();!b.done;b=g.next()){(0,b.value)(this.state.context,this.state.history?this.state.history.context:void 0)}}catch(t){a={error:t}}finally{try{b&&!b.done&&(u=g.return)&&u.call(g)}finally{if(a)throw a.error}}var m=_(t.configuration||[],this.machine);if(this.state.configuration&&m){var x=t.configuration.find((function(t){return"final"===t.type&&t.parent===l.machine})),w=x&&x.doneData?f(x.doneData,t.context,e):void 0;try{for(var S=i(this.doneListeners),E=S.next();!E.done;E=S.next()){(0,E.value)(D(this.id,w))}}catch(t){c={error:t}}finally{try{E&&!E.done&&(h=S.return)&&h.call(S)}finally{if(c)throw c.error}}this.stop()}},a.prototype.onTransition=function(e){return this.listeners.add(e),this.status===t.InterpreterStatus.Running&&e(this.state,this.state.event),this},a.prototype.subscribe=function(e,n,r){var i,o=this;if(!e)return{unsubscribe:function(){}};var s=r;return"function"==typeof e?i=e:(i=e.next.bind(e),s=e.complete.bind(e)),this.listeners.add(i),this.status!==t.InterpreterStatus.NotStarted&&i(this.state),s&&(this.status===t.InterpreterStatus.Stopped?s():this.onDone(s)),{unsubscribe:function(){i&&o.listeners.delete(i),s&&o.doneListeners.delete(s)}}},a.prototype.onEvent=function(t){return this.eventListeners.add(t),this},a.prototype.onSend=function(t){return this.sendListeners.add(t),this},a.prototype.onChange=function(t){return this.contextListeners.add(t),this},a.prototype.onStop=function(t){return this.stopListeners.add(t),this},a.prototype.onDone=function(t){return this.doneListeners.add(t),this},a.prototype.off=function(t){return this.listeners.delete(t),this.eventListeners.delete(t),this.sendListeners.delete(t),this.stopListeners.delete(t),this.doneListeners.delete(t),this.contextListeners.delete(t),this},a.prototype.start=function(e){var n=this;if(this.status===t.InterpreterStatus.Running)return this;this.machine._init(),B(this.sessionId,this),this.initialized=!0,this.status=t.InterpreterStatus.Running;var r=void 0===e?this.initialState:q(this,(function(){return"object"==typeof(t=e)&&null!==t&&"value"in t&&"_event"in t?n.machine.resolveState(e):n.machine.resolveState(z.from(e,n.machine.context));var t}));return this.options.devTools&&this.attachDev(),this.scheduler.initialize((function(){n.update(r,A)})),this},a.prototype.stop=function(){var e,n,r,a,u,c,h,f,l,d,v=this;try{for(var y=i(this.listeners),g=y.next();!g.done;g=y.next()){var b=g.value;this.listeners.delete(b)}}catch(t){e={error:t}}finally{try{g&&!g.done&&(n=y.return)&&n.call(y)}finally{if(e)throw e.error}}try{for(var m=i(this.stopListeners),x=m.next();!x.done;x=m.next()){(b=x.value)(),this.stopListeners.delete(b)}}catch(t){r={error:t}}finally{try{x&&!x.done&&(a=m.return)&&a.call(m)}finally{if(r)throw r.error}}try{for(var w=i(this.contextListeners),S=w.next();!S.done;S=w.next()){b=S.value;this.contextListeners.delete(b)}}catch(t){u={error:t}}finally{try{S&&!S.done&&(c=w.return)&&c.call(w)}finally{if(u)throw u.error}}try{for(var E=i(this.doneListeners),_=E.next();!_.done;_=E.next()){b=_.value;this.doneListeners.delete(b)}}catch(t){h={error:t}}finally{try{_&&!_.done&&(f=E.return)&&f.call(E)}finally{if(h)throw h.error}}if(!this.initialized)return this;s([],o(this.state.configuration),!1).sort((function(t,e){return e.order-t.order})).forEach((function(t){var e,n;try{for(var r=i(t.definition.exit),o=r.next();!o.done;o=r.next()){var s=o.value;v.exec(s,v.state)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}})),this.children.forEach((function(t){p(t.stop)&&t.stop()})),this.children.clear();try{for(var O=i(Object.keys(this.delayedEventsMap)),T=O.next();!T.done;T=O.next()){var I=T.value;this.clock.clearTimeout(this.delayedEventsMap[I])}}catch(t){l={error:t}}finally{try{T&&!T.done&&(d=O.return)&&d.call(O)}finally{if(l)throw l.error}}return this.scheduler.clear(),this.scheduler=new V({deferEvents:this.options.deferEvents}),this.initialized=!1,this.status=t.InterpreterStatus.Stopped,this._initialState=void 0,H(this.sessionId),this},a.prototype.batch=function(e){var n=this;if(this.status===t.InterpreterStatus.NotStarted&&this.options.deferEvents);else if(this.status!==t.InterpreterStatus.Running)throw new Error("".concat(e.length,' event(s) were sent to uninitialized service "').concat(this.machine.id,'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.'));this.scheduler.schedule((function(){var t,a,u=n.state,c=!1,h=[],f=function(t){var e=x(t);n.forward(e),u=q(n,(function(){return n.machine.transition(u,e)})),h.push.apply(h,s([],o(u.actions.map((function(t){return n=u,i=(e=t).exec,r(r({},e),{exec:void 0!==i?function(){return i(n.context,n.event,{action:e,state:n,_event:n._event})}:void 0});var e,n,i}))),!1)),c=c||!!u.changed};try{for(var l=i(e),d=l.next();!d.done;d=l.next()){f(d.value)}}catch(e){t={error:e}}finally{try{d&&!d.done&&(a=l.return)&&a.call(l)}finally{if(t)throw t.error}}u.changed=c,u.actions=h,n.update(u,x(e[e.length-1]))}))},a.prototype.sender=function(t){return this.send.bind(this,t)},a.prototype.nextState=function(t){var e=this,n=x(t);if(0===n.name.indexOf(C)&&!this.state.nextEvents.some((function(t){return 0===t.indexOf(C)})))throw n.data.data;return q(this,(function(){return e.machine.transition(e.state,n)}))},a.prototype.forward=function(t){var e,n;try{for(var r=i(this.forwardTo),o=r.next();!o.done;o=r.next()){var s=o.value,a=this.children.get(s);if(!a)throw new Error("Unable to forward event '".concat(t,"' from interpreter '").concat(this.id,"' to nonexistant child '").concat(s,"'."));a.send(t)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}},a.prototype.defer=function(t){var e=this;this.delayedEventsMap[t.id]=this.clock.setTimeout((function(){t.to?e.sendTo(t._event,t.to):e.send(t._event)}),t.delay)},a.prototype.cancel=function(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]},a.prototype.exec=function(n,r,i){void 0===i&&(i=this.machine.options.actions);var o,s=r.context,a=r._event,u=n.exec||function(t,e){return e&&e[t]||void 0}(n.type,i),c=p(u)?u:u?u.exec:n.exec;if(c)try{return c(s,a.data,{action:n,state:this.state,_event:a})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(n.type){case I:var h=n;if("number"==typeof h.delay)return void this.defer(h);h.to?this.sendTo(h._event,h.to):this.send(h._event);break;case L:this.cancel(n.sendId);break;case O:if(this.status!==t.InterpreterStatus.Running)return;var l=n.activity;if(!this.state.activities[l.id||l.type])break;if(l.type===e.Invoke){var d="string"==typeof(o=l.src)?{type:o}:o,v=this.machine.options.services?this.machine.options.services[d.type]:void 0,y=l.id,b=l.data,m="autoForward"in l?l.autoForward:!!l.forward;if(!v)return;var x=b?f(b,s,a):void 0;if("string"==typeof v)return;var w=p(v)?v(s,a.data,{data:x,src:d,meta:l.meta}):v;if(!w)return;var S=void 0;g(w)&&(w=x?w.withContext(x):w,S={autoForward:m}),this.spawn(w,y,S)}else this.spawnActivity(l);break;case T:this.stopChild(n.activity.id);break;case k:var E=n.label,_=n.value;E?this.logger(E,_):this.logger(_)}},a.prototype.removeChild=function(t){var e;this.children.delete(t),this.forwardTo.delete(t),null===(e=this.state)||void 0===e||delete e.children[t]},a.prototype.stopChild=function(t){var e=this.children.get(t);e&&(this.removeChild(t),p(e.stop)&&e.stop())},a.prototype.spawn=function(t,e,n){if(l(t))return this.spawnPromise(Promise.resolve(t),e);if(p(t))return this.spawnCallback(t,e);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(o=t)&&"id"in o)return this.spawnActor(t,e);if(function(t){try{return"subscribe"in t&&p(t.subscribe)}catch(t){return!1}}(t))return this.spawnObservable(t,e);if(g(t))return this.spawnMachine(t,r(r({},n),{id:e}));if(null!==(i=t)&&"object"==typeof i&&"transition"in i&&"function"==typeof i.transition)return this.spawnBehavior(t,e);throw new Error('Unable to spawn entity "'.concat(e,'" of type "').concat(typeof t,'".'));var i,o},a.prototype.spawnMachine=function(t,e){var n=this;void 0===e&&(e={});var i=new a(t,r(r({},this.options),{parent:this,id:e.id||t.id})),o=r(r({},Z),e);o.sync&&i.onTransition((function(t){n.send(N,{state:t,id:i.id})}));var s=i;return this.children.set(i.id,s),o.autoForward&&this.forwardTo.add(i.id),i.onDone((function(t){n.removeChild(i.id),n.send(x(t,{origin:i.id}))})).start(),s},a.prototype.spawnBehavior=function(t,e){var n=W(t,{id:e,parent:this});return this.children.set(e,n),n},a.prototype.spawnPromise=function(t,e){var n,r,i=this,o=!1;t.then((function(t){o||(r=t,i.removeChild(e),i.send(x(D(e,t),{origin:e})))}),(function(t){if(!o){i.removeChild(e);var n=M(e,t);try{i.send(x(n,{origin:e}))}catch(t){i.devTools&&i.devTools.send(n,i.state),i.machine.strict&&i.stop()}}}));var s=((n={id:e,send:function(){},subscribe:function(e,n,r){var i=w(e,n,r),o=!1;return t.then((function(t){o||(i.next(t),o||i.complete())}),(function(t){o||i.error(t)})),{unsubscribe:function(){return o=!0}}},stop:function(){o=!0},toJSON:function(){return{id:e}},getSnapshot:function(){return r}})[y]=function(){return this},n);return this.children.set(e,s),s},a.prototype.spawnCallback=function(t,e){var n,r,i,o=this,s=!1,a=new Set,u=new Set;try{i=t((function(t){r=t,u.forEach((function(e){return e(t)})),s||o.send(x(t,{origin:e}))}),(function(t){a.add(t)}))}catch(t){this.send(M(e,t))}if(l(i))return this.spawnPromise(i,e);var c=((n={id:e,send:function(t){return a.forEach((function(e){return e(t)}))},subscribe:function(t){var e=w(t);return u.add(e.next),{unsubscribe:function(){u.delete(e.next)}}},stop:function(){s=!0,p(i)&&i()},toJSON:function(){return{id:e}},getSnapshot:function(){return r}})[y]=function(){return this},n);return this.children.set(e,c),c},a.prototype.spawnObservable=function(t,e){var n,r,i=this,o=t.subscribe((function(t){r=t,i.send(x(t,{origin:e}))}),(function(t){i.removeChild(e),i.send(x(M(e,t),{origin:e}))}),(function(){i.removeChild(e),i.send(x(D(e),{origin:e}))})),s=((n={id:e,send:function(){},subscribe:function(e,n,r){return t.subscribe(e,n,r)},stop:function(){return o.unsubscribe()},getSnapshot:function(){return r},toJSON:function(){return{id:e}}})[y]=function(){return this},n);return this.children.set(e,s),s},a.prototype.spawnActor=function(t,e){return this.children.set(e,t),t},a.prototype.spawnActivity=function(t){var e=this.machine.options&&this.machine.options.activities?this.machine.options.activities[t.type]:void 0;if(e){var n=e(this.state.context,t);this.spawnEffect(t.id,n)}},a.prototype.spawnEffect=function(t,e){var n;this.children.set(t,((n={id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},stop:e||void 0,getSnapshot:function(){},toJSON:function(){return{id:t}}})[y]=function(){return this},n))},a.prototype.attachDev=function(){var t=K();if(this.options.devTools&&t){if(t.__REDUX_DEVTOOLS_EXTENSION__){var e="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=t.__REDUX_DEVTOOLS_EXTENSION__.connect(r(r({name:this.id,autoPause:!0,stateSanitizer:function(t){return{value:t.value,context:t.context,actions:t.actions}}},e),{features:r({jump:!1,skip:!1},e?e.features:void 0)}),this.machine),this.devTools.init(this.state)}Q(this)}},a.prototype.toJSON=function(){return{id:this.id}},a.prototype[y]=function(){return this},a.prototype.getSnapshot=function(){return this.status===t.InterpreterStatus.NotStarted?this.initialState:this._state},a.defaultOptions={execute:!0,deferEvents:!0,clock:{setTimeout:function(t,e){return setTimeout(t,e)},clearTimeout:function(t){return clearTimeout(t)}},logger:console.log.bind(console),devTools:!1},a.interpret=et,a}();function et(t,e){return new tt(t,e)}t.Interpreter=tt,t.interpret=et,t.spawn=function(t,e){var n=function(t){return v(t)?r(r({},Z),{name:t}):r(r(r({},Z),{name:b()}),t)}(e);return function(e){return e?e.spawn(t,n.name,n):U(t,n.name)}(J[J.length-1])},Object.defineProperty(t,"__esModule",{value:!0})}));
|