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