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/utils.js
DELETED
|
@@ -1,673 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var _tslib = require('./_virtual/_tslib.js');
|
|
6
|
-
var constants = require('./constants.js');
|
|
7
|
-
var environment = require('./environment.js');
|
|
8
|
-
|
|
9
|
-
var _a;
|
|
10
|
-
function keys(value) {
|
|
11
|
-
return Object.keys(value);
|
|
12
|
-
}
|
|
13
|
-
function matchesState(parentStateId, childStateId, delimiter) {
|
|
14
|
-
if (delimiter === void 0) {
|
|
15
|
-
delimiter = constants.STATE_DELIMITER;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
var parentStateValue = toStateValue(parentStateId, delimiter);
|
|
19
|
-
var childStateValue = toStateValue(childStateId, delimiter);
|
|
20
|
-
|
|
21
|
-
if (isString(childStateValue)) {
|
|
22
|
-
if (isString(parentStateValue)) {
|
|
23
|
-
return childStateValue === parentStateValue;
|
|
24
|
-
} // Parent more specific than child
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (isString(parentStateValue)) {
|
|
31
|
-
return parentStateValue in childStateValue;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return Object.keys(parentStateValue).every(function (key) {
|
|
35
|
-
if (!(key in childStateValue)) {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return matchesState(parentStateValue[key], childStateValue[key]);
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
function getEventType(event) {
|
|
43
|
-
try {
|
|
44
|
-
return isString(event) || typeof event === 'number' ? "".concat(event) : event.type;
|
|
45
|
-
} catch (e) {
|
|
46
|
-
throw new Error('Events must be strings or objects with a string event.type property.');
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
function getActionType(action) {
|
|
50
|
-
try {
|
|
51
|
-
return isString(action) || typeof action === 'number' ? "".concat(action) : isFunction(action) ? action.name : action.type;
|
|
52
|
-
} catch (e) {
|
|
53
|
-
throw new Error('Actions must be strings or objects with a string action.type property.');
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
function toStatePath(stateId, delimiter) {
|
|
57
|
-
try {
|
|
58
|
-
if (isArray(stateId)) {
|
|
59
|
-
return stateId;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return stateId.toString().split(delimiter);
|
|
63
|
-
} catch (e) {
|
|
64
|
-
throw new Error("'".concat(stateId, "' is not a valid state path."));
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
function isStateLike(state) {
|
|
68
|
-
return typeof state === 'object' && 'value' in state && 'context' in state && 'event' in state && '_event' in state;
|
|
69
|
-
}
|
|
70
|
-
function toStateValue(stateValue, delimiter) {
|
|
71
|
-
if (isStateLike(stateValue)) {
|
|
72
|
-
return stateValue.value;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (isArray(stateValue)) {
|
|
76
|
-
return pathToStateValue(stateValue);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (typeof stateValue !== 'string') {
|
|
80
|
-
return stateValue;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
var statePath = toStatePath(stateValue, delimiter);
|
|
84
|
-
return pathToStateValue(statePath);
|
|
85
|
-
}
|
|
86
|
-
function pathToStateValue(statePath) {
|
|
87
|
-
if (statePath.length === 1) {
|
|
88
|
-
return statePath[0];
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
var value = {};
|
|
92
|
-
var marker = value;
|
|
93
|
-
|
|
94
|
-
for (var i = 0; i < statePath.length - 1; i++) {
|
|
95
|
-
if (i === statePath.length - 2) {
|
|
96
|
-
marker[statePath[i]] = statePath[i + 1];
|
|
97
|
-
} else {
|
|
98
|
-
marker[statePath[i]] = {};
|
|
99
|
-
marker = marker[statePath[i]];
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return value;
|
|
104
|
-
}
|
|
105
|
-
function mapValues(collection, iteratee) {
|
|
106
|
-
var result = {};
|
|
107
|
-
var collectionKeys = Object.keys(collection);
|
|
108
|
-
|
|
109
|
-
for (var i = 0; i < collectionKeys.length; i++) {
|
|
110
|
-
var key = collectionKeys[i];
|
|
111
|
-
result[key] = iteratee(collection[key], key, collection, i);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return result;
|
|
115
|
-
}
|
|
116
|
-
function mapFilterValues(collection, iteratee, predicate) {
|
|
117
|
-
var e_1, _a;
|
|
118
|
-
|
|
119
|
-
var result = {};
|
|
120
|
-
|
|
121
|
-
try {
|
|
122
|
-
for (var _b = _tslib.__values(Object.keys(collection)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
123
|
-
var key = _c.value;
|
|
124
|
-
var item = collection[key];
|
|
125
|
-
|
|
126
|
-
if (!predicate(item)) {
|
|
127
|
-
continue;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
result[key] = iteratee(item, key, collection);
|
|
131
|
-
}
|
|
132
|
-
} catch (e_1_1) {
|
|
133
|
-
e_1 = {
|
|
134
|
-
error: e_1_1
|
|
135
|
-
};
|
|
136
|
-
} finally {
|
|
137
|
-
try {
|
|
138
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
139
|
-
} finally {
|
|
140
|
-
if (e_1) throw e_1.error;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return result;
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Retrieves a value at the given path.
|
|
148
|
-
* @param props The deep path to the prop of the desired value
|
|
149
|
-
*/
|
|
150
|
-
|
|
151
|
-
var path = function (props) {
|
|
152
|
-
return function (object) {
|
|
153
|
-
var e_2, _a;
|
|
154
|
-
|
|
155
|
-
var result = object;
|
|
156
|
-
|
|
157
|
-
try {
|
|
158
|
-
for (var props_1 = _tslib.__values(props), props_1_1 = props_1.next(); !props_1_1.done; props_1_1 = props_1.next()) {
|
|
159
|
-
var prop = props_1_1.value;
|
|
160
|
-
result = result[prop];
|
|
161
|
-
}
|
|
162
|
-
} catch (e_2_1) {
|
|
163
|
-
e_2 = {
|
|
164
|
-
error: e_2_1
|
|
165
|
-
};
|
|
166
|
-
} finally {
|
|
167
|
-
try {
|
|
168
|
-
if (props_1_1 && !props_1_1.done && (_a = props_1.return)) _a.call(props_1);
|
|
169
|
-
} finally {
|
|
170
|
-
if (e_2) throw e_2.error;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
return result;
|
|
175
|
-
};
|
|
176
|
-
};
|
|
177
|
-
/**
|
|
178
|
-
* Retrieves a value at the given path via the nested accessor prop.
|
|
179
|
-
* @param props The deep path to the prop of the desired value
|
|
180
|
-
*/
|
|
181
|
-
|
|
182
|
-
function nestedPath(props, accessorProp) {
|
|
183
|
-
return function (object) {
|
|
184
|
-
var e_3, _a;
|
|
185
|
-
|
|
186
|
-
var result = object;
|
|
187
|
-
|
|
188
|
-
try {
|
|
189
|
-
for (var props_2 = _tslib.__values(props), props_2_1 = props_2.next(); !props_2_1.done; props_2_1 = props_2.next()) {
|
|
190
|
-
var prop = props_2_1.value;
|
|
191
|
-
result = result[accessorProp][prop];
|
|
192
|
-
}
|
|
193
|
-
} catch (e_3_1) {
|
|
194
|
-
e_3 = {
|
|
195
|
-
error: e_3_1
|
|
196
|
-
};
|
|
197
|
-
} finally {
|
|
198
|
-
try {
|
|
199
|
-
if (props_2_1 && !props_2_1.done && (_a = props_2.return)) _a.call(props_2);
|
|
200
|
-
} finally {
|
|
201
|
-
if (e_3) throw e_3.error;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
return result;
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
function toStatePaths(stateValue) {
|
|
209
|
-
if (!stateValue) {
|
|
210
|
-
return [[]];
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
if (isString(stateValue)) {
|
|
214
|
-
return [[stateValue]];
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
var result = flatten(Object.keys(stateValue).map(function (key) {
|
|
218
|
-
var subStateValue = stateValue[key];
|
|
219
|
-
|
|
220
|
-
if (typeof subStateValue !== 'string' && (!subStateValue || !Object.keys(subStateValue).length)) {
|
|
221
|
-
return [[key]];
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
return toStatePaths(stateValue[key]).map(function (subPath) {
|
|
225
|
-
return [key].concat(subPath);
|
|
226
|
-
});
|
|
227
|
-
}));
|
|
228
|
-
return result;
|
|
229
|
-
}
|
|
230
|
-
function pathsToStateValue(paths) {
|
|
231
|
-
var e_4, _a;
|
|
232
|
-
|
|
233
|
-
var result = {};
|
|
234
|
-
|
|
235
|
-
if (paths && paths.length === 1 && paths[0].length === 1) {
|
|
236
|
-
return paths[0][0];
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
try {
|
|
240
|
-
for (var paths_1 = _tslib.__values(paths), paths_1_1 = paths_1.next(); !paths_1_1.done; paths_1_1 = paths_1.next()) {
|
|
241
|
-
var currentPath = paths_1_1.value;
|
|
242
|
-
var marker = result; // tslint:disable-next-line:prefer-for-of
|
|
243
|
-
|
|
244
|
-
for (var i = 0; i < currentPath.length; i++) {
|
|
245
|
-
var subPath = currentPath[i];
|
|
246
|
-
|
|
247
|
-
if (i === currentPath.length - 2) {
|
|
248
|
-
marker[subPath] = currentPath[i + 1];
|
|
249
|
-
break;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
marker[subPath] = marker[subPath] || {};
|
|
253
|
-
marker = marker[subPath];
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
} catch (e_4_1) {
|
|
257
|
-
e_4 = {
|
|
258
|
-
error: e_4_1
|
|
259
|
-
};
|
|
260
|
-
} finally {
|
|
261
|
-
try {
|
|
262
|
-
if (paths_1_1 && !paths_1_1.done && (_a = paths_1.return)) _a.call(paths_1);
|
|
263
|
-
} finally {
|
|
264
|
-
if (e_4) throw e_4.error;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
return result;
|
|
269
|
-
}
|
|
270
|
-
function flatten(array) {
|
|
271
|
-
var _a;
|
|
272
|
-
|
|
273
|
-
return (_a = []).concat.apply(_a, _tslib.__spreadArray([], _tslib.__read(array), false));
|
|
274
|
-
}
|
|
275
|
-
function toArrayStrict(value) {
|
|
276
|
-
if (isArray(value)) {
|
|
277
|
-
return value;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
return [value];
|
|
281
|
-
}
|
|
282
|
-
function toArray(value) {
|
|
283
|
-
if (value === undefined) {
|
|
284
|
-
return [];
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
return toArrayStrict(value);
|
|
288
|
-
}
|
|
289
|
-
function mapContext(mapper, context, _event) {
|
|
290
|
-
var e_5, _a;
|
|
291
|
-
|
|
292
|
-
if (isFunction(mapper)) {
|
|
293
|
-
return mapper(context, _event.data);
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
var result = {};
|
|
297
|
-
|
|
298
|
-
try {
|
|
299
|
-
for (var _b = _tslib.__values(Object.keys(mapper)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
300
|
-
var key = _c.value;
|
|
301
|
-
var subMapper = mapper[key];
|
|
302
|
-
|
|
303
|
-
if (isFunction(subMapper)) {
|
|
304
|
-
result[key] = subMapper(context, _event.data);
|
|
305
|
-
} else {
|
|
306
|
-
result[key] = subMapper;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
} catch (e_5_1) {
|
|
310
|
-
e_5 = {
|
|
311
|
-
error: e_5_1
|
|
312
|
-
};
|
|
313
|
-
} finally {
|
|
314
|
-
try {
|
|
315
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
316
|
-
} finally {
|
|
317
|
-
if (e_5) throw e_5.error;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
return result;
|
|
322
|
-
}
|
|
323
|
-
function isBuiltInEvent(eventType) {
|
|
324
|
-
return /^(done|error)\./.test(eventType);
|
|
325
|
-
}
|
|
326
|
-
function isPromiseLike(value) {
|
|
327
|
-
if (value instanceof Promise) {
|
|
328
|
-
return true;
|
|
329
|
-
} // Check if shape matches the Promise/A+ specification for a "thenable".
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
if (value !== null && (isFunction(value) || typeof value === 'object') && isFunction(value.then)) {
|
|
333
|
-
return true;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
return false;
|
|
337
|
-
}
|
|
338
|
-
function isBehavior(value) {
|
|
339
|
-
return value !== null && typeof value === 'object' && 'transition' in value && typeof value.transition === 'function';
|
|
340
|
-
}
|
|
341
|
-
function partition(items, predicate) {
|
|
342
|
-
var e_6, _a;
|
|
343
|
-
|
|
344
|
-
var _b = _tslib.__read([[], []], 2),
|
|
345
|
-
truthy = _b[0],
|
|
346
|
-
falsy = _b[1];
|
|
347
|
-
|
|
348
|
-
try {
|
|
349
|
-
for (var items_1 = _tslib.__values(items), items_1_1 = items_1.next(); !items_1_1.done; items_1_1 = items_1.next()) {
|
|
350
|
-
var item = items_1_1.value;
|
|
351
|
-
|
|
352
|
-
if (predicate(item)) {
|
|
353
|
-
truthy.push(item);
|
|
354
|
-
} else {
|
|
355
|
-
falsy.push(item);
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
} catch (e_6_1) {
|
|
359
|
-
e_6 = {
|
|
360
|
-
error: e_6_1
|
|
361
|
-
};
|
|
362
|
-
} finally {
|
|
363
|
-
try {
|
|
364
|
-
if (items_1_1 && !items_1_1.done && (_a = items_1.return)) _a.call(items_1);
|
|
365
|
-
} finally {
|
|
366
|
-
if (e_6) throw e_6.error;
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
return [truthy, falsy];
|
|
371
|
-
}
|
|
372
|
-
function updateHistoryStates(hist, stateValue) {
|
|
373
|
-
return mapValues(hist.states, function (subHist, key) {
|
|
374
|
-
if (!subHist) {
|
|
375
|
-
return undefined;
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
var subStateValue = (isString(stateValue) ? undefined : stateValue[key]) || (subHist ? subHist.current : undefined);
|
|
379
|
-
|
|
380
|
-
if (!subStateValue) {
|
|
381
|
-
return undefined;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
return {
|
|
385
|
-
current: subStateValue,
|
|
386
|
-
states: updateHistoryStates(subHist, subStateValue)
|
|
387
|
-
};
|
|
388
|
-
});
|
|
389
|
-
}
|
|
390
|
-
function updateHistoryValue(hist, stateValue) {
|
|
391
|
-
return {
|
|
392
|
-
current: stateValue,
|
|
393
|
-
states: updateHistoryStates(hist, stateValue)
|
|
394
|
-
};
|
|
395
|
-
}
|
|
396
|
-
function updateContext(context, _event, assignActions, state) {
|
|
397
|
-
if (!environment.IS_PRODUCTION) {
|
|
398
|
-
exports.warn(!!context, 'Attempting to update undefined context');
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
var updatedContext = context ? assignActions.reduce(function (acc, assignAction) {
|
|
402
|
-
var e_7, _a;
|
|
403
|
-
|
|
404
|
-
var assignment = assignAction.assignment;
|
|
405
|
-
var meta = {
|
|
406
|
-
state: state,
|
|
407
|
-
action: assignAction,
|
|
408
|
-
_event: _event
|
|
409
|
-
};
|
|
410
|
-
var partialUpdate = {};
|
|
411
|
-
|
|
412
|
-
if (isFunction(assignment)) {
|
|
413
|
-
partialUpdate = assignment(acc, _event.data, meta);
|
|
414
|
-
} else {
|
|
415
|
-
try {
|
|
416
|
-
for (var _b = _tslib.__values(Object.keys(assignment)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
417
|
-
var key = _c.value;
|
|
418
|
-
var propAssignment = assignment[key];
|
|
419
|
-
partialUpdate[key] = isFunction(propAssignment) ? propAssignment(acc, _event.data, meta) : propAssignment;
|
|
420
|
-
}
|
|
421
|
-
} catch (e_7_1) {
|
|
422
|
-
e_7 = {
|
|
423
|
-
error: e_7_1
|
|
424
|
-
};
|
|
425
|
-
} finally {
|
|
426
|
-
try {
|
|
427
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
428
|
-
} finally {
|
|
429
|
-
if (e_7) throw e_7.error;
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
return Object.assign({}, acc, partialUpdate);
|
|
435
|
-
}, context) : context;
|
|
436
|
-
return updatedContext;
|
|
437
|
-
} // tslint:disable-next-line:no-empty
|
|
438
|
-
|
|
439
|
-
exports.warn = function () {};
|
|
440
|
-
|
|
441
|
-
if (!environment.IS_PRODUCTION) {
|
|
442
|
-
exports.warn = function (condition, message) {
|
|
443
|
-
var error = condition instanceof Error ? condition : undefined;
|
|
444
|
-
|
|
445
|
-
if (!error && condition) {
|
|
446
|
-
return;
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
if (console !== undefined) {
|
|
450
|
-
var args = ["Warning: ".concat(message)];
|
|
451
|
-
|
|
452
|
-
if (error) {
|
|
453
|
-
args.push(error);
|
|
454
|
-
} // tslint:disable-next-line:no-console
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
console.warn.apply(console, args);
|
|
458
|
-
}
|
|
459
|
-
};
|
|
460
|
-
}
|
|
461
|
-
function isArray(value) {
|
|
462
|
-
return Array.isArray(value);
|
|
463
|
-
} // tslint:disable-next-line:ban-types
|
|
464
|
-
|
|
465
|
-
function isFunction(value) {
|
|
466
|
-
return typeof value === 'function';
|
|
467
|
-
}
|
|
468
|
-
function isString(value) {
|
|
469
|
-
return typeof value === 'string';
|
|
470
|
-
}
|
|
471
|
-
function toGuard(condition, guardMap) {
|
|
472
|
-
if (!condition) {
|
|
473
|
-
return undefined;
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
if (isString(condition)) {
|
|
477
|
-
return {
|
|
478
|
-
type: constants.DEFAULT_GUARD_TYPE,
|
|
479
|
-
name: condition,
|
|
480
|
-
predicate: guardMap ? guardMap[condition] : undefined
|
|
481
|
-
};
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
if (isFunction(condition)) {
|
|
485
|
-
return {
|
|
486
|
-
type: constants.DEFAULT_GUARD_TYPE,
|
|
487
|
-
name: condition.name,
|
|
488
|
-
predicate: condition
|
|
489
|
-
};
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
return condition;
|
|
493
|
-
}
|
|
494
|
-
function isObservable(value) {
|
|
495
|
-
try {
|
|
496
|
-
return 'subscribe' in value && isFunction(value.subscribe);
|
|
497
|
-
} catch (e) {
|
|
498
|
-
return false;
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
var symbolObservable = /*#__PURE__*/function () {
|
|
502
|
-
return typeof Symbol === 'function' && Symbol.observable || '@@observable';
|
|
503
|
-
}(); // TODO: to be removed in v5, left it out just to minimize the scope of the change and maintain compatibility with older versions of integration paackages
|
|
504
|
-
|
|
505
|
-
var interopSymbols = (_a = {}, _a[symbolObservable] = function () {
|
|
506
|
-
return this;
|
|
507
|
-
}, _a[Symbol.observable] = function () {
|
|
508
|
-
return this;
|
|
509
|
-
}, _a);
|
|
510
|
-
function isMachine(value) {
|
|
511
|
-
return !!value && '__xstatenode' in value;
|
|
512
|
-
}
|
|
513
|
-
function isActor(value) {
|
|
514
|
-
return !!value && typeof value.send === 'function';
|
|
515
|
-
}
|
|
516
|
-
var uniqueId = /*#__PURE__*/function () {
|
|
517
|
-
var currentId = 0;
|
|
518
|
-
return function () {
|
|
519
|
-
currentId++;
|
|
520
|
-
return currentId.toString(16);
|
|
521
|
-
};
|
|
522
|
-
}();
|
|
523
|
-
function toEventObject(event, payload // id?: TEvent['type']
|
|
524
|
-
) {
|
|
525
|
-
if (isString(event) || typeof event === 'number') {
|
|
526
|
-
return _tslib.__assign({
|
|
527
|
-
type: event
|
|
528
|
-
}, payload);
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
return event;
|
|
532
|
-
}
|
|
533
|
-
function toSCXMLEvent(event, scxmlEvent) {
|
|
534
|
-
if (!isString(event) && '$$type' in event && event.$$type === 'scxml') {
|
|
535
|
-
return event;
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
var eventObject = toEventObject(event);
|
|
539
|
-
return _tslib.__assign({
|
|
540
|
-
name: eventObject.type,
|
|
541
|
-
data: eventObject,
|
|
542
|
-
$$type: 'scxml',
|
|
543
|
-
type: 'external'
|
|
544
|
-
}, scxmlEvent);
|
|
545
|
-
}
|
|
546
|
-
function toTransitionConfigArray(event, configLike) {
|
|
547
|
-
var transitions = toArrayStrict(configLike).map(function (transitionLike) {
|
|
548
|
-
if (typeof transitionLike === 'undefined' || typeof transitionLike === 'string' || isMachine(transitionLike)) {
|
|
549
|
-
return {
|
|
550
|
-
target: transitionLike,
|
|
551
|
-
event: event
|
|
552
|
-
};
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
return _tslib.__assign(_tslib.__assign({}, transitionLike), {
|
|
556
|
-
event: event
|
|
557
|
-
});
|
|
558
|
-
});
|
|
559
|
-
return transitions;
|
|
560
|
-
}
|
|
561
|
-
function normalizeTarget(target) {
|
|
562
|
-
if (target === undefined || target === constants.TARGETLESS_KEY) {
|
|
563
|
-
return undefined;
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
return toArray(target);
|
|
567
|
-
}
|
|
568
|
-
function reportUnhandledExceptionOnInvocation(originalError, currentError, id) {
|
|
569
|
-
if (!environment.IS_PRODUCTION) {
|
|
570
|
-
var originalStackTrace = originalError.stack ? " Stacktrace was '".concat(originalError.stack, "'") : '';
|
|
571
|
-
|
|
572
|
-
if (originalError === currentError) {
|
|
573
|
-
// tslint:disable-next-line:no-console
|
|
574
|
-
console.error("Missing onError handler for invocation '".concat(id, "', error was '").concat(originalError, "'.").concat(originalStackTrace));
|
|
575
|
-
} else {
|
|
576
|
-
var stackTrace = currentError.stack ? " Stacktrace was '".concat(currentError.stack, "'") : ''; // tslint:disable-next-line:no-console
|
|
577
|
-
|
|
578
|
-
console.error("Missing onError handler and/or unhandled exception/promise rejection for invocation '".concat(id, "'. ") + "Original error: '".concat(originalError, "'. ").concat(originalStackTrace, " Current error is '").concat(currentError, "'.").concat(stackTrace));
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
function evaluateGuard(machine, guard, context, _event, state) {
|
|
583
|
-
var guards = machine.options.guards;
|
|
584
|
-
var guardMeta = {
|
|
585
|
-
state: state,
|
|
586
|
-
cond: guard,
|
|
587
|
-
_event: _event
|
|
588
|
-
}; // TODO: do not hardcode!
|
|
589
|
-
|
|
590
|
-
if (guard.type === constants.DEFAULT_GUARD_TYPE) {
|
|
591
|
-
return ((guards === null || guards === void 0 ? void 0 : guards[guard.name]) || guard.predicate)(context, _event.data, guardMeta);
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
var condFn = guards === null || guards === void 0 ? void 0 : guards[guard.type];
|
|
595
|
-
|
|
596
|
-
if (!condFn) {
|
|
597
|
-
throw new Error("Guard '".concat(guard.type, "' is not implemented on machine '").concat(machine.id, "'."));
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
return condFn(context, _event.data, guardMeta);
|
|
601
|
-
}
|
|
602
|
-
function toInvokeSource(src) {
|
|
603
|
-
if (typeof src === 'string') {
|
|
604
|
-
return {
|
|
605
|
-
type: src
|
|
606
|
-
};
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
return src;
|
|
610
|
-
}
|
|
611
|
-
function toObserver(nextHandler, errorHandler, completionHandler) {
|
|
612
|
-
if (typeof nextHandler === 'object') {
|
|
613
|
-
return nextHandler;
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
var noop = function () {
|
|
617
|
-
return void 0;
|
|
618
|
-
};
|
|
619
|
-
|
|
620
|
-
return {
|
|
621
|
-
next: nextHandler,
|
|
622
|
-
error: errorHandler || noop,
|
|
623
|
-
complete: completionHandler || noop
|
|
624
|
-
};
|
|
625
|
-
}
|
|
626
|
-
function createInvokeId(stateNodeId, index) {
|
|
627
|
-
return "".concat(stateNodeId, ":invocation[").concat(index, "]");
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
exports.createInvokeId = createInvokeId;
|
|
631
|
-
exports.evaluateGuard = evaluateGuard;
|
|
632
|
-
exports.flatten = flatten;
|
|
633
|
-
exports.getActionType = getActionType;
|
|
634
|
-
exports.getEventType = getEventType;
|
|
635
|
-
exports.interopSymbols = interopSymbols;
|
|
636
|
-
exports.isActor = isActor;
|
|
637
|
-
exports.isArray = isArray;
|
|
638
|
-
exports.isBehavior = isBehavior;
|
|
639
|
-
exports.isBuiltInEvent = isBuiltInEvent;
|
|
640
|
-
exports.isFunction = isFunction;
|
|
641
|
-
exports.isMachine = isMachine;
|
|
642
|
-
exports.isObservable = isObservable;
|
|
643
|
-
exports.isPromiseLike = isPromiseLike;
|
|
644
|
-
exports.isStateLike = isStateLike;
|
|
645
|
-
exports.isString = isString;
|
|
646
|
-
exports.keys = keys;
|
|
647
|
-
exports.mapContext = mapContext;
|
|
648
|
-
exports.mapFilterValues = mapFilterValues;
|
|
649
|
-
exports.mapValues = mapValues;
|
|
650
|
-
exports.matchesState = matchesState;
|
|
651
|
-
exports.nestedPath = nestedPath;
|
|
652
|
-
exports.normalizeTarget = normalizeTarget;
|
|
653
|
-
exports.partition = partition;
|
|
654
|
-
exports.path = path;
|
|
655
|
-
exports.pathToStateValue = pathToStateValue;
|
|
656
|
-
exports.pathsToStateValue = pathsToStateValue;
|
|
657
|
-
exports.reportUnhandledExceptionOnInvocation = reportUnhandledExceptionOnInvocation;
|
|
658
|
-
exports.symbolObservable = symbolObservable;
|
|
659
|
-
exports.toArray = toArray;
|
|
660
|
-
exports.toArrayStrict = toArrayStrict;
|
|
661
|
-
exports.toEventObject = toEventObject;
|
|
662
|
-
exports.toGuard = toGuard;
|
|
663
|
-
exports.toInvokeSource = toInvokeSource;
|
|
664
|
-
exports.toObserver = toObserver;
|
|
665
|
-
exports.toSCXMLEvent = toSCXMLEvent;
|
|
666
|
-
exports.toStatePath = toStatePath;
|
|
667
|
-
exports.toStatePaths = toStatePaths;
|
|
668
|
-
exports.toStateValue = toStateValue;
|
|
669
|
-
exports.toTransitionConfigArray = toTransitionConfigArray;
|
|
670
|
-
exports.uniqueId = uniqueId;
|
|
671
|
-
exports.updateContext = updateContext;
|
|
672
|
-
exports.updateHistoryStates = updateHistoryStates;
|
|
673
|
-
exports.updateHistoryValue = updateHistoryValue;
|
package/lib/waitFor.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { ActorRef, EmittedFrom } from '.';
|
|
2
|
-
interface WaitForOptions {
|
|
3
|
-
/**
|
|
4
|
-
* How long to wait before rejecting, if no emitted
|
|
5
|
-
* state satisfies the predicate.
|
|
6
|
-
*
|
|
7
|
-
* @default 10_000 (10 seconds)
|
|
8
|
-
*/
|
|
9
|
-
timeout: number;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Subscribes to an actor ref and waits for its emitted value to satisfy
|
|
13
|
-
* a predicate, and then resolves with that value.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```js
|
|
17
|
-
* const state = await waitFor(someService, state => {
|
|
18
|
-
* return state.hasTag('loaded');
|
|
19
|
-
* });
|
|
20
|
-
*
|
|
21
|
-
* state.hasTag('loaded'); // true
|
|
22
|
-
* ```
|
|
23
|
-
*
|
|
24
|
-
* @param actorRef The actor ref to subscribe to
|
|
25
|
-
* @param predicate Determines if a value matches the condition to wait for
|
|
26
|
-
* @param options
|
|
27
|
-
* @returns A promise that eventually resolves to the emitted value
|
|
28
|
-
* that matches the condition
|
|
29
|
-
*/
|
|
30
|
-
export declare function waitFor<TActorRef extends ActorRef<any, any>>(actorRef: TActorRef, predicate: (emitted: EmittedFrom<TActorRef>) => boolean, options?: Partial<WaitForOptions>): Promise<EmittedFrom<TActorRef>>;
|
|
31
|
-
export {};
|
|
32
|
-
//# sourceMappingURL=waitFor.d.ts.map
|