xstate 5.0.0-beta.8 → 5.0.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/README.md +10 -8
- package/actions/dist/xstate-actions.cjs.d.mts +2 -0
- package/actions/dist/xstate-actions.cjs.d.mts.map +1 -0
- package/actions/dist/xstate-actions.cjs.d.ts +1 -0
- package/actions/dist/xstate-actions.cjs.d.ts.map +1 -0
- package/actions/dist/xstate-actions.cjs.js +19 -5
- package/actions/dist/xstate-actions.cjs.mjs +13 -0
- package/actions/dist/xstate-actions.development.cjs.js +21 -0
- package/actions/dist/xstate-actions.development.cjs.mjs +13 -0
- package/actions/dist/xstate-actions.development.esm.js +3 -0
- package/actions/dist/xstate-actions.esm.js +3 -2
- package/actions/dist/xstate-actions.umd.min.js +1 -1
- package/actions/dist/xstate-actions.umd.min.js.map +1 -1
- package/actors/dist/xstate-actors.cjs.d.mts +2 -0
- package/actors/dist/xstate-actors.cjs.d.mts.map +1 -0
- package/actors/dist/xstate-actors.cjs.d.ts +1 -0
- package/actors/dist/xstate-actors.cjs.d.ts.map +1 -0
- package/actors/dist/xstate-actors.cjs.js +621 -4
- package/actors/dist/xstate-actors.cjs.mjs +8 -0
- package/actors/dist/xstate-actors.development.cjs.js +624 -0
- package/actors/dist/xstate-actors.development.cjs.mjs +8 -0
- package/actors/dist/xstate-actors.development.esm.js +615 -0
- package/actors/dist/xstate-actors.esm.js +615 -2
- package/actors/dist/xstate-actors.umd.min.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dev/dist/xstate-dev.cjs.d.mts +2 -0
- package/dev/dist/xstate-dev.cjs.d.mts.map +1 -0
- package/dev/dist/xstate-dev.cjs.d.ts +1 -0
- package/dev/dist/xstate-dev.cjs.d.ts.map +1 -0
- package/dev/dist/xstate-dev.cjs.js +45 -4
- package/dev/dist/xstate-dev.cjs.mjs +5 -0
- package/{dist/index-ebaab3c9.cjs.dev.js → dev/dist/xstate-dev.development.cjs.js} +6 -7
- package/dev/dist/xstate-dev.development.cjs.mjs +5 -0
- package/{dist/index-50bd0aff.esm.js → dev/dist/xstate-dev.development.esm.js} +6 -8
- package/dev/dist/xstate-dev.esm.js +42 -1
- package/dev/dist/xstate-dev.umd.min.js +1 -1
- package/dev/dist/xstate-dev.umd.min.js.map +1 -1
- package/dist/declarations/src/SimulatedClock.d.ts +1 -1
- package/dist/declarations/src/State.d.ts +47 -73
- package/dist/declarations/src/StateMachine.d.ts +29 -57
- package/dist/declarations/src/StateNode.d.ts +36 -33
- package/dist/declarations/src/actions/assign.d.ts +11 -2
- package/dist/declarations/src/actions/cancel.d.ts +7 -3
- package/dist/declarations/src/actions/enqueueActions.d.ts +32 -0
- package/dist/declarations/src/actions/log.d.ts +7 -3
- package/dist/declarations/src/actions/raise.d.ts +7 -2
- package/dist/declarations/src/actions/send.d.ts +14 -36
- package/dist/declarations/src/actions/spawnChild.d.ts +29 -0
- package/dist/declarations/src/actions/stopChild.d.ts +18 -0
- package/dist/declarations/src/actions.d.ts +8 -48
- package/dist/declarations/src/actors/callback.d.ts +91 -8
- package/dist/declarations/src/actors/index.d.ts +6 -28
- package/dist/declarations/src/actors/observable.d.ts +101 -18
- package/dist/declarations/src/actors/promise.d.ts +80 -10
- package/dist/declarations/src/actors/transition.d.ts +64 -9
- package/dist/declarations/src/constants.d.ts +3 -0
- package/dist/declarations/src/createMachine.d.ts +20 -0
- package/dist/declarations/src/dev/index.d.ts +6 -6
- package/dist/declarations/src/guards.d.ts +41 -8
- package/dist/declarations/src/index.d.ts +18 -23
- package/dist/declarations/src/interpreter.d.ts +150 -41
- package/dist/declarations/src/setup.d.ts +51 -0
- package/dist/declarations/src/spawn.d.ts +23 -2
- package/dist/declarations/src/stateUtils.d.ts +30 -45
- package/dist/declarations/src/system.d.ts +26 -2
- package/dist/declarations/src/typegenTypes.d.ts +40 -22
- package/dist/declarations/src/types.d.ts +528 -669
- package/dist/declarations/src/utils.d.ts +15 -52
- package/dist/declarations/src/waitFor.d.ts +2 -2
- package/dist/log-22e678c5.esm.js +364 -0
- package/dist/log-5e226275.cjs.js +372 -0
- package/dist/log-641cd926.development.cjs.js +394 -0
- package/dist/log-f196f85f.development.esm.js +386 -0
- package/dist/raise-34e25c2c.cjs.js +2368 -0
- package/dist/raise-62704519.development.cjs.js +2422 -0
- package/dist/raise-89c581c4.development.esm.js +2371 -0
- package/dist/raise-8bc422d1.esm.js +2317 -0
- package/dist/xstate.cjs.d.mts +2 -0
- package/dist/xstate.cjs.d.mts.map +1 -0
- package/dist/xstate.cjs.d.ts +1 -0
- package/dist/xstate.cjs.d.ts.map +1 -0
- package/dist/xstate.cjs.js +728 -4
- package/dist/xstate.cjs.mjs +39 -0
- package/dist/xstate.development.cjs.js +737 -0
- package/dist/xstate.development.cjs.mjs +39 -0
- package/dist/xstate.development.esm.js +699 -0
- package/dist/xstate.esm.js +561 -770
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.d.mts +2 -0
- package/guards/dist/xstate-guards.cjs.d.mts.map +1 -0
- package/guards/dist/xstate-guards.cjs.d.ts +1 -0
- package/guards/dist/xstate-guards.cjs.d.ts.map +1 -0
- package/guards/dist/xstate-guards.cjs.js +12 -5
- package/guards/dist/xstate-guards.cjs.mjs +7 -0
- package/guards/dist/xstate-guards.development.cjs.js +14 -0
- package/guards/dist/xstate-guards.development.cjs.mjs +7 -0
- package/guards/dist/xstate-guards.development.esm.js +2 -0
- package/guards/dist/xstate-guards.esm.js +2 -2
- package/guards/dist/xstate-guards.umd.min.js +1 -1
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +59 -1
- package/actions/dist/xstate-actions.cjs.dev.js +0 -32
- package/actions/dist/xstate-actions.cjs.prod.js +0 -32
- package/actions/dynamicAction.ts +0 -42
- package/actors/dist/xstate-actors.cjs.dev.js +0 -22
- package/actors/dist/xstate-actors.cjs.prod.js +0 -22
- package/dev/dist/xstate-dev.cjs.dev.js +0 -11
- package/dev/dist/xstate-dev.cjs.prod.js +0 -48
- package/dist/actions-900f9761.cjs.prod.js +0 -4349
- package/dist/actions-c8d7df32.esm.js +0 -4332
- package/dist/actions-d06ca158.cjs.dev.js +0 -4387
- package/dist/declarations/actions/dynamicAction.d.ts +0 -5
- package/dist/declarations/src/Machine.d.ts +0 -4
- package/dist/declarations/src/Mailbox.d.ts +0 -12
- package/dist/declarations/src/actionTypes.d.ts +0 -16
- package/dist/declarations/src/actions/choose.d.ts +0 -3
- package/dist/declarations/src/actions/invoke.d.ts +0 -3
- package/dist/declarations/src/actions/pure.d.ts +0 -6
- package/dist/declarations/src/actions/stop.d.ts +0 -7
- package/dist/declarations/src/environment.d.ts +0 -1
- package/dist/declarations/src/mapState.d.ts +0 -3
- package/dist/declarations/src/memo.d.ts +0 -2
- package/dist/xstate.cjs.dev.js +0 -956
- package/dist/xstate.cjs.prod.js +0 -953
- package/guards/dist/xstate-guards.cjs.dev.js +0 -15
- package/guards/dist/xstate-guards.cjs.prod.js +0 -15
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var guards_dist_xstateGuards = require('./raise-62704519.development.cjs.js');
|
|
4
|
+
|
|
5
|
+
function createSpawner(actorScope, {
|
|
6
|
+
machine,
|
|
7
|
+
context
|
|
8
|
+
}, event, spawnedChildren) {
|
|
9
|
+
const spawn = (src, options = {}) => {
|
|
10
|
+
const {
|
|
11
|
+
systemId,
|
|
12
|
+
input
|
|
13
|
+
} = options;
|
|
14
|
+
if (typeof src === 'string') {
|
|
15
|
+
const logic = guards_dist_xstateGuards.resolveReferencedActor(machine, src);
|
|
16
|
+
if (!logic) {
|
|
17
|
+
throw new Error(`Actor logic '${src}' not implemented in machine '${machine.id}'`);
|
|
18
|
+
}
|
|
19
|
+
const actorRef = guards_dist_xstateGuards.createActor(logic, {
|
|
20
|
+
id: options.id,
|
|
21
|
+
parent: actorScope.self,
|
|
22
|
+
syncSnapshot: options.syncSnapshot,
|
|
23
|
+
input: typeof input === 'function' ? input({
|
|
24
|
+
context,
|
|
25
|
+
event,
|
|
26
|
+
self: actorScope.self
|
|
27
|
+
}) : input,
|
|
28
|
+
src,
|
|
29
|
+
systemId
|
|
30
|
+
});
|
|
31
|
+
spawnedChildren[actorRef.id] = actorRef;
|
|
32
|
+
return actorRef;
|
|
33
|
+
} else {
|
|
34
|
+
const actorRef = guards_dist_xstateGuards.createActor(src, {
|
|
35
|
+
id: options.id,
|
|
36
|
+
parent: actorScope.self,
|
|
37
|
+
syncSnapshot: options.syncSnapshot,
|
|
38
|
+
input: options.input,
|
|
39
|
+
src,
|
|
40
|
+
systemId
|
|
41
|
+
});
|
|
42
|
+
return actorRef;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
return (src, options) => {
|
|
46
|
+
const actorRef = spawn(src, options); // TODO: fix types
|
|
47
|
+
spawnedChildren[actorRef.id] = actorRef;
|
|
48
|
+
actorScope.defer(() => {
|
|
49
|
+
if (actorRef._processingStatus === guards_dist_xstateGuards.ProcessingStatus.Stopped) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
actorRef.start();
|
|
53
|
+
});
|
|
54
|
+
return actorRef;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function resolveAssign(actorScope, snapshot, actionArgs, actionParams, {
|
|
59
|
+
assignment
|
|
60
|
+
}) {
|
|
61
|
+
if (!snapshot.context) {
|
|
62
|
+
throw new Error('Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.');
|
|
63
|
+
}
|
|
64
|
+
const spawnedChildren = {};
|
|
65
|
+
const assignArgs = {
|
|
66
|
+
context: snapshot.context,
|
|
67
|
+
event: actionArgs.event,
|
|
68
|
+
spawn: createSpawner(actorScope, snapshot, actionArgs.event, spawnedChildren),
|
|
69
|
+
self: actorScope?.self,
|
|
70
|
+
system: actorScope?.system
|
|
71
|
+
};
|
|
72
|
+
let partialUpdate = {};
|
|
73
|
+
if (typeof assignment === 'function') {
|
|
74
|
+
partialUpdate = assignment(assignArgs, actionParams);
|
|
75
|
+
} else {
|
|
76
|
+
for (const key of Object.keys(assignment)) {
|
|
77
|
+
const propAssignment = assignment[key];
|
|
78
|
+
partialUpdate[key] = typeof propAssignment === 'function' ? propAssignment(assignArgs, actionParams) : propAssignment;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const updatedContext = Object.assign({}, snapshot.context, partialUpdate);
|
|
82
|
+
return [guards_dist_xstateGuards.cloneMachineSnapshot(snapshot, {
|
|
83
|
+
context: updatedContext,
|
|
84
|
+
children: Object.keys(spawnedChildren).length ? {
|
|
85
|
+
...snapshot.children,
|
|
86
|
+
...spawnedChildren
|
|
87
|
+
} : snapshot.children
|
|
88
|
+
})];
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Updates the current context of the machine.
|
|
92
|
+
*
|
|
93
|
+
* @param assignment An object that represents the partial context to update.
|
|
94
|
+
*/
|
|
95
|
+
function assign(assignment) {
|
|
96
|
+
function assign(args, params) {
|
|
97
|
+
{
|
|
98
|
+
throw new Error(`This isn't supposed to be called`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
assign.type = 'xstate.assign';
|
|
102
|
+
assign.assignment = assignment;
|
|
103
|
+
assign.resolve = resolveAssign;
|
|
104
|
+
return assign;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
*
|
|
109
|
+
* @remarks
|
|
110
|
+
*
|
|
111
|
+
* `T | unknown` reduces to `unknown` and that can be problematic when it comes to contextual typing.
|
|
112
|
+
* It especially is a problem when the union has a function member, like here:
|
|
113
|
+
*
|
|
114
|
+
* ```ts
|
|
115
|
+
* declare function test(cbOrVal: ((arg: number) => unknown) | unknown): void;
|
|
116
|
+
* test((arg) => {}) // oops, implicit any
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* This type can be used to avoid this problem. This union represents the same value space as `unknown`.
|
|
120
|
+
*/
|
|
121
|
+
|
|
122
|
+
// https://github.com/microsoft/TypeScript/issues/23182#issuecomment-379091887
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* The full definition of an event, with a string `type`.
|
|
126
|
+
*/
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* The string or object representing the state value relative to the parent state node.
|
|
130
|
+
*
|
|
131
|
+
* @remarks
|
|
132
|
+
*
|
|
133
|
+
* - For a child atomic state node, this is a string, e.g., `"pending"`.
|
|
134
|
+
*
|
|
135
|
+
* - For complex state nodes, this is an object, e.g., `{ success: "someChildState" }`.
|
|
136
|
+
*/
|
|
137
|
+
|
|
138
|
+
// TODO: remove once TS fixes this type-widening issue
|
|
139
|
+
|
|
140
|
+
/** @deprecated use `AnyMachineSnapshot` instead */
|
|
141
|
+
|
|
142
|
+
// TODO: possibly refactor this somehow, use even a simpler type, and maybe even make `machine.options` private or something
|
|
143
|
+
|
|
144
|
+
let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
145
|
+
SpecialTargets["Parent"] = "#_parent";
|
|
146
|
+
SpecialTargets["Internal"] = "#_internal";
|
|
147
|
+
return SpecialTargets;
|
|
148
|
+
}({});
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* @deprecated Use `AnyActor` instead.
|
|
152
|
+
*/
|
|
153
|
+
|
|
154
|
+
// Based on RxJS types
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* @deprecated Use `Actor<T>` instead.
|
|
158
|
+
*/
|
|
159
|
+
|
|
160
|
+
// only meant to be used internally for debugging purposes
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Represents logic which can be used by an actor.
|
|
164
|
+
*
|
|
165
|
+
* @template TSnapshot - The type of the snapshot.
|
|
166
|
+
* @template TEvent - The type of the event object.
|
|
167
|
+
* @template TInput - The type of the input.
|
|
168
|
+
* @template TSystem - The type of the actor system.
|
|
169
|
+
*/
|
|
170
|
+
|
|
171
|
+
function resolveSendTo(actorScope, snapshot, args, actionParams, {
|
|
172
|
+
to,
|
|
173
|
+
event: eventOrExpr,
|
|
174
|
+
id,
|
|
175
|
+
delay
|
|
176
|
+
}, extra) {
|
|
177
|
+
const delaysMap = snapshot.machine.implementations.delays;
|
|
178
|
+
if (typeof eventOrExpr === 'string') {
|
|
179
|
+
throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${eventOrExpr}" }) instead`);
|
|
180
|
+
}
|
|
181
|
+
const resolvedEvent = typeof eventOrExpr === 'function' ? eventOrExpr(args, actionParams) : eventOrExpr;
|
|
182
|
+
let resolvedDelay;
|
|
183
|
+
if (typeof delay === 'string') {
|
|
184
|
+
const configDelay = delaysMap && delaysMap[delay];
|
|
185
|
+
resolvedDelay = typeof configDelay === 'function' ? configDelay(args, actionParams) : configDelay;
|
|
186
|
+
} else {
|
|
187
|
+
resolvedDelay = typeof delay === 'function' ? delay(args, actionParams) : delay;
|
|
188
|
+
}
|
|
189
|
+
const resolvedTarget = typeof to === 'function' ? to(args, actionParams) : to;
|
|
190
|
+
let targetActorRef;
|
|
191
|
+
if (typeof resolvedTarget === 'string') {
|
|
192
|
+
if (resolvedTarget === SpecialTargets.Parent) {
|
|
193
|
+
targetActorRef = actorScope?.self._parent;
|
|
194
|
+
} else if (resolvedTarget === SpecialTargets.Internal) {
|
|
195
|
+
targetActorRef = actorScope?.self;
|
|
196
|
+
} else if (resolvedTarget.startsWith('#_')) {
|
|
197
|
+
// SCXML compatibility: https://www.w3.org/TR/scxml/#SCXMLEventProcessor
|
|
198
|
+
// #_invokeid. If the target is the special term '#_invokeid', where invokeid is the invokeid of an SCXML session that the sending session has created by <invoke>, the Processor must add the event to the external queue of that session.
|
|
199
|
+
targetActorRef = snapshot.children[resolvedTarget.slice(2)];
|
|
200
|
+
} else {
|
|
201
|
+
targetActorRef = extra.deferredActorIds?.includes(resolvedTarget) ? resolvedTarget : snapshot.children[resolvedTarget];
|
|
202
|
+
}
|
|
203
|
+
if (!targetActorRef) {
|
|
204
|
+
throw new Error(`Unable to send event to actor '${resolvedTarget}' from machine '${snapshot.machine.id}'.`);
|
|
205
|
+
}
|
|
206
|
+
} else {
|
|
207
|
+
targetActorRef = resolvedTarget || actorScope?.self;
|
|
208
|
+
}
|
|
209
|
+
return [snapshot, {
|
|
210
|
+
to: targetActorRef,
|
|
211
|
+
event: resolvedEvent,
|
|
212
|
+
id,
|
|
213
|
+
delay: resolvedDelay
|
|
214
|
+
}];
|
|
215
|
+
}
|
|
216
|
+
function retryResolveSendTo(_, snapshot, params) {
|
|
217
|
+
if (typeof params.to === 'string') {
|
|
218
|
+
params.to = snapshot.children[params.to];
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
function executeSendTo(actorScope, params) {
|
|
222
|
+
if (typeof params.delay === 'number') {
|
|
223
|
+
actorScope.self.delaySend(params);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// this forms an outgoing events queue
|
|
228
|
+
// thanks to that the recipient actors are able to read the *updated* snapshot value of the sender
|
|
229
|
+
actorScope.defer(() => {
|
|
230
|
+
const {
|
|
231
|
+
to,
|
|
232
|
+
event
|
|
233
|
+
} = params;
|
|
234
|
+
actorScope?.system._relay(actorScope.self, to, event.type === guards_dist_xstateGuards.XSTATE_ERROR ? guards_dist_xstateGuards.createErrorActorEvent(actorScope.self.id, event.data) : event);
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Sends an event to an actor.
|
|
239
|
+
*
|
|
240
|
+
* @param actor The `ActorRef` to send the event to.
|
|
241
|
+
* @param event The event to send, or an expression that evaluates to the event to send
|
|
242
|
+
* @param options Send action options
|
|
243
|
+
* - `id` - The unique send event identifier (used with `cancel()`).
|
|
244
|
+
* - `delay` - The number of milliseconds to delay the sending of the event.
|
|
245
|
+
*/
|
|
246
|
+
function sendTo(to, eventOrExpr, options) {
|
|
247
|
+
function sendTo(args, params) {
|
|
248
|
+
{
|
|
249
|
+
throw new Error(`This isn't supposed to be called`);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
sendTo.type = 'xsnapshot.sendTo';
|
|
253
|
+
sendTo.to = to;
|
|
254
|
+
sendTo.event = eventOrExpr;
|
|
255
|
+
sendTo.id = options?.id;
|
|
256
|
+
sendTo.delay = options?.delay;
|
|
257
|
+
sendTo.resolve = resolveSendTo;
|
|
258
|
+
sendTo.retryResolve = retryResolveSendTo;
|
|
259
|
+
sendTo.execute = executeSendTo;
|
|
260
|
+
return sendTo;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Sends an event to this machine's parent.
|
|
265
|
+
*
|
|
266
|
+
* @param event The event to send to the parent machine.
|
|
267
|
+
* @param options Options to pass into the send event.
|
|
268
|
+
*/
|
|
269
|
+
function sendParent(event, options) {
|
|
270
|
+
return sendTo(SpecialTargets.Parent, event, options);
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Forwards (sends) an event to a specified service.
|
|
274
|
+
*
|
|
275
|
+
* @param target The target service to forward the event to.
|
|
276
|
+
* @param options Options to pass into the send action creator.
|
|
277
|
+
*/
|
|
278
|
+
function forwardTo(target, options) {
|
|
279
|
+
if ((!target || typeof target === 'function')) {
|
|
280
|
+
const originalTarget = target;
|
|
281
|
+
target = (...args) => {
|
|
282
|
+
const resolvedTarget = typeof originalTarget === 'function' ? originalTarget(...args) : originalTarget;
|
|
283
|
+
if (!resolvedTarget) {
|
|
284
|
+
throw new Error(`Attempted to forward event to undefined actor. This risks an infinite loop in the sender.`);
|
|
285
|
+
}
|
|
286
|
+
return resolvedTarget;
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
return sendTo(target, ({
|
|
290
|
+
event
|
|
291
|
+
}) => event, options);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function resolveEnqueueActions(_, snapshot, args, _actionParams, {
|
|
295
|
+
collect
|
|
296
|
+
}) {
|
|
297
|
+
const actions = [];
|
|
298
|
+
const enqueue = function enqueue(action) {
|
|
299
|
+
actions.push(action);
|
|
300
|
+
};
|
|
301
|
+
enqueue.assign = (...args) => {
|
|
302
|
+
actions.push(assign(...args));
|
|
303
|
+
};
|
|
304
|
+
enqueue.cancel = (...args) => {
|
|
305
|
+
actions.push(guards_dist_xstateGuards.cancel(...args));
|
|
306
|
+
};
|
|
307
|
+
enqueue.raise = (...args) => {
|
|
308
|
+
actions.push(guards_dist_xstateGuards.raise(...args));
|
|
309
|
+
};
|
|
310
|
+
enqueue.sendTo = (...args) => {
|
|
311
|
+
actions.push(sendTo(...args));
|
|
312
|
+
};
|
|
313
|
+
enqueue.spawnChild = (...args) => {
|
|
314
|
+
actions.push(guards_dist_xstateGuards.spawnChild(...args));
|
|
315
|
+
};
|
|
316
|
+
enqueue.stopChild = (...args) => {
|
|
317
|
+
actions.push(guards_dist_xstateGuards.stopChild(...args));
|
|
318
|
+
};
|
|
319
|
+
collect({
|
|
320
|
+
context: args.context,
|
|
321
|
+
event: args.event,
|
|
322
|
+
enqueue,
|
|
323
|
+
check: guard => guards_dist_xstateGuards.evaluateGuard(guard, snapshot.context, args.event, snapshot)
|
|
324
|
+
});
|
|
325
|
+
return [snapshot, undefined, actions];
|
|
326
|
+
}
|
|
327
|
+
function enqueueActions(collect) {
|
|
328
|
+
function enqueueActions(args, params) {
|
|
329
|
+
{
|
|
330
|
+
throw new Error(`This isn't supposed to be called`);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
enqueueActions.type = 'xstate.enqueueActions';
|
|
334
|
+
enqueueActions.collect = collect;
|
|
335
|
+
enqueueActions.resolve = resolveEnqueueActions;
|
|
336
|
+
return enqueueActions;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function resolveLog(_, snapshot, actionArgs, actionParams, {
|
|
340
|
+
value,
|
|
341
|
+
label
|
|
342
|
+
}) {
|
|
343
|
+
return [snapshot, {
|
|
344
|
+
value: typeof value === 'function' ? value(actionArgs, actionParams) : value,
|
|
345
|
+
label
|
|
346
|
+
}];
|
|
347
|
+
}
|
|
348
|
+
function executeLog({
|
|
349
|
+
logger
|
|
350
|
+
}, {
|
|
351
|
+
value,
|
|
352
|
+
label
|
|
353
|
+
}) {
|
|
354
|
+
if (label) {
|
|
355
|
+
logger(label, value);
|
|
356
|
+
} else {
|
|
357
|
+
logger(value);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
*
|
|
362
|
+
* @param expr The expression function to evaluate which will be logged.
|
|
363
|
+
* Takes in 2 arguments:
|
|
364
|
+
* - `ctx` - the current state context
|
|
365
|
+
* - `event` - the event that caused this action to be executed.
|
|
366
|
+
* @param label The label to give to the logged expression.
|
|
367
|
+
*/
|
|
368
|
+
function log(value = ({
|
|
369
|
+
context,
|
|
370
|
+
event
|
|
371
|
+
}) => ({
|
|
372
|
+
context,
|
|
373
|
+
event
|
|
374
|
+
}), label) {
|
|
375
|
+
function log(args, params) {
|
|
376
|
+
{
|
|
377
|
+
throw new Error(`This isn't supposed to be called`);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
log.type = 'xstate.log';
|
|
381
|
+
log.value = value;
|
|
382
|
+
log.label = label;
|
|
383
|
+
log.resolve = resolveLog;
|
|
384
|
+
log.execute = executeLog;
|
|
385
|
+
return log;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
exports.SpecialTargets = SpecialTargets;
|
|
389
|
+
exports.assign = assign;
|
|
390
|
+
exports.enqueueActions = enqueueActions;
|
|
391
|
+
exports.forwardTo = forwardTo;
|
|
392
|
+
exports.log = log;
|
|
393
|
+
exports.sendParent = sendParent;
|
|
394
|
+
exports.sendTo = sendTo;
|