xstate 5.4.1 → 5.5.1
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/actions/dist/xstate-actions.cjs.js +2 -2
- package/actions/dist/xstate-actions.development.cjs.js +2 -2
- package/actions/dist/xstate-actions.development.esm.js +2 -2
- package/actions/dist/xstate-actions.esm.js +2 -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.js +1 -1
- package/actors/dist/xstate-actors.development.cjs.js +1 -1
- package/actors/dist/xstate-actors.development.esm.js +1 -1
- package/actors/dist/xstate-actors.esm.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/declarations/src/State.d.ts +30 -3
- package/dist/declarations/src/StateMachine.d.ts +3 -3
- package/dist/declarations/src/StateNode.d.ts +0 -4
- package/dist/declarations/src/actions/assign.d.ts +28 -1
- package/dist/declarations/src/actions/cancel.d.ts +23 -4
- package/dist/declarations/src/actions/enqueueActions.d.ts +20 -0
- package/dist/declarations/src/actions/send.d.ts +2 -2
- package/dist/declarations/src/createActor.d.ts +0 -1
- package/dist/declarations/src/createMachine.d.ts +40 -0
- package/dist/declarations/src/getNextSnapshot.d.ts +32 -0
- package/dist/declarations/src/guards.d.ts +86 -0
- package/dist/declarations/src/index.d.ts +1 -0
- package/dist/declarations/src/spawn.d.ts +2 -2
- package/dist/declarations/src/typegenTypes.d.ts +26 -1
- package/dist/declarations/src/types.d.ts +9 -29
- package/dist/{log-88b333eb.esm.js → log-22b3587f.esm.js} +67 -10
- package/dist/{log-11038f00.development.esm.js → log-285f62db.development.esm.js} +67 -10
- package/dist/{log-2580e864.cjs.js → log-742895c6.cjs.js} +67 -10
- package/dist/{log-18eb632d.development.cjs.js → log-da322832.development.cjs.js} +67 -10
- package/dist/{raise-3b380e4b.esm.js → raise-0e64ee6e.esm.js} +124 -13
- package/dist/{raise-3d3d6d51.development.cjs.js → raise-7af39710.development.cjs.js} +124 -13
- package/dist/{raise-057d17af.development.esm.js → raise-8da27ebb.development.esm.js} +124 -13
- package/dist/{raise-5c58eb8e.cjs.js → raise-ad8bb7c2.cjs.js} +124 -13
- package/dist/xstate.cjs.js +105 -4
- package/dist/xstate.cjs.mjs +1 -0
- package/dist/xstate.development.cjs.js +105 -4
- package/dist/xstate.development.cjs.mjs +1 -0
- package/dist/xstate.development.esm.js +107 -7
- package/dist/xstate.esm.js +107 -7
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.js +1 -1
- package/guards/dist/xstate-guards.development.cjs.js +1 -1
- package/guards/dist/xstate-guards.development.esm.js +1 -1
- package/guards/dist/xstate-guards.esm.js +1 -1
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { R as ProcessingStatus, y as resolveReferencedActor, z as createActor, T as cloneMachineSnapshot, U as XSTATE_ERROR, V as createErrorActorEvent, e as evaluateGuard, L as cancel, M as raise, O as spawnChild, Q as stopChild } from './raise-
|
|
1
|
+
import { R as ProcessingStatus, y as resolveReferencedActor, z as createActor, T as cloneMachineSnapshot, U as XSTATE_ERROR, V as createErrorActorEvent, e as evaluateGuard, L as cancel, M as raise, O as spawnChild, Q as stopChild } from './raise-8da27ebb.development.esm.js';
|
|
2
2
|
|
|
3
3
|
// it's likely-ish that `(TActor & { src: TSrc })['logic']` would be faster
|
|
4
4
|
// but it's only possible to do it since https://github.com/microsoft/TypeScript/pull/53098 (TS 5.1)
|
|
@@ -67,8 +67,8 @@ function resolveAssign(actorScope, snapshot, actionArgs, actionParams, {
|
|
|
67
67
|
context: snapshot.context,
|
|
68
68
|
event: actionArgs.event,
|
|
69
69
|
spawn: createSpawner(actorScope, snapshot, actionArgs.event, spawnedChildren),
|
|
70
|
-
self: actorScope
|
|
71
|
-
system: actorScope
|
|
70
|
+
self: actorScope.self,
|
|
71
|
+
system: actorScope.system
|
|
72
72
|
};
|
|
73
73
|
let partialUpdate = {};
|
|
74
74
|
if (typeof assignment === 'function') {
|
|
@@ -91,7 +91,34 @@ function resolveAssign(actorScope, snapshot, actionArgs, actionParams, {
|
|
|
91
91
|
/**
|
|
92
92
|
* Updates the current context of the machine.
|
|
93
93
|
*
|
|
94
|
-
* @param assignment An object that represents the partial context to update
|
|
94
|
+
* @param assignment An object that represents the partial context to update, or a
|
|
95
|
+
* function that returns an object that represents the partial context to update.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
```ts
|
|
99
|
+
import { createMachine, assign } from 'xstate';
|
|
100
|
+
|
|
101
|
+
const countMachine = createMachine({
|
|
102
|
+
context: {
|
|
103
|
+
count: 0,
|
|
104
|
+
message: ''
|
|
105
|
+
},
|
|
106
|
+
on: {
|
|
107
|
+
inc: {
|
|
108
|
+
actions: assign({
|
|
109
|
+
count: ({ context }) => context.count + 1
|
|
110
|
+
})
|
|
111
|
+
},
|
|
112
|
+
updateMessage: {
|
|
113
|
+
actions: assign(({ context, event }) => {
|
|
114
|
+
return {
|
|
115
|
+
message: event.message.trim()
|
|
116
|
+
}
|
|
117
|
+
})
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
```
|
|
95
122
|
*/
|
|
96
123
|
function assign(assignment) {
|
|
97
124
|
function assign(args, params) {
|
|
@@ -141,7 +168,9 @@ function assign(assignment) {
|
|
|
141
168
|
/** @deprecated use `AnyMachineSnapshot` instead */
|
|
142
169
|
|
|
143
170
|
// TODO: possibly refactor this somehow, use even a simpler type, and maybe even make `machine.options` private or something
|
|
144
|
-
|
|
171
|
+
/**
|
|
172
|
+
* @internal
|
|
173
|
+
*/
|
|
145
174
|
let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
146
175
|
SpecialTargets["Parent"] = "#_parent";
|
|
147
176
|
SpecialTargets["Internal"] = "#_internal";
|
|
@@ -154,6 +183,14 @@ let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
|
154
183
|
|
|
155
184
|
// Based on RxJS types
|
|
156
185
|
|
|
186
|
+
/**
|
|
187
|
+
* @internal
|
|
188
|
+
*/
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* @internal
|
|
192
|
+
*/
|
|
193
|
+
|
|
157
194
|
/**
|
|
158
195
|
* @deprecated Use `Actor<T>` instead.
|
|
159
196
|
*/
|
|
@@ -191,9 +228,9 @@ function resolveSendTo(actorScope, snapshot, args, actionParams, {
|
|
|
191
228
|
let targetActorRef;
|
|
192
229
|
if (typeof resolvedTarget === 'string') {
|
|
193
230
|
if (resolvedTarget === SpecialTargets.Parent) {
|
|
194
|
-
targetActorRef = actorScope
|
|
231
|
+
targetActorRef = actorScope.self._parent;
|
|
195
232
|
} else if (resolvedTarget === SpecialTargets.Internal) {
|
|
196
|
-
targetActorRef = actorScope
|
|
233
|
+
targetActorRef = actorScope.self;
|
|
197
234
|
} else if (resolvedTarget.startsWith('#_')) {
|
|
198
235
|
// SCXML compatibility: https://www.w3.org/TR/scxml/#SCXMLEventProcessor
|
|
199
236
|
// #_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.
|
|
@@ -205,7 +242,7 @@ function resolveSendTo(actorScope, snapshot, args, actionParams, {
|
|
|
205
242
|
throw new Error(`Unable to send event to actor '${resolvedTarget}' from machine '${snapshot.machine.id}'.`);
|
|
206
243
|
}
|
|
207
244
|
} else {
|
|
208
|
-
targetActorRef = resolvedTarget || actorScope
|
|
245
|
+
targetActorRef = resolvedTarget || actorScope.self;
|
|
209
246
|
}
|
|
210
247
|
return [snapshot, {
|
|
211
248
|
to: targetActorRef,
|
|
@@ -275,9 +312,9 @@ function sendParent(event, options) {
|
|
|
275
312
|
return sendTo(SpecialTargets.Parent, event, options);
|
|
276
313
|
}
|
|
277
314
|
/**
|
|
278
|
-
* Forwards (sends) an event to
|
|
315
|
+
* Forwards (sends) an event to the `target` actor.
|
|
279
316
|
*
|
|
280
|
-
* @param target The target
|
|
317
|
+
* @param target The target actor to forward the event to.
|
|
281
318
|
* @param options Options to pass into the send action creator.
|
|
282
319
|
*/
|
|
283
320
|
function forwardTo(target, options) {
|
|
@@ -331,6 +368,26 @@ function resolveEnqueueActions(actorScope, snapshot, args, _actionParams, {
|
|
|
331
368
|
});
|
|
332
369
|
return [snapshot, undefined, actions];
|
|
333
370
|
}
|
|
371
|
+
/**
|
|
372
|
+
* Creates an action object that will execute actions that are queued by the `enqueue(action)` function.
|
|
373
|
+
*
|
|
374
|
+
* @example
|
|
375
|
+
```ts
|
|
376
|
+
import { createMachine, enqueueActions } from 'xstate';
|
|
377
|
+
|
|
378
|
+
const machine = createMachine({
|
|
379
|
+
entry: enqueueActions(({ enqueue, check }) => {
|
|
380
|
+
enqueue.assign({ count: 0 });
|
|
381
|
+
|
|
382
|
+
if (check('someGuard')) {
|
|
383
|
+
enqueue.assign({ count: 1 });
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
enqueue('someAction');
|
|
387
|
+
})
|
|
388
|
+
})
|
|
389
|
+
```
|
|
390
|
+
*/
|
|
334
391
|
function enqueueActions(collect) {
|
|
335
392
|
function enqueueActions(args, params) {
|
|
336
393
|
{
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
3
|
+
var guards_dist_xstateGuards = require('./raise-ad8bb7c2.cjs.js');
|
|
4
4
|
|
|
5
5
|
// it's likely-ish that `(TActor & { src: TSrc })['logic']` would be faster
|
|
6
6
|
// but it's only possible to do it since https://github.com/microsoft/TypeScript/pull/53098 (TS 5.1)
|
|
@@ -69,8 +69,8 @@ function resolveAssign(actorScope, snapshot, actionArgs, actionParams, {
|
|
|
69
69
|
context: snapshot.context,
|
|
70
70
|
event: actionArgs.event,
|
|
71
71
|
spawn: createSpawner(actorScope, snapshot, actionArgs.event, spawnedChildren),
|
|
72
|
-
self: actorScope
|
|
73
|
-
system: actorScope
|
|
72
|
+
self: actorScope.self,
|
|
73
|
+
system: actorScope.system
|
|
74
74
|
};
|
|
75
75
|
let partialUpdate = {};
|
|
76
76
|
if (typeof assignment === 'function') {
|
|
@@ -93,7 +93,34 @@ function resolveAssign(actorScope, snapshot, actionArgs, actionParams, {
|
|
|
93
93
|
/**
|
|
94
94
|
* Updates the current context of the machine.
|
|
95
95
|
*
|
|
96
|
-
* @param assignment An object that represents the partial context to update
|
|
96
|
+
* @param assignment An object that represents the partial context to update, or a
|
|
97
|
+
* function that returns an object that represents the partial context to update.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
```ts
|
|
101
|
+
import { createMachine, assign } from 'xstate';
|
|
102
|
+
|
|
103
|
+
const countMachine = createMachine({
|
|
104
|
+
context: {
|
|
105
|
+
count: 0,
|
|
106
|
+
message: ''
|
|
107
|
+
},
|
|
108
|
+
on: {
|
|
109
|
+
inc: {
|
|
110
|
+
actions: assign({
|
|
111
|
+
count: ({ context }) => context.count + 1
|
|
112
|
+
})
|
|
113
|
+
},
|
|
114
|
+
updateMessage: {
|
|
115
|
+
actions: assign(({ context, event }) => {
|
|
116
|
+
return {
|
|
117
|
+
message: event.message.trim()
|
|
118
|
+
}
|
|
119
|
+
})
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
```
|
|
97
124
|
*/
|
|
98
125
|
function assign(assignment) {
|
|
99
126
|
function assign(args, params) {
|
|
@@ -140,7 +167,9 @@ function assign(assignment) {
|
|
|
140
167
|
/** @deprecated use `AnyMachineSnapshot` instead */
|
|
141
168
|
|
|
142
169
|
// TODO: possibly refactor this somehow, use even a simpler type, and maybe even make `machine.options` private or something
|
|
143
|
-
|
|
170
|
+
/**
|
|
171
|
+
* @internal
|
|
172
|
+
*/
|
|
144
173
|
let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
145
174
|
SpecialTargets["Parent"] = "#_parent";
|
|
146
175
|
SpecialTargets["Internal"] = "#_internal";
|
|
@@ -153,6 +182,14 @@ let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
|
153
182
|
|
|
154
183
|
// Based on RxJS types
|
|
155
184
|
|
|
185
|
+
/**
|
|
186
|
+
* @internal
|
|
187
|
+
*/
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* @internal
|
|
191
|
+
*/
|
|
192
|
+
|
|
156
193
|
/**
|
|
157
194
|
* @deprecated Use `Actor<T>` instead.
|
|
158
195
|
*/
|
|
@@ -190,9 +227,9 @@ function resolveSendTo(actorScope, snapshot, args, actionParams, {
|
|
|
190
227
|
let targetActorRef;
|
|
191
228
|
if (typeof resolvedTarget === 'string') {
|
|
192
229
|
if (resolvedTarget === SpecialTargets.Parent) {
|
|
193
|
-
targetActorRef = actorScope
|
|
230
|
+
targetActorRef = actorScope.self._parent;
|
|
194
231
|
} else if (resolvedTarget === SpecialTargets.Internal) {
|
|
195
|
-
targetActorRef = actorScope
|
|
232
|
+
targetActorRef = actorScope.self;
|
|
196
233
|
} else if (resolvedTarget.startsWith('#_')) {
|
|
197
234
|
// SCXML compatibility: https://www.w3.org/TR/scxml/#SCXMLEventProcessor
|
|
198
235
|
// #_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.
|
|
@@ -204,7 +241,7 @@ function resolveSendTo(actorScope, snapshot, args, actionParams, {
|
|
|
204
241
|
throw new Error(`Unable to send event to actor '${resolvedTarget}' from machine '${snapshot.machine.id}'.`);
|
|
205
242
|
}
|
|
206
243
|
} else {
|
|
207
|
-
targetActorRef = resolvedTarget || actorScope
|
|
244
|
+
targetActorRef = resolvedTarget || actorScope.self;
|
|
208
245
|
}
|
|
209
246
|
return [snapshot, {
|
|
210
247
|
to: targetActorRef,
|
|
@@ -271,9 +308,9 @@ function sendParent(event, options) {
|
|
|
271
308
|
return sendTo(SpecialTargets.Parent, event, options);
|
|
272
309
|
}
|
|
273
310
|
/**
|
|
274
|
-
* Forwards (sends) an event to
|
|
311
|
+
* Forwards (sends) an event to the `target` actor.
|
|
275
312
|
*
|
|
276
|
-
* @param target The target
|
|
313
|
+
* @param target The target actor to forward the event to.
|
|
277
314
|
* @param options Options to pass into the send action creator.
|
|
278
315
|
*/
|
|
279
316
|
function forwardTo(target, options) {
|
|
@@ -317,6 +354,26 @@ function resolveEnqueueActions(actorScope, snapshot, args, _actionParams, {
|
|
|
317
354
|
});
|
|
318
355
|
return [snapshot, undefined, actions];
|
|
319
356
|
}
|
|
357
|
+
/**
|
|
358
|
+
* Creates an action object that will execute actions that are queued by the `enqueue(action)` function.
|
|
359
|
+
*
|
|
360
|
+
* @example
|
|
361
|
+
```ts
|
|
362
|
+
import { createMachine, enqueueActions } from 'xstate';
|
|
363
|
+
|
|
364
|
+
const machine = createMachine({
|
|
365
|
+
entry: enqueueActions(({ enqueue, check }) => {
|
|
366
|
+
enqueue.assign({ count: 0 });
|
|
367
|
+
|
|
368
|
+
if (check('someGuard')) {
|
|
369
|
+
enqueue.assign({ count: 1 });
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
enqueue('someAction');
|
|
373
|
+
})
|
|
374
|
+
})
|
|
375
|
+
```
|
|
376
|
+
*/
|
|
320
377
|
function enqueueActions(collect) {
|
|
321
378
|
function enqueueActions(args, params) {
|
|
322
379
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
3
|
+
var guards_dist_xstateGuards = require('./raise-7af39710.development.cjs.js');
|
|
4
4
|
|
|
5
5
|
// it's likely-ish that `(TActor & { src: TSrc })['logic']` would be faster
|
|
6
6
|
// but it's only possible to do it since https://github.com/microsoft/TypeScript/pull/53098 (TS 5.1)
|
|
@@ -69,8 +69,8 @@ function resolveAssign(actorScope, snapshot, actionArgs, actionParams, {
|
|
|
69
69
|
context: snapshot.context,
|
|
70
70
|
event: actionArgs.event,
|
|
71
71
|
spawn: createSpawner(actorScope, snapshot, actionArgs.event, spawnedChildren),
|
|
72
|
-
self: actorScope
|
|
73
|
-
system: actorScope
|
|
72
|
+
self: actorScope.self,
|
|
73
|
+
system: actorScope.system
|
|
74
74
|
};
|
|
75
75
|
let partialUpdate = {};
|
|
76
76
|
if (typeof assignment === 'function') {
|
|
@@ -93,7 +93,34 @@ function resolveAssign(actorScope, snapshot, actionArgs, actionParams, {
|
|
|
93
93
|
/**
|
|
94
94
|
* Updates the current context of the machine.
|
|
95
95
|
*
|
|
96
|
-
* @param assignment An object that represents the partial context to update
|
|
96
|
+
* @param assignment An object that represents the partial context to update, or a
|
|
97
|
+
* function that returns an object that represents the partial context to update.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
```ts
|
|
101
|
+
import { createMachine, assign } from 'xstate';
|
|
102
|
+
|
|
103
|
+
const countMachine = createMachine({
|
|
104
|
+
context: {
|
|
105
|
+
count: 0,
|
|
106
|
+
message: ''
|
|
107
|
+
},
|
|
108
|
+
on: {
|
|
109
|
+
inc: {
|
|
110
|
+
actions: assign({
|
|
111
|
+
count: ({ context }) => context.count + 1
|
|
112
|
+
})
|
|
113
|
+
},
|
|
114
|
+
updateMessage: {
|
|
115
|
+
actions: assign(({ context, event }) => {
|
|
116
|
+
return {
|
|
117
|
+
message: event.message.trim()
|
|
118
|
+
}
|
|
119
|
+
})
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
```
|
|
97
124
|
*/
|
|
98
125
|
function assign(assignment) {
|
|
99
126
|
function assign(args, params) {
|
|
@@ -143,7 +170,9 @@ function assign(assignment) {
|
|
|
143
170
|
/** @deprecated use `AnyMachineSnapshot` instead */
|
|
144
171
|
|
|
145
172
|
// TODO: possibly refactor this somehow, use even a simpler type, and maybe even make `machine.options` private or something
|
|
146
|
-
|
|
173
|
+
/**
|
|
174
|
+
* @internal
|
|
175
|
+
*/
|
|
147
176
|
let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
148
177
|
SpecialTargets["Parent"] = "#_parent";
|
|
149
178
|
SpecialTargets["Internal"] = "#_internal";
|
|
@@ -156,6 +185,14 @@ let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
|
156
185
|
|
|
157
186
|
// Based on RxJS types
|
|
158
187
|
|
|
188
|
+
/**
|
|
189
|
+
* @internal
|
|
190
|
+
*/
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* @internal
|
|
194
|
+
*/
|
|
195
|
+
|
|
159
196
|
/**
|
|
160
197
|
* @deprecated Use `Actor<T>` instead.
|
|
161
198
|
*/
|
|
@@ -193,9 +230,9 @@ function resolveSendTo(actorScope, snapshot, args, actionParams, {
|
|
|
193
230
|
let targetActorRef;
|
|
194
231
|
if (typeof resolvedTarget === 'string') {
|
|
195
232
|
if (resolvedTarget === SpecialTargets.Parent) {
|
|
196
|
-
targetActorRef = actorScope
|
|
233
|
+
targetActorRef = actorScope.self._parent;
|
|
197
234
|
} else if (resolvedTarget === SpecialTargets.Internal) {
|
|
198
|
-
targetActorRef = actorScope
|
|
235
|
+
targetActorRef = actorScope.self;
|
|
199
236
|
} else if (resolvedTarget.startsWith('#_')) {
|
|
200
237
|
// SCXML compatibility: https://www.w3.org/TR/scxml/#SCXMLEventProcessor
|
|
201
238
|
// #_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.
|
|
@@ -207,7 +244,7 @@ function resolveSendTo(actorScope, snapshot, args, actionParams, {
|
|
|
207
244
|
throw new Error(`Unable to send event to actor '${resolvedTarget}' from machine '${snapshot.machine.id}'.`);
|
|
208
245
|
}
|
|
209
246
|
} else {
|
|
210
|
-
targetActorRef = resolvedTarget || actorScope
|
|
247
|
+
targetActorRef = resolvedTarget || actorScope.self;
|
|
211
248
|
}
|
|
212
249
|
return [snapshot, {
|
|
213
250
|
to: targetActorRef,
|
|
@@ -277,9 +314,9 @@ function sendParent(event, options) {
|
|
|
277
314
|
return sendTo(SpecialTargets.Parent, event, options);
|
|
278
315
|
}
|
|
279
316
|
/**
|
|
280
|
-
* Forwards (sends) an event to
|
|
317
|
+
* Forwards (sends) an event to the `target` actor.
|
|
281
318
|
*
|
|
282
|
-
* @param target The target
|
|
319
|
+
* @param target The target actor to forward the event to.
|
|
283
320
|
* @param options Options to pass into the send action creator.
|
|
284
321
|
*/
|
|
285
322
|
function forwardTo(target, options) {
|
|
@@ -333,6 +370,26 @@ function resolveEnqueueActions(actorScope, snapshot, args, _actionParams, {
|
|
|
333
370
|
});
|
|
334
371
|
return [snapshot, undefined, actions];
|
|
335
372
|
}
|
|
373
|
+
/**
|
|
374
|
+
* Creates an action object that will execute actions that are queued by the `enqueue(action)` function.
|
|
375
|
+
*
|
|
376
|
+
* @example
|
|
377
|
+
```ts
|
|
378
|
+
import { createMachine, enqueueActions } from 'xstate';
|
|
379
|
+
|
|
380
|
+
const machine = createMachine({
|
|
381
|
+
entry: enqueueActions(({ enqueue, check }) => {
|
|
382
|
+
enqueue.assign({ count: 0 });
|
|
383
|
+
|
|
384
|
+
if (check('someGuard')) {
|
|
385
|
+
enqueue.assign({ count: 1 });
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
enqueue('someAction');
|
|
389
|
+
})
|
|
390
|
+
})
|
|
391
|
+
```
|
|
392
|
+
*/
|
|
336
393
|
function enqueueActions(collect) {
|
|
337
394
|
function enqueueActions(args, params) {
|
|
338
395
|
{
|
|
@@ -431,6 +431,7 @@ class Actor {
|
|
|
431
431
|
this._processingStatus = ProcessingStatus.NotStarted;
|
|
432
432
|
// Actor Ref
|
|
433
433
|
this._parent = void 0;
|
|
434
|
+
/** @internal */
|
|
434
435
|
this._syncSnapshot = void 0;
|
|
435
436
|
this.ref = void 0;
|
|
436
437
|
// TODO: add typings for system
|
|
@@ -999,11 +1000,30 @@ function executeCancel(actorScope, resolvedSendId) {
|
|
|
999
1000
|
});
|
|
1000
1001
|
}
|
|
1001
1002
|
/**
|
|
1002
|
-
* Cancels
|
|
1003
|
-
*
|
|
1004
|
-
* (e.g., if `cancel(...)` is called after the `send(...)` action's `delay`).
|
|
1003
|
+
* Cancels a delayed `sendTo(...)` action that is waiting to be executed. The canceled `sendTo(...)` action
|
|
1004
|
+
* will not send its event or execute, unless the `delay` has already elapsed before `cancel(...)` is called.
|
|
1005
1005
|
*
|
|
1006
|
-
* @param sendId The `id` of the `
|
|
1006
|
+
* @param sendId The `id` of the `sendTo(...)` action to cancel.
|
|
1007
|
+
*
|
|
1008
|
+
* @example
|
|
1009
|
+
```ts
|
|
1010
|
+
import { createMachine, sendTo, cancel } from 'xstate';
|
|
1011
|
+
|
|
1012
|
+
const machine = createMachine({
|
|
1013
|
+
// ...
|
|
1014
|
+
on: {
|
|
1015
|
+
sendEvent: {
|
|
1016
|
+
actions: sendTo('some-actor', { type: 'someEvent' }, {
|
|
1017
|
+
id: 'some-id',
|
|
1018
|
+
delay: 1000
|
|
1019
|
+
})
|
|
1020
|
+
},
|
|
1021
|
+
cancelEvent: {
|
|
1022
|
+
actions: cancel('some-id')
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
});
|
|
1026
|
+
```
|
|
1007
1027
|
*/
|
|
1008
1028
|
function cancel(sendId) {
|
|
1009
1029
|
function cancel(args, params) {
|
|
@@ -1029,13 +1049,13 @@ function resolveSpawn(actorScope, snapshot, actionArgs, _actionParams, {
|
|
|
1029
1049
|
actorRef = createActor(logic, {
|
|
1030
1050
|
id: resolvedId,
|
|
1031
1051
|
src,
|
|
1032
|
-
parent: actorScope
|
|
1052
|
+
parent: actorScope.self,
|
|
1033
1053
|
syncSnapshot,
|
|
1034
1054
|
systemId,
|
|
1035
1055
|
input: typeof input === 'function' ? input({
|
|
1036
1056
|
context: snapshot.context,
|
|
1037
1057
|
event: actionArgs.event,
|
|
1038
|
-
self: actorScope
|
|
1058
|
+
self: actorScope.self
|
|
1039
1059
|
}) : input
|
|
1040
1060
|
});
|
|
1041
1061
|
}
|
|
@@ -1169,6 +1189,33 @@ function checkNot(snapshot, {
|
|
|
1169
1189
|
}) {
|
|
1170
1190
|
return !evaluateGuard(guards[0], context, event, snapshot);
|
|
1171
1191
|
}
|
|
1192
|
+
|
|
1193
|
+
/**
|
|
1194
|
+
* Higher-order guard that evaluates to `true` if the `guard` passed to it evaluates to `false`.
|
|
1195
|
+
*
|
|
1196
|
+
* @category Guards
|
|
1197
|
+
* @example
|
|
1198
|
+
```ts
|
|
1199
|
+
import { setup, not } from 'xstate';
|
|
1200
|
+
|
|
1201
|
+
const machine = setup({
|
|
1202
|
+
guards: {
|
|
1203
|
+
someNamedGuard: () => false
|
|
1204
|
+
}
|
|
1205
|
+
}).createMachine({
|
|
1206
|
+
on: {
|
|
1207
|
+
someEvent: {
|
|
1208
|
+
guard: not('someNamedGuard'),
|
|
1209
|
+
actions: () => {
|
|
1210
|
+
// will be executed if guard in `not(...)`
|
|
1211
|
+
// evaluates to `false`
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
});
|
|
1216
|
+
```
|
|
1217
|
+
* @returns A guard
|
|
1218
|
+
*/
|
|
1172
1219
|
function not(guard) {
|
|
1173
1220
|
function not(args, params) {
|
|
1174
1221
|
return false;
|
|
@@ -1185,6 +1232,37 @@ function checkAnd(snapshot, {
|
|
|
1185
1232
|
}) {
|
|
1186
1233
|
return guards.every(guard => evaluateGuard(guard, context, event, snapshot));
|
|
1187
1234
|
}
|
|
1235
|
+
|
|
1236
|
+
/**
|
|
1237
|
+
* Higher-order guard that evaluates to `true` if all `guards` passed to it
|
|
1238
|
+
* evaluate to `true`.
|
|
1239
|
+
*
|
|
1240
|
+
* @category Guards
|
|
1241
|
+
* @example
|
|
1242
|
+
```ts
|
|
1243
|
+
import { setup, and } from 'xstate';
|
|
1244
|
+
|
|
1245
|
+
const machine = setup({
|
|
1246
|
+
guards: {
|
|
1247
|
+
someNamedGuard: () => true
|
|
1248
|
+
}
|
|
1249
|
+
}).createMachine({
|
|
1250
|
+
on: {
|
|
1251
|
+
someEvent: {
|
|
1252
|
+
guard: and([
|
|
1253
|
+
({ context }) => context.value > 0,
|
|
1254
|
+
'someNamedGuard'
|
|
1255
|
+
]),
|
|
1256
|
+
actions: () => {
|
|
1257
|
+
// will be executed if all guards in `and(...)`
|
|
1258
|
+
// evaluate to true
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
});
|
|
1263
|
+
```
|
|
1264
|
+
* @returns A guard action object
|
|
1265
|
+
*/
|
|
1188
1266
|
function and(guards) {
|
|
1189
1267
|
function and(args, params) {
|
|
1190
1268
|
return false;
|
|
@@ -1201,6 +1279,37 @@ function checkOr(snapshot, {
|
|
|
1201
1279
|
}) {
|
|
1202
1280
|
return guards.some(guard => evaluateGuard(guard, context, event, snapshot));
|
|
1203
1281
|
}
|
|
1282
|
+
|
|
1283
|
+
/**
|
|
1284
|
+
* Higher-order guard that evaluates to `true` if any of the `guards` passed to it
|
|
1285
|
+
* evaluate to `true`.
|
|
1286
|
+
*
|
|
1287
|
+
* @category Guards
|
|
1288
|
+
* @example
|
|
1289
|
+
```ts
|
|
1290
|
+
import { setup, or } from 'xstate';
|
|
1291
|
+
|
|
1292
|
+
const machine = setup({
|
|
1293
|
+
guards: {
|
|
1294
|
+
someNamedGuard: () => true
|
|
1295
|
+
}
|
|
1296
|
+
}).createMachine({
|
|
1297
|
+
on: {
|
|
1298
|
+
someEvent: {
|
|
1299
|
+
guard: or([
|
|
1300
|
+
({ context }) => context.value > 0,
|
|
1301
|
+
'someNamedGuard'
|
|
1302
|
+
]),
|
|
1303
|
+
actions: () => {
|
|
1304
|
+
// will be executed if any of the guards in `or(...)`
|
|
1305
|
+
// evaluate to true
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
});
|
|
1310
|
+
```
|
|
1311
|
+
* @returns A guard action object
|
|
1312
|
+
*/
|
|
1204
1313
|
function or(guards) {
|
|
1205
1314
|
function or(args, params) {
|
|
1206
1315
|
return false;
|
|
@@ -2045,18 +2154,18 @@ function resolveActionsAndContextWorker(currentSnapshot, event, actorScope, acti
|
|
|
2045
2154
|
const actionArgs = {
|
|
2046
2155
|
context: intermediateSnapshot.context,
|
|
2047
2156
|
event,
|
|
2048
|
-
self: actorScope
|
|
2049
|
-
system: actorScope
|
|
2157
|
+
self: actorScope.self,
|
|
2158
|
+
system: actorScope.system
|
|
2050
2159
|
};
|
|
2051
2160
|
const actionParams = isInline || typeof action === 'string' ? undefined : 'params' in action ? typeof action.params === 'function' ? action.params({
|
|
2052
2161
|
context: intermediateSnapshot.context,
|
|
2053
2162
|
event
|
|
2054
2163
|
}) : action.params : undefined;
|
|
2055
2164
|
if (!('resolve' in resolvedAction)) {
|
|
2056
|
-
if (actorScope
|
|
2165
|
+
if (actorScope.self._processingStatus === ProcessingStatus.Running) {
|
|
2057
2166
|
resolvedAction(actionArgs, actionParams);
|
|
2058
2167
|
} else {
|
|
2059
|
-
actorScope
|
|
2168
|
+
actorScope.defer(() => {
|
|
2060
2169
|
resolvedAction(actionArgs, actionParams);
|
|
2061
2170
|
});
|
|
2062
2171
|
}
|
|
@@ -2071,10 +2180,10 @@ function resolveActionsAndContextWorker(currentSnapshot, event, actorScope, acti
|
|
|
2071
2180
|
retries?.push([builtinAction, params]);
|
|
2072
2181
|
}
|
|
2073
2182
|
if ('execute' in builtinAction) {
|
|
2074
|
-
if (actorScope
|
|
2183
|
+
if (actorScope.self._processingStatus === ProcessingStatus.Running) {
|
|
2075
2184
|
builtinAction.execute(actorScope, params);
|
|
2076
2185
|
} else {
|
|
2077
|
-
actorScope
|
|
2186
|
+
actorScope.defer(builtinAction.execute.bind(null, actorScope, params));
|
|
2078
2187
|
}
|
|
2079
2188
|
}
|
|
2080
2189
|
if (actions) {
|
|
@@ -2131,7 +2240,9 @@ function macrostep(snapshot, event, actorScope, internalQueue = []) {
|
|
|
2131
2240
|
microstates: states
|
|
2132
2241
|
};
|
|
2133
2242
|
}
|
|
2134
|
-
nextSnapshot = microstep(transitions, snapshot, actorScope, nextEvent, false,
|
|
2243
|
+
nextSnapshot = microstep(transitions, snapshot, actorScope, nextEvent, false,
|
|
2244
|
+
// isInitial
|
|
2245
|
+
internalQueue);
|
|
2135
2246
|
states.push(nextSnapshot);
|
|
2136
2247
|
}
|
|
2137
2248
|
let shouldSelectEventlessTransitions = true;
|