xstate 4.22.0 → 4.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +58 -4
- package/dist/xstate.interpreter.js +1 -1
- package/dist/xstate.js +1 -1
- package/dist/xstate.web.js +2 -2
- package/es/Actor.js +1 -6
- package/es/Machine.d.ts +3 -3
- package/es/Machine.js +1 -2
- package/es/State.js +1 -3
- package/es/StateNode.js +3 -2
- package/es/_virtual/_tslib.js +59 -73
- package/es/actionTypes.js +3 -2
- package/es/actions.d.ts +1 -1
- package/es/actions.js +51 -37
- package/es/behaviors.js +4 -2
- package/es/constants.js +2 -1
- package/es/devTools.js +1 -1
- package/es/environment.js +2 -1
- package/es/index.js +3 -1
- package/es/interpreter.d.ts +8 -2
- package/es/interpreter.js +8 -6
- package/es/invokeUtils.js +4 -3
- package/es/mapState.js +1 -1
- package/es/match.js +1 -1
- package/es/model.d.ts +2 -37
- package/es/model.types.d.ts +37 -0
- package/es/registry.js +2 -1
- package/es/scheduler.js +2 -1
- package/es/schema.js +1 -1
- package/es/serviceScope.js +1 -3
- package/es/stateUtils.js +1 -9
- package/es/types.d.ts +12 -2
- package/es/types.js +1 -1
- package/es/utils.js +1 -41
- package/lib/Actor.d.ts +25 -25
- package/lib/Actor.js +85 -66
- package/lib/Machine.d.ts +17 -17
- package/lib/Machine.js +14 -8
- package/lib/SimulatedClock.d.ts +16 -16
- package/lib/State.d.ts +108 -108
- package/lib/State.js +246 -236
- package/lib/StateNode.d.ts +279 -279
- package/lib/StateNode.js +1535 -1357
- package/lib/_virtual/_tslib.js +81 -0
- package/lib/actionTypes.d.ts +19 -19
- package/lib/actionTypes.js +43 -23
- package/lib/actions.d.ts +138 -138
- package/lib/actions.js +465 -387
- package/lib/behaviors.d.ts +36 -36
- package/lib/behaviors.js +65 -106
- package/lib/constants.d.ts +5 -5
- package/lib/constants.js +13 -7
- package/lib/devTools.d.ts +15 -15
- package/lib/devTools.js +37 -26
- package/lib/each.d.ts +3 -3
- package/lib/environment.d.ts +1 -1
- package/lib/environment.js +7 -4
- package/lib/index.d.ts +30 -30
- package/lib/index.js +67 -57
- package/lib/interpreter.d.ts +205 -199
- package/lib/interpreter.js +1306 -1060
- package/lib/invoke.d.ts +10 -10
- package/lib/invokeUtils.d.ts +6 -6
- package/lib/invokeUtils.js +40 -37
- package/lib/json.d.ts +30 -30
- package/lib/mapState.d.ts +3 -3
- package/lib/mapState.js +31 -32
- package/lib/match.d.ts +8 -8
- package/lib/match.js +33 -47
- package/lib/model.d.ts +4 -39
- package/lib/model.types.d.ts +37 -0
- package/lib/model.types.js +2 -0
- package/lib/patterns.d.ts +13 -13
- package/lib/registry.d.ts +8 -8
- package/lib/registry.js +21 -18
- package/lib/scheduler.d.ts +16 -16
- package/lib/scheduler.js +79 -70
- package/lib/schema.d.ts +1 -1
- package/lib/schema.js +6 -4
- package/lib/scxml.d.ts +5 -5
- package/lib/serviceScope.d.ts +3 -3
- package/lib/serviceScope.js +16 -12
- package/lib/stateUtils.d.ts +14 -14
- package/lib/stateUtils.js +231 -199
- package/lib/types.d.ts +928 -918
- package/lib/types.js +29 -29
- package/lib/utils.d.ts +68 -68
- package/lib/utils.js +528 -534
- package/package.json +5 -5
package/lib/actions.js
CHANGED
|
@@ -1,460 +1,538 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
|
-
if (!m) return o;
|
|
16
|
-
var i = m.call(o), r, ar = [], e;
|
|
17
|
-
try {
|
|
18
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
19
|
-
}
|
|
20
|
-
catch (error) { e = { error: error }; }
|
|
21
|
-
finally {
|
|
22
|
-
try {
|
|
23
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
24
|
-
}
|
|
25
|
-
finally { if (e) throw e.error; }
|
|
26
|
-
}
|
|
27
|
-
return ar;
|
|
28
|
-
};
|
|
29
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.resolveActions = exports.choose = exports.escalate = exports.forwardTo = exports.pure = exports.error = exports.doneInvoke = exports.done = exports.after = exports.isActionObject = exports.assign = exports.resolveStop = exports.stop = exports.start = exports.cancel = exports.resolveLog = exports.log = exports.respond = exports.sendUpdate = exports.sendParent = exports.resolveSend = exports.send = exports.resolveRaise = exports.raise = exports.toActivityDefinition = exports.toActionObjects = exports.toActionObject = exports.getActionFunction = exports.initEvent = exports.actionTypes = void 0;
|
|
31
|
-
var types_1 = require("./types");
|
|
32
|
-
var actionTypes = require("./actionTypes");
|
|
33
|
-
exports.actionTypes = actionTypes;
|
|
34
|
-
var utils_1 = require("./utils");
|
|
35
|
-
var environment_1 = require("./environment");
|
|
36
|
-
exports.initEvent = utils_1.toSCXMLEvent({ type: actionTypes.init });
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _tslib = require('./_virtual/_tslib.js');
|
|
6
|
+
var environment = require('./environment.js');
|
|
7
|
+
var utils = require('./utils.js');
|
|
8
|
+
var types = require('./types.js');
|
|
9
|
+
var actionTypes = require('./actionTypes.js');
|
|
10
|
+
|
|
11
|
+
var initEvent = /*#__PURE__*/utils.toSCXMLEvent({
|
|
12
|
+
type: actionTypes.init
|
|
13
|
+
});
|
|
37
14
|
function getActionFunction(actionType, actionFunctionMap) {
|
|
38
|
-
|
|
39
|
-
? actionFunctionMap[actionType] || undefined
|
|
40
|
-
: undefined;
|
|
15
|
+
return actionFunctionMap ? actionFunctionMap[actionType] || undefined : undefined;
|
|
41
16
|
}
|
|
42
|
-
exports.getActionFunction = getActionFunction;
|
|
43
17
|
function toActionObject(action, actionFunctionMap) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
actionObject = {
|
|
62
|
-
// Convert action to string if unnamed
|
|
63
|
-
type: action.name || action.toString(),
|
|
64
|
-
exec: action
|
|
65
|
-
};
|
|
18
|
+
var actionObject;
|
|
19
|
+
|
|
20
|
+
if (utils.isString(action) || typeof action === 'number') {
|
|
21
|
+
var exec = getActionFunction(action, actionFunctionMap);
|
|
22
|
+
|
|
23
|
+
if (utils.isFunction(exec)) {
|
|
24
|
+
actionObject = {
|
|
25
|
+
type: action,
|
|
26
|
+
exec: exec
|
|
27
|
+
};
|
|
28
|
+
} else if (exec) {
|
|
29
|
+
actionObject = exec;
|
|
30
|
+
} else {
|
|
31
|
+
actionObject = {
|
|
32
|
+
type: action,
|
|
33
|
+
exec: undefined
|
|
34
|
+
};
|
|
66
35
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
36
|
+
} else if (utils.isFunction(action)) {
|
|
37
|
+
actionObject = {
|
|
38
|
+
// Convert action to string if unnamed
|
|
39
|
+
type: action.name || action.toString(),
|
|
40
|
+
exec: action
|
|
41
|
+
};
|
|
42
|
+
} else {
|
|
43
|
+
var exec = getActionFunction(action.type, actionFunctionMap);
|
|
44
|
+
|
|
45
|
+
if (utils.isFunction(exec)) {
|
|
46
|
+
actionObject = _tslib.__assign(_tslib.__assign({}, action), {
|
|
47
|
+
exec: exec
|
|
48
|
+
});
|
|
49
|
+
} else if (exec) {
|
|
50
|
+
var actionType = exec.type || action.type;
|
|
51
|
+
actionObject = _tslib.__assign(_tslib.__assign(_tslib.__assign({}, exec), action), {
|
|
52
|
+
type: actionType
|
|
53
|
+
});
|
|
54
|
+
} else {
|
|
55
|
+
actionObject = action;
|
|
79
56
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
Object.defineProperty(actionObject, 'toString', {
|
|
60
|
+
value: function () {
|
|
61
|
+
return actionObject.type;
|
|
62
|
+
},
|
|
63
|
+
enumerable: false,
|
|
64
|
+
configurable: true
|
|
65
|
+
});
|
|
66
|
+
return actionObject;
|
|
86
67
|
}
|
|
87
|
-
exports.toActionObject = toActionObject;
|
|
88
68
|
var toActionObjects = function (action, actionFunctionMap) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
69
|
+
if (!action) {
|
|
70
|
+
return [];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
var actions = utils.isArray(action) ? action : [action];
|
|
74
|
+
return actions.map(function (subAction) {
|
|
75
|
+
return toActionObject(subAction, actionFunctionMap);
|
|
76
|
+
});
|
|
96
77
|
};
|
|
97
|
-
exports.toActionObjects = toActionObjects;
|
|
98
78
|
function toActivityDefinition(action) {
|
|
99
|
-
|
|
100
|
-
|
|
79
|
+
var actionObject = toActionObject(action);
|
|
80
|
+
return _tslib.__assign(_tslib.__assign({
|
|
81
|
+
id: utils.isString(action) ? action : actionObject.id
|
|
82
|
+
}, actionObject), {
|
|
83
|
+
type: actionObject.type
|
|
84
|
+
});
|
|
101
85
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
* @param eventType The event to raise.
|
|
86
|
+
/**
|
|
87
|
+
* Raises an event. This places the event in the internal event queue, so that
|
|
88
|
+
* the event is immediately consumed by the machine in the current step.
|
|
89
|
+
*
|
|
90
|
+
* @param eventType The event to raise.
|
|
108
91
|
*/
|
|
92
|
+
|
|
109
93
|
function raise(event) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
94
|
+
if (!utils.isString(event)) {
|
|
95
|
+
return send(event, {
|
|
96
|
+
to: types.SpecialTargets.Internal
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
type: actionTypes.raise,
|
|
102
|
+
event: event
|
|
103
|
+
};
|
|
117
104
|
}
|
|
118
|
-
exports.raise = raise;
|
|
119
105
|
function resolveRaise(action) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
106
|
+
return {
|
|
107
|
+
type: actionTypes.raise,
|
|
108
|
+
_event: utils.toSCXMLEvent(action.event)
|
|
109
|
+
};
|
|
124
110
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
* @param
|
|
131
|
-
*
|
|
132
|
-
* - `
|
|
133
|
-
* - `
|
|
134
|
-
* - `to` - The target of this event (by default, the machine the event was sent from).
|
|
111
|
+
/**
|
|
112
|
+
* Sends an event. This returns an action that will be read by an interpreter to
|
|
113
|
+
* send the event in the next step, after the current step is finished executing.
|
|
114
|
+
*
|
|
115
|
+
* @param event The event to send.
|
|
116
|
+
* @param options Options to pass into the send event:
|
|
117
|
+
* - `id` - The unique send event identifier (used with `cancel()`).
|
|
118
|
+
* - `delay` - The number of milliseconds to delay the sending of the event.
|
|
119
|
+
* - `to` - The target of this event (by default, the machine the event was sent from).
|
|
135
120
|
*/
|
|
121
|
+
|
|
136
122
|
function send(event, options) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
: utils_1.isFunction(event)
|
|
145
|
-
? event.name
|
|
146
|
-
: utils_1.getEventType(event)
|
|
147
|
-
};
|
|
123
|
+
return {
|
|
124
|
+
to: options ? options.to : undefined,
|
|
125
|
+
type: actionTypes.send,
|
|
126
|
+
event: utils.isFunction(event) ? event : utils.toEventObject(event),
|
|
127
|
+
delay: options ? options.delay : undefined,
|
|
128
|
+
id: options && options.id !== undefined ? options.id : utils.isFunction(event) ? event.name : utils.getEventType(event)
|
|
129
|
+
};
|
|
148
130
|
}
|
|
149
|
-
exports.send = send;
|
|
150
131
|
function resolveSend(action, ctx, _event, delaysMap) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
: action.to;
|
|
173
|
-
return __assign(__assign({}, action), { to: resolvedTarget, _event: resolvedEvent, event: resolvedEvent.data, delay: resolvedDelay });
|
|
132
|
+
var meta = {
|
|
133
|
+
_event: _event
|
|
134
|
+
}; // TODO: helper function for resolving Expr
|
|
135
|
+
|
|
136
|
+
var resolvedEvent = utils.toSCXMLEvent(utils.isFunction(action.event) ? action.event(ctx, _event.data, meta) : action.event);
|
|
137
|
+
var resolvedDelay;
|
|
138
|
+
|
|
139
|
+
if (utils.isString(action.delay)) {
|
|
140
|
+
var configDelay = delaysMap && delaysMap[action.delay];
|
|
141
|
+
resolvedDelay = utils.isFunction(configDelay) ? configDelay(ctx, _event.data, meta) : configDelay;
|
|
142
|
+
} else {
|
|
143
|
+
resolvedDelay = utils.isFunction(action.delay) ? action.delay(ctx, _event.data, meta) : action.delay;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
var resolvedTarget = utils.isFunction(action.to) ? action.to(ctx, _event.data, meta) : action.to;
|
|
147
|
+
return _tslib.__assign(_tslib.__assign({}, action), {
|
|
148
|
+
to: resolvedTarget,
|
|
149
|
+
_event: resolvedEvent,
|
|
150
|
+
event: resolvedEvent.data,
|
|
151
|
+
delay: resolvedDelay
|
|
152
|
+
});
|
|
174
153
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
* @param
|
|
180
|
-
* @param options Options to pass into the send event.
|
|
154
|
+
/**
|
|
155
|
+
* Sends an event to this machine's parent.
|
|
156
|
+
*
|
|
157
|
+
* @param event The event to send to the parent machine.
|
|
158
|
+
* @param options Options to pass into the send event.
|
|
181
159
|
*/
|
|
160
|
+
|
|
182
161
|
function sendParent(event, options) {
|
|
183
|
-
|
|
162
|
+
return send(event, _tslib.__assign(_tslib.__assign({}, options), {
|
|
163
|
+
to: types.SpecialTargets.Parent
|
|
164
|
+
}));
|
|
184
165
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
* Sends an update event to this machine's parent.
|
|
166
|
+
/**
|
|
167
|
+
* Sends an update event to this machine's parent.
|
|
188
168
|
*/
|
|
169
|
+
|
|
189
170
|
function sendUpdate() {
|
|
190
|
-
|
|
171
|
+
return sendParent(actionTypes.update);
|
|
191
172
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
* @param
|
|
197
|
-
* @param options Options to pass into the send event
|
|
173
|
+
/**
|
|
174
|
+
* Sends an event back to the sender of the original event.
|
|
175
|
+
*
|
|
176
|
+
* @param event The event to send back to the sender
|
|
177
|
+
* @param options Options to pass into the send event
|
|
198
178
|
*/
|
|
179
|
+
|
|
199
180
|
function respond(event, options) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
181
|
+
return send(event, _tslib.__assign(_tslib.__assign({}, options), {
|
|
182
|
+
to: function (_, __, _a) {
|
|
183
|
+
var _event = _a._event;
|
|
184
|
+
return _event.origin; // TODO: handle when _event.origin is undefined
|
|
185
|
+
}
|
|
186
|
+
}));
|
|
204
187
|
}
|
|
205
|
-
|
|
206
|
-
var defaultLogExpr = function (context, event) {
|
|
188
|
+
|
|
189
|
+
var defaultLogExpr = function (context, event) {
|
|
190
|
+
return {
|
|
207
191
|
context: context,
|
|
208
192
|
event: event
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
* - `
|
|
216
|
-
*
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
/**
|
|
196
|
+
*
|
|
197
|
+
* @param expr The expression function to evaluate which will be logged.
|
|
198
|
+
* Takes in 2 arguments:
|
|
199
|
+
* - `ctx` - the current state context
|
|
200
|
+
* - `event` - the event that caused this action to be executed.
|
|
201
|
+
* @param label The label to give to the logged expression.
|
|
217
202
|
*/
|
|
203
|
+
|
|
204
|
+
|
|
218
205
|
function log(expr, label) {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
206
|
+
if (expr === void 0) {
|
|
207
|
+
expr = defaultLogExpr;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return {
|
|
211
|
+
type: actionTypes.log,
|
|
212
|
+
label: label,
|
|
213
|
+
expr: expr
|
|
214
|
+
};
|
|
225
215
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* Cancels an in-flight `send(...)` action. A canceled sent action will not
|
|
235
|
-
* be executed, nor will its event be sent, unless it has already been sent
|
|
236
|
-
* (e.g., if `cancel(...)` is called after the `send(...)` action's `delay`).
|
|
237
|
-
*
|
|
238
|
-
* @param sendId The `id` of the `send(...)` action to cancel.
|
|
216
|
+
var resolveLog = function (action, ctx, _event) {
|
|
217
|
+
return _tslib.__assign(_tslib.__assign({}, action), {
|
|
218
|
+
value: utils.isString(action.expr) ? action.expr : action.expr(ctx, _event.data, {
|
|
219
|
+
_event: _event
|
|
220
|
+
})
|
|
221
|
+
});
|
|
222
|
+
};
|
|
223
|
+
/**
|
|
224
|
+
* Cancels an in-flight `send(...)` action. A canceled sent action will not
|
|
225
|
+
* be executed, nor will its event be sent, unless it has already been sent
|
|
226
|
+
* (e.g., if `cancel(...)` is called after the `send(...)` action's `delay`).
|
|
227
|
+
*
|
|
228
|
+
* @param sendId The `id` of the `send(...)` action to cancel.
|
|
239
229
|
*/
|
|
230
|
+
|
|
240
231
|
var cancel = function (sendId) {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
232
|
+
return {
|
|
233
|
+
type: actionTypes.cancel,
|
|
234
|
+
sendId: sendId
|
|
235
|
+
};
|
|
245
236
|
};
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
*
|
|
249
|
-
*
|
|
250
|
-
* @param activity The activity to start.
|
|
237
|
+
/**
|
|
238
|
+
* Starts an activity.
|
|
239
|
+
*
|
|
240
|
+
* @param activity The activity to start.
|
|
251
241
|
*/
|
|
242
|
+
|
|
252
243
|
function start(activity) {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
244
|
+
var activityDef = toActivityDefinition(activity);
|
|
245
|
+
return {
|
|
246
|
+
type: types.ActionTypes.Start,
|
|
247
|
+
activity: activityDef,
|
|
248
|
+
exec: undefined
|
|
249
|
+
};
|
|
259
250
|
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
* @param actorRef The activity to stop.
|
|
251
|
+
/**
|
|
252
|
+
* Stops an activity.
|
|
253
|
+
*
|
|
254
|
+
* @param actorRef The activity to stop.
|
|
265
255
|
*/
|
|
256
|
+
|
|
266
257
|
function stop(actorRef) {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
exec: undefined
|
|
274
|
-
};
|
|
258
|
+
var activity = utils.isFunction(actorRef) ? actorRef : toActivityDefinition(actorRef);
|
|
259
|
+
return {
|
|
260
|
+
type: types.ActionTypes.Stop,
|
|
261
|
+
activity: activity,
|
|
262
|
+
exec: undefined
|
|
263
|
+
};
|
|
275
264
|
}
|
|
276
|
-
exports.stop = stop;
|
|
277
265
|
function resolveStop(action, context, _event) {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
};
|
|
288
|
-
return actionObject;
|
|
266
|
+
var actorRefOrString = utils.isFunction(action.activity) ? action.activity(context, _event.data) : action.activity;
|
|
267
|
+
var resolvedActorRef = typeof actorRefOrString === 'string' ? {
|
|
268
|
+
id: actorRefOrString
|
|
269
|
+
} : actorRefOrString;
|
|
270
|
+
var actionObject = {
|
|
271
|
+
type: types.ActionTypes.Stop,
|
|
272
|
+
activity: resolvedActorRef
|
|
273
|
+
};
|
|
274
|
+
return actionObject;
|
|
289
275
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
*
|
|
293
|
-
*
|
|
294
|
-
* @param assignment An object that represents the partial context to update.
|
|
276
|
+
/**
|
|
277
|
+
* Updates the current context of the machine.
|
|
278
|
+
*
|
|
279
|
+
* @param assignment An object that represents the partial context to update.
|
|
295
280
|
*/
|
|
281
|
+
|
|
296
282
|
var assign = function (assignment) {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
283
|
+
return {
|
|
284
|
+
type: actionTypes.assign,
|
|
285
|
+
assignment: assignment
|
|
286
|
+
};
|
|
301
287
|
};
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
* Returns an event type that represents an implicit event that
|
|
309
|
-
* is sent after the specified `delay`.
|
|
310
|
-
*
|
|
311
|
-
* @param delayRef The delay in milliseconds
|
|
312
|
-
* @param id The state node ID where this event is handled
|
|
288
|
+
/**
|
|
289
|
+
* Returns an event type that represents an implicit event that
|
|
290
|
+
* is sent after the specified `delay`.
|
|
291
|
+
*
|
|
292
|
+
* @param delayRef The delay in milliseconds
|
|
293
|
+
* @param id The state node ID where this event is handled
|
|
313
294
|
*/
|
|
295
|
+
|
|
314
296
|
function after(delayRef, id) {
|
|
315
|
-
|
|
316
|
-
|
|
297
|
+
var idSuffix = id ? "#" + id : '';
|
|
298
|
+
return types.ActionTypes.After + "(" + delayRef + ")" + idSuffix;
|
|
317
299
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
*
|
|
321
|
-
*
|
|
322
|
-
*
|
|
323
|
-
* @param
|
|
324
|
-
* @param data The data to pass into the event
|
|
300
|
+
/**
|
|
301
|
+
* Returns an event that represents that a final state node
|
|
302
|
+
* has been reached in the parent state node.
|
|
303
|
+
*
|
|
304
|
+
* @param id The final state node's parent state node `id`
|
|
305
|
+
* @param data The data to pass into the event
|
|
325
306
|
*/
|
|
307
|
+
|
|
326
308
|
function done(id, data) {
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
309
|
+
var type = types.ActionTypes.DoneState + "." + id;
|
|
310
|
+
var eventObject = {
|
|
311
|
+
type: type,
|
|
312
|
+
data: data
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
eventObject.toString = function () {
|
|
316
|
+
return type;
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
return eventObject;
|
|
334
320
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
*
|
|
338
|
-
*
|
|
339
|
-
*
|
|
340
|
-
*
|
|
341
|
-
*
|
|
342
|
-
* @param
|
|
343
|
-
* @param data The data to pass into the event
|
|
321
|
+
/**
|
|
322
|
+
* Returns an event that represents that an invoked service has terminated.
|
|
323
|
+
*
|
|
324
|
+
* An invoked service is terminated when it has reached a top-level final state node,
|
|
325
|
+
* but not when it is canceled.
|
|
326
|
+
*
|
|
327
|
+
* @param id The final state node ID
|
|
328
|
+
* @param data The data to pass into the event
|
|
344
329
|
*/
|
|
330
|
+
|
|
345
331
|
function doneInvoke(id, data) {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
332
|
+
var type = types.ActionTypes.DoneInvoke + "." + id;
|
|
333
|
+
var eventObject = {
|
|
334
|
+
type: type,
|
|
335
|
+
data: data
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
eventObject.toString = function () {
|
|
339
|
+
return type;
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
return eventObject;
|
|
353
343
|
}
|
|
354
|
-
exports.doneInvoke = doneInvoke;
|
|
355
344
|
function error(id, data) {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
345
|
+
var type = types.ActionTypes.ErrorPlatform + "." + id;
|
|
346
|
+
var eventObject = {
|
|
347
|
+
type: type,
|
|
348
|
+
data: data
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
eventObject.toString = function () {
|
|
352
|
+
return type;
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
return eventObject;
|
|
360
356
|
}
|
|
361
|
-
exports.error = error;
|
|
362
357
|
function pure(getActions) {
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
358
|
+
return {
|
|
359
|
+
type: types.ActionTypes.Pure,
|
|
360
|
+
get: getActions
|
|
361
|
+
};
|
|
367
362
|
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
*
|
|
371
|
-
*
|
|
372
|
-
* @param
|
|
373
|
-
* @param options Options to pass into the send action creator.
|
|
363
|
+
/**
|
|
364
|
+
* Forwards (sends) an event to a specified service.
|
|
365
|
+
*
|
|
366
|
+
* @param target The target service to forward the event to.
|
|
367
|
+
* @param options Options to pass into the send action creator.
|
|
374
368
|
*/
|
|
369
|
+
|
|
375
370
|
function forwardTo(target, options) {
|
|
376
|
-
|
|
371
|
+
return send(function (_, event) {
|
|
372
|
+
return event;
|
|
373
|
+
}, _tslib.__assign(_tslib.__assign({}, options), {
|
|
374
|
+
to: target
|
|
375
|
+
}));
|
|
377
376
|
}
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
*
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
*
|
|
384
|
-
* @param options Options to pass into the send action creator.
|
|
377
|
+
/**
|
|
378
|
+
* Escalates an error by sending it as an event to this machine's parent.
|
|
379
|
+
*
|
|
380
|
+
* @param errorData The error data to send, or the expression function that
|
|
381
|
+
* takes in the `context`, `event`, and `meta`, and returns the error data to send.
|
|
382
|
+
* @param options Options to pass into the send action creator.
|
|
385
383
|
*/
|
|
384
|
+
|
|
386
385
|
function escalate(errorData, options) {
|
|
387
|
-
|
|
388
|
-
return {
|
|
389
|
-
type: actionTypes.error,
|
|
390
|
-
data: utils_1.isFunction(errorData)
|
|
391
|
-
? errorData(context, event, meta)
|
|
392
|
-
: errorData
|
|
393
|
-
};
|
|
394
|
-
}, __assign(__assign({}, options), { to: types_1.SpecialTargets.Parent }));
|
|
395
|
-
}
|
|
396
|
-
exports.escalate = escalate;
|
|
397
|
-
function choose(conds) {
|
|
386
|
+
return sendParent(function (context, event, meta) {
|
|
398
387
|
return {
|
|
399
|
-
|
|
400
|
-
|
|
388
|
+
type: actionTypes.error,
|
|
389
|
+
data: utils.isFunction(errorData) ? errorData(context, event, meta) : errorData
|
|
401
390
|
};
|
|
391
|
+
}, _tslib.__assign(_tslib.__assign({}, options), {
|
|
392
|
+
to: types.SpecialTargets.Parent
|
|
393
|
+
}));
|
|
402
394
|
}
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
395
|
+
function choose(conds) {
|
|
396
|
+
return {
|
|
397
|
+
type: types.ActionTypes.Choose,
|
|
398
|
+
conds: conds
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
function resolveActions(machine, currentState, currentContext, _event, actions, preserveActionOrder) {
|
|
402
|
+
if (preserveActionOrder === void 0) {
|
|
403
|
+
preserveActionOrder = false;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
var _a = _tslib.__read(preserveActionOrder ? [[], actions] : utils.partition(actions, function (action) {
|
|
407
|
+
return action.type === actionTypes.assign;
|
|
408
|
+
}), 2),
|
|
409
|
+
assignActions = _a[0],
|
|
410
|
+
otherActions = _a[1];
|
|
411
|
+
|
|
412
|
+
var updatedContext = assignActions.length ? utils.updateContext(currentContext, _event, assignActions, currentState) : currentContext;
|
|
413
|
+
var preservedContexts = preserveActionOrder ? [currentContext] : undefined;
|
|
414
|
+
var resolvedActions = utils.flatten(otherActions.map(function (actionObject) {
|
|
415
|
+
var _a;
|
|
416
|
+
|
|
417
|
+
switch (actionObject.type) {
|
|
418
|
+
case actionTypes.raise:
|
|
419
|
+
return resolveRaise(actionObject);
|
|
420
|
+
|
|
421
|
+
case actionTypes.send:
|
|
422
|
+
var sendAction = resolveSend(actionObject, updatedContext, _event, machine.options.delays); // TODO: fix ActionTypes.Init
|
|
423
|
+
|
|
424
|
+
if (!environment.IS_PRODUCTION) {
|
|
425
|
+
// warn after resolving as we can create better contextual message here
|
|
426
|
+
utils.warn(!utils.isString(actionObject.delay) || typeof sendAction.delay === 'number', // tslint:disable-next-line:max-line-length
|
|
427
|
+
"No delay reference for delay expression '" + actionObject.delay + "' was found on machine '" + machine.id + "'");
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
return sendAction;
|
|
431
|
+
|
|
432
|
+
case actionTypes.log:
|
|
433
|
+
return resolveLog(actionObject, updatedContext, _event);
|
|
434
|
+
|
|
435
|
+
case actionTypes.choose:
|
|
436
|
+
{
|
|
437
|
+
var chooseAction = actionObject;
|
|
438
|
+
var matchedActions = (_a = chooseAction.conds.find(function (condition) {
|
|
439
|
+
var guard = utils.toGuard(condition.cond, machine.options.guards);
|
|
440
|
+
return !guard || utils.evaluateGuard(machine, guard, updatedContext, _event, currentState);
|
|
441
|
+
})) === null || _a === void 0 ? void 0 : _a.actions;
|
|
442
|
+
|
|
443
|
+
if (!matchedActions) {
|
|
444
|
+
return [];
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
var _b = _tslib.__read(resolveActions(machine, currentState, updatedContext, _event, toActionObjects(utils.toArray(matchedActions), machine.options.actions), preserveActionOrder), 2),
|
|
448
|
+
resolvedActionsFromChoose = _b[0],
|
|
449
|
+
resolvedContextFromChoose = _b[1];
|
|
450
|
+
|
|
451
|
+
updatedContext = resolvedContextFromChoose;
|
|
452
|
+
preservedContexts === null || preservedContexts === void 0 ? void 0 : preservedContexts.push(updatedContext);
|
|
453
|
+
return resolvedActionsFromChoose;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
case actionTypes.pure:
|
|
457
|
+
{
|
|
458
|
+
var matchedActions = actionObject.get(updatedContext, _event.data);
|
|
459
|
+
|
|
460
|
+
if (!matchedActions) {
|
|
461
|
+
return [];
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
var _c = _tslib.__read(resolveActions(machine, currentState, updatedContext, _event, toActionObjects(utils.toArray(matchedActions), machine.options.actions), preserveActionOrder), 2),
|
|
465
|
+
resolvedActionsFromPure = _c[0],
|
|
466
|
+
resolvedContext = _c[1];
|
|
467
|
+
|
|
468
|
+
updatedContext = resolvedContext;
|
|
469
|
+
preservedContexts === null || preservedContexts === void 0 ? void 0 : preservedContexts.push(updatedContext);
|
|
470
|
+
return resolvedActionsFromPure;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
case actionTypes.stop:
|
|
474
|
+
{
|
|
475
|
+
return resolveStop(actionObject, updatedContext, _event);
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
case actionTypes.assign:
|
|
479
|
+
{
|
|
480
|
+
updatedContext = utils.updateContext(updatedContext, _event, [actionObject], currentState);
|
|
481
|
+
preservedContexts === null || preservedContexts === void 0 ? void 0 : preservedContexts.push(updatedContext);
|
|
482
|
+
break;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
default:
|
|
486
|
+
var resolvedActionObject = toActionObject(actionObject, machine.options.actions);
|
|
487
|
+
var exec_1 = resolvedActionObject.exec;
|
|
488
|
+
|
|
489
|
+
if (exec_1 && preservedContexts) {
|
|
490
|
+
var contextIndex_1 = preservedContexts.length - 1;
|
|
491
|
+
|
|
492
|
+
resolvedActionObject.exec = function (_ctx) {
|
|
493
|
+
var args = [];
|
|
494
|
+
|
|
495
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
496
|
+
args[_i - 1] = arguments[_i];
|
|
453
497
|
}
|
|
454
|
-
|
|
455
|
-
|
|
498
|
+
|
|
499
|
+
exec_1 === null || exec_1 === void 0 ? void 0 : exec_1.apply(void 0, _tslib.__spreadArray([preservedContexts[contextIndex_1]], _tslib.__read(args)));
|
|
500
|
+
};
|
|
456
501
|
}
|
|
457
|
-
|
|
458
|
-
|
|
502
|
+
|
|
503
|
+
return resolvedActionObject;
|
|
504
|
+
}
|
|
505
|
+
}).filter(function (a) {
|
|
506
|
+
return !!a;
|
|
507
|
+
}));
|
|
508
|
+
return [resolvedActions, updatedContext];
|
|
459
509
|
}
|
|
510
|
+
|
|
511
|
+
exports.after = after;
|
|
512
|
+
exports.assign = assign;
|
|
513
|
+
exports.cancel = cancel;
|
|
514
|
+
exports.choose = choose;
|
|
515
|
+
exports.done = done;
|
|
516
|
+
exports.doneInvoke = doneInvoke;
|
|
517
|
+
exports.error = error;
|
|
518
|
+
exports.escalate = escalate;
|
|
519
|
+
exports.forwardTo = forwardTo;
|
|
520
|
+
exports.getActionFunction = getActionFunction;
|
|
521
|
+
exports.initEvent = initEvent;
|
|
522
|
+
exports.log = log;
|
|
523
|
+
exports.pure = pure;
|
|
524
|
+
exports.raise = raise;
|
|
460
525
|
exports.resolveActions = resolveActions;
|
|
526
|
+
exports.resolveLog = resolveLog;
|
|
527
|
+
exports.resolveRaise = resolveRaise;
|
|
528
|
+
exports.resolveSend = resolveSend;
|
|
529
|
+
exports.resolveStop = resolveStop;
|
|
530
|
+
exports.respond = respond;
|
|
531
|
+
exports.send = send;
|
|
532
|
+
exports.sendParent = sendParent;
|
|
533
|
+
exports.sendUpdate = sendUpdate;
|
|
534
|
+
exports.start = start;
|
|
535
|
+
exports.stop = stop;
|
|
536
|
+
exports.toActionObject = toActionObject;
|
|
537
|
+
exports.toActionObjects = toActionObjects;
|
|
538
|
+
exports.toActivityDefinition = toActivityDefinition;
|