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