xstate 5.13.2 → 5.15.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/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 +289 -79
- package/actors/dist/xstate-actors.development.cjs.js +289 -79
- package/actors/dist/xstate-actors.development.esm.js +289 -79
- package/actors/dist/xstate-actors.esm.js +289 -79
- package/actors/dist/xstate-actors.umd.min.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/declarations/src/State.d.ts +21 -25
- package/dist/declarations/src/StateMachine.d.ts +18 -30
- package/dist/declarations/src/StateNode.d.ts +29 -51
- package/dist/declarations/src/actions/assign.d.ts +29 -27
- package/dist/declarations/src/actions/cancel.d.ts +28 -22
- package/dist/declarations/src/actions/emit.d.ts +33 -33
- package/dist/declarations/src/actions/enqueueActions.d.ts +18 -16
- package/dist/declarations/src/actions/log.d.ts +5 -4
- package/dist/declarations/src/actions/send.d.ts +5 -3
- package/dist/declarations/src/actors/callback.d.ts +69 -29
- package/dist/declarations/src/actors/index.d.ts +4 -4
- package/dist/declarations/src/actors/observable.d.ts +74 -29
- package/dist/declarations/src/actors/promise.d.ts +91 -13
- package/dist/declarations/src/actors/transition.d.ts +90 -16
- package/dist/declarations/src/assert.d.ts +21 -20
- package/dist/declarations/src/createActor.d.ts +51 -42
- package/dist/declarations/src/createMachine.d.ts +40 -54
- package/dist/declarations/src/getNextSnapshot.d.ts +27 -24
- package/dist/declarations/src/guards.d.ts +67 -66
- package/dist/declarations/src/index.d.ts +0 -1
- package/dist/declarations/src/inspection.d.ts +1 -0
- package/dist/declarations/src/setup.d.ts +1 -2
- package/dist/declarations/src/spawn.d.ts +2 -5
- package/dist/declarations/src/stateUtils.d.ts +5 -10
- package/dist/declarations/src/system.d.ts +2 -2
- package/dist/declarations/src/toPromise.d.ts +1 -0
- package/dist/declarations/src/types.d.ts +169 -192
- package/dist/declarations/src/waitFor.d.ts +9 -9
- package/dist/{log-c447a931.esm.js → log-63de2429.esm.js} +112 -117
- package/dist/{log-5b14d850.cjs.js → log-b8c93ee3.cjs.js} +112 -117
- package/dist/{log-d06dd00b.development.cjs.js → log-d2c282d6.development.cjs.js} +112 -117
- package/dist/{log-b3b03961.development.esm.js → log-e9953143.development.esm.js} +112 -117
- package/dist/{raise-f406edbd.esm.js → raise-2cfe6b8f.esm.js} +302 -284
- package/dist/{raise-150d5679.development.esm.js → raise-7d030497.development.esm.js} +302 -284
- package/dist/{raise-ff8990f7.cjs.js → raise-a6298350.cjs.js} +302 -284
- package/dist/{raise-bf7a8462.development.cjs.js → raise-bad6a97b.development.cjs.js} +302 -284
- package/dist/xstate.cjs.js +134 -157
- package/dist/xstate.development.cjs.js +134 -157
- package/dist/xstate.development.esm.js +136 -159
- package/dist/xstate.esm.js +136 -159
- 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
- package/dist/declarations/src/typegenTypes.d.ts +0 -168
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
3
|
+
var guards_dist_xstateGuards = require('./raise-bad6a97b.development.cjs.js');
|
|
4
4
|
|
|
5
|
-
// it's likely-ish that `(TActor & { src: TSrc })['logic']` would be faster
|
|
6
|
-
// but it's only possible to do it since https://github.com/microsoft/TypeScript/pull/53098 (TS 5.1)
|
|
7
|
-
// and we strive to support TS 5.0 whenever possible
|
|
8
5
|
function createSpawner(actorScope, {
|
|
9
6
|
machine,
|
|
10
7
|
context
|
|
@@ -93,34 +90,36 @@ function resolveAssign(actorScope, snapshot, actionArgs, actionParams, {
|
|
|
93
90
|
/**
|
|
94
91
|
* Updates the current context of the machine.
|
|
95
92
|
*
|
|
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
93
|
* @example
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
94
|
+
*
|
|
95
|
+
* ```ts
|
|
96
|
+
* import { createMachine, assign } from 'xstate';
|
|
97
|
+
*
|
|
98
|
+
* const countMachine = createMachine({
|
|
99
|
+
* context: {
|
|
100
|
+
* count: 0,
|
|
101
|
+
* message: ''
|
|
102
|
+
* },
|
|
103
|
+
* on: {
|
|
104
|
+
* inc: {
|
|
105
|
+
* actions: assign({
|
|
106
|
+
* count: ({ context }) => context.count + 1
|
|
107
|
+
* })
|
|
108
|
+
* },
|
|
109
|
+
* updateMessage: {
|
|
110
|
+
* actions: assign(({ context, event }) => {
|
|
111
|
+
* return {
|
|
112
|
+
* message: event.message.trim()
|
|
113
|
+
* };
|
|
114
|
+
* })
|
|
115
|
+
* }
|
|
116
|
+
* }
|
|
117
|
+
* });
|
|
118
|
+
* ```
|
|
119
|
+
*
|
|
120
|
+
* @param assignment An object that represents the partial context to update, or
|
|
121
|
+
* a function that returns an object that represents the partial context to
|
|
122
|
+
* update.
|
|
124
123
|
*/
|
|
125
124
|
function assign(assignment) {
|
|
126
125
|
if (guards_dist_xstateGuards.executingCustomAction) {
|
|
@@ -154,43 +153,42 @@ function executeEmit(actorScope, {
|
|
|
154
153
|
actorScope.defer(() => actorScope.emit(event));
|
|
155
154
|
}
|
|
156
155
|
/**
|
|
157
|
-
* Emits an event to event handlers registered on the actor via `actor.on(event,
|
|
156
|
+
* Emits an event to event handlers registered on the actor via `actor.on(event,
|
|
157
|
+
* handler)`.
|
|
158
158
|
*
|
|
159
159
|
* @example
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
function emit(
|
|
191
|
-
/**
|
|
192
|
-
* The event to emit, or an expression that returns an event to emit.
|
|
160
|
+
*
|
|
161
|
+
* ```ts
|
|
162
|
+
* import { emit } from 'xstate';
|
|
163
|
+
*
|
|
164
|
+
* const machine = createMachine({
|
|
165
|
+
* // ...
|
|
166
|
+
* on: {
|
|
167
|
+
* something: {
|
|
168
|
+
* actions: emit({
|
|
169
|
+
* type: 'emitted',
|
|
170
|
+
* some: 'data'
|
|
171
|
+
* })
|
|
172
|
+
* }
|
|
173
|
+
* }
|
|
174
|
+
* // ...
|
|
175
|
+
* });
|
|
176
|
+
*
|
|
177
|
+
* const actor = createActor(machine).start();
|
|
178
|
+
*
|
|
179
|
+
* actor.on('emitted', (event) => {
|
|
180
|
+
* console.log(event);
|
|
181
|
+
* });
|
|
182
|
+
*
|
|
183
|
+
* actor.send({ type: 'something' });
|
|
184
|
+
* // logs:
|
|
185
|
+
* // {
|
|
186
|
+
* // type: 'emitted',
|
|
187
|
+
* // some: 'data'
|
|
188
|
+
* // }
|
|
189
|
+
* ```
|
|
193
190
|
*/
|
|
191
|
+
function emit( /** The event to emit, or an expression that returns an event to emit. */
|
|
194
192
|
eventOrExpr) {
|
|
195
193
|
if (guards_dist_xstateGuards.executingCustomAction) {
|
|
196
194
|
console.warn('Custom actions should not call `emit()` directly, as it is not imperative. See https://stately.ai/docs/actions#built-in-actions for more details.');
|
|
@@ -208,62 +206,52 @@ eventOrExpr) {
|
|
|
208
206
|
}
|
|
209
207
|
|
|
210
208
|
/**
|
|
211
|
-
*
|
|
212
209
|
* @remarks
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
*
|
|
210
|
+
* `T | unknown` reduces to `unknown` and that can be problematic when it comes
|
|
211
|
+
* to contextual typing. It especially is a problem when the union has a
|
|
212
|
+
* function member, like here:
|
|
216
213
|
*
|
|
217
214
|
* ```ts
|
|
218
|
-
* declare function test(
|
|
219
|
-
*
|
|
215
|
+
* declare function test(
|
|
216
|
+
* cbOrVal: ((arg: number) => unknown) | unknown
|
|
217
|
+
* ): void;
|
|
218
|
+
* test((arg) => {}); // oops, implicit any
|
|
220
219
|
* ```
|
|
221
220
|
*
|
|
222
|
-
* This type can be used to avoid this problem. This union represents the same
|
|
221
|
+
* This type can be used to avoid this problem. This union represents the same
|
|
222
|
+
* value space as `unknown`.
|
|
223
223
|
*/
|
|
224
224
|
|
|
225
225
|
// https://github.com/microsoft/TypeScript/issues/23182#issuecomment-379091887
|
|
226
226
|
|
|
227
227
|
// @TODO: Replace with native `NoInfer` when TS issue gets fixed:
|
|
228
228
|
// https://github.com/microsoft/TypeScript/pull/57673
|
|
229
|
+
/** @deprecated Use the built-in `NoInfer` type instead */
|
|
230
|
+
/** The full definition of an event, with a string `type`. */
|
|
229
231
|
/**
|
|
230
|
-
*
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* The full definition of an event, with a string `type`.
|
|
234
|
-
*/
|
|
235
|
-
/**
|
|
236
|
-
* The string or object representing the state value relative to the parent state node.
|
|
232
|
+
* The string or object representing the state value relative to the parent
|
|
233
|
+
* state node.
|
|
237
234
|
*
|
|
238
235
|
* @remarks
|
|
239
|
-
*
|
|
240
236
|
* - For a child atomic state node, this is a string, e.g., `"pending"`.
|
|
241
|
-
*
|
|
242
|
-
*
|
|
237
|
+
* - For complex state nodes, this is an object, e.g., `{ success:
|
|
238
|
+
* "someChildState" }`.
|
|
243
239
|
*/
|
|
244
240
|
// TODO: remove once TS fixes this type-widening issue
|
|
245
|
-
/** @deprecated
|
|
241
|
+
/** @deprecated Use `AnyMachineSnapshot` instead */
|
|
246
242
|
// TODO: possibly refactor this somehow, use even a simpler type, and maybe even make `machine.options` private or something
|
|
247
|
-
/**
|
|
248
|
-
* @hidden
|
|
249
|
-
*/
|
|
243
|
+
/** @ignore */
|
|
250
244
|
let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
251
245
|
SpecialTargets["Parent"] = "#_parent";
|
|
252
246
|
SpecialTargets["Internal"] = "#_internal";
|
|
253
247
|
return SpecialTargets;
|
|
254
248
|
}({});
|
|
255
249
|
|
|
256
|
-
/**
|
|
257
|
-
* @deprecated Use `AnyActor` instead.
|
|
258
|
-
*/
|
|
250
|
+
/** @deprecated Use `AnyActor` instead. */
|
|
259
251
|
|
|
260
252
|
// Based on RxJS types
|
|
261
253
|
|
|
262
|
-
/**
|
|
263
|
-
* @deprecated Use `Actor<T>` instead.
|
|
264
|
-
*/
|
|
265
|
-
|
|
266
|
-
// only meant to be used internally for debugging purposes
|
|
254
|
+
/** @deprecated Use `Actor<T>` instead. */
|
|
267
255
|
|
|
268
256
|
/**
|
|
269
257
|
* Represents logic which can be used by an actor.
|
|
@@ -274,6 +262,8 @@ let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
|
274
262
|
* @template TSystem - The type of the actor system.
|
|
275
263
|
*/
|
|
276
264
|
|
|
265
|
+
/** @deprecated */
|
|
266
|
+
|
|
277
267
|
function resolveSendTo(actorScope, snapshot, args, actionParams, {
|
|
278
268
|
to,
|
|
279
269
|
event: eventOrExpr,
|
|
@@ -348,10 +338,12 @@ function executeSendTo(actorScope, params) {
|
|
|
348
338
|
* Sends an event to an actor.
|
|
349
339
|
*
|
|
350
340
|
* @param actor The `ActorRef` to send the event to.
|
|
351
|
-
* @param event The event to send, or an expression that evaluates to the event
|
|
341
|
+
* @param event The event to send, or an expression that evaluates to the event
|
|
342
|
+
* to send
|
|
352
343
|
* @param options Send action options
|
|
353
|
-
*
|
|
354
|
-
*
|
|
344
|
+
*
|
|
345
|
+
* - `id` - The unique send event identifier (used with `cancel()`).
|
|
346
|
+
* - `delay` - The number of milliseconds to delay the sending of the event.
|
|
355
347
|
*/
|
|
356
348
|
function sendTo(to, eventOrExpr, options) {
|
|
357
349
|
if (guards_dist_xstateGuards.executingCustomAction) {
|
|
@@ -447,24 +439,26 @@ function resolveEnqueueActions(actorScope, snapshot, args, actionParams, {
|
|
|
447
439
|
return [snapshot, undefined, actions];
|
|
448
440
|
}
|
|
449
441
|
/**
|
|
450
|
-
* Creates an action object that will execute actions that are queued by the
|
|
442
|
+
* Creates an action object that will execute actions that are queued by the
|
|
443
|
+
* `enqueue(action)` function.
|
|
451
444
|
*
|
|
452
445
|
* @example
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
446
|
+
*
|
|
447
|
+
* ```ts
|
|
448
|
+
* import { createMachine, enqueueActions } from 'xstate';
|
|
449
|
+
*
|
|
450
|
+
* const machine = createMachine({
|
|
451
|
+
* entry: enqueueActions(({ enqueue, check }) => {
|
|
452
|
+
* enqueue.assign({ count: 0 });
|
|
453
|
+
*
|
|
454
|
+
* if (check('someGuard')) {
|
|
455
|
+
* enqueue.assign({ count: 1 });
|
|
456
|
+
* }
|
|
457
|
+
*
|
|
458
|
+
* enqueue('someAction');
|
|
459
|
+
* })
|
|
460
|
+
* });
|
|
461
|
+
* ```
|
|
468
462
|
*/
|
|
469
463
|
function enqueueActions(collect) {
|
|
470
464
|
function enqueueActions(args, params) {
|
|
@@ -500,11 +494,12 @@ function executeLog({
|
|
|
500
494
|
}
|
|
501
495
|
}
|
|
502
496
|
/**
|
|
497
|
+
* @param expr The expression function to evaluate which will be logged. Takes
|
|
498
|
+
* in 2 arguments:
|
|
499
|
+
*
|
|
500
|
+
* - `ctx` - the current state context
|
|
501
|
+
* - `event` - the event that caused this action to be executed.
|
|
503
502
|
*
|
|
504
|
-
* @param expr The expression function to evaluate which will be logged.
|
|
505
|
-
* Takes in 2 arguments:
|
|
506
|
-
* - `ctx` - the current state context
|
|
507
|
-
* - `event` - the event that caused this action to be executed.
|
|
508
503
|
* @param label The label to give to the logged expression.
|
|
509
504
|
*/
|
|
510
505
|
function log(value = ({
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { T as ProcessingStatus, z as resolveReferencedActor, A as createActor, U as cloneMachineSnapshot, V as executingCustomAction, W as XSTATE_ERROR, Y as createErrorActorEvent, e as evaluateGuard, M as cancel, O as raise, P as spawnChild, R as stopChild } from './raise-
|
|
1
|
+
import { T as ProcessingStatus, z as resolveReferencedActor, A as createActor, U as cloneMachineSnapshot, V as executingCustomAction, W as XSTATE_ERROR, Y as createErrorActorEvent, e as evaluateGuard, M as cancel, O as raise, P as spawnChild, R as stopChild } from './raise-7d030497.development.esm.js';
|
|
2
2
|
|
|
3
|
-
// it's likely-ish that `(TActor & { src: TSrc })['logic']` would be faster
|
|
4
|
-
// but it's only possible to do it since https://github.com/microsoft/TypeScript/pull/53098 (TS 5.1)
|
|
5
|
-
// and we strive to support TS 5.0 whenever possible
|
|
6
3
|
function createSpawner(actorScope, {
|
|
7
4
|
machine,
|
|
8
5
|
context
|
|
@@ -91,34 +88,36 @@ function resolveAssign(actorScope, snapshot, actionArgs, actionParams, {
|
|
|
91
88
|
/**
|
|
92
89
|
* Updates the current context of the machine.
|
|
93
90
|
*
|
|
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
91
|
* @example
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
92
|
+
*
|
|
93
|
+
* ```ts
|
|
94
|
+
* import { createMachine, assign } from 'xstate';
|
|
95
|
+
*
|
|
96
|
+
* const countMachine = createMachine({
|
|
97
|
+
* context: {
|
|
98
|
+
* count: 0,
|
|
99
|
+
* message: ''
|
|
100
|
+
* },
|
|
101
|
+
* on: {
|
|
102
|
+
* inc: {
|
|
103
|
+
* actions: assign({
|
|
104
|
+
* count: ({ context }) => context.count + 1
|
|
105
|
+
* })
|
|
106
|
+
* },
|
|
107
|
+
* updateMessage: {
|
|
108
|
+
* actions: assign(({ context, event }) => {
|
|
109
|
+
* return {
|
|
110
|
+
* message: event.message.trim()
|
|
111
|
+
* };
|
|
112
|
+
* })
|
|
113
|
+
* }
|
|
114
|
+
* }
|
|
115
|
+
* });
|
|
116
|
+
* ```
|
|
117
|
+
*
|
|
118
|
+
* @param assignment An object that represents the partial context to update, or
|
|
119
|
+
* a function that returns an object that represents the partial context to
|
|
120
|
+
* update.
|
|
122
121
|
*/
|
|
123
122
|
function assign(assignment) {
|
|
124
123
|
if (executingCustomAction) {
|
|
@@ -152,43 +151,42 @@ function executeEmit(actorScope, {
|
|
|
152
151
|
actorScope.defer(() => actorScope.emit(event));
|
|
153
152
|
}
|
|
154
153
|
/**
|
|
155
|
-
* Emits an event to event handlers registered on the actor via `actor.on(event,
|
|
154
|
+
* Emits an event to event handlers registered on the actor via `actor.on(event,
|
|
155
|
+
* handler)`.
|
|
156
156
|
*
|
|
157
157
|
* @example
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
function emit(
|
|
189
|
-
/**
|
|
190
|
-
* The event to emit, or an expression that returns an event to emit.
|
|
158
|
+
*
|
|
159
|
+
* ```ts
|
|
160
|
+
* import { emit } from 'xstate';
|
|
161
|
+
*
|
|
162
|
+
* const machine = createMachine({
|
|
163
|
+
* // ...
|
|
164
|
+
* on: {
|
|
165
|
+
* something: {
|
|
166
|
+
* actions: emit({
|
|
167
|
+
* type: 'emitted',
|
|
168
|
+
* some: 'data'
|
|
169
|
+
* })
|
|
170
|
+
* }
|
|
171
|
+
* }
|
|
172
|
+
* // ...
|
|
173
|
+
* });
|
|
174
|
+
*
|
|
175
|
+
* const actor = createActor(machine).start();
|
|
176
|
+
*
|
|
177
|
+
* actor.on('emitted', (event) => {
|
|
178
|
+
* console.log(event);
|
|
179
|
+
* });
|
|
180
|
+
*
|
|
181
|
+
* actor.send({ type: 'something' });
|
|
182
|
+
* // logs:
|
|
183
|
+
* // {
|
|
184
|
+
* // type: 'emitted',
|
|
185
|
+
* // some: 'data'
|
|
186
|
+
* // }
|
|
187
|
+
* ```
|
|
191
188
|
*/
|
|
189
|
+
function emit( /** The event to emit, or an expression that returns an event to emit. */
|
|
192
190
|
eventOrExpr) {
|
|
193
191
|
if (executingCustomAction) {
|
|
194
192
|
console.warn('Custom actions should not call `emit()` directly, as it is not imperative. See https://stately.ai/docs/actions#built-in-actions for more details.');
|
|
@@ -206,62 +204,52 @@ eventOrExpr) {
|
|
|
206
204
|
}
|
|
207
205
|
|
|
208
206
|
/**
|
|
209
|
-
*
|
|
210
207
|
* @remarks
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
208
|
+
* `T | unknown` reduces to `unknown` and that can be problematic when it comes
|
|
209
|
+
* to contextual typing. It especially is a problem when the union has a
|
|
210
|
+
* function member, like here:
|
|
214
211
|
*
|
|
215
212
|
* ```ts
|
|
216
|
-
* declare function test(
|
|
217
|
-
*
|
|
213
|
+
* declare function test(
|
|
214
|
+
* cbOrVal: ((arg: number) => unknown) | unknown
|
|
215
|
+
* ): void;
|
|
216
|
+
* test((arg) => {}); // oops, implicit any
|
|
218
217
|
* ```
|
|
219
218
|
*
|
|
220
|
-
* This type can be used to avoid this problem. This union represents the same
|
|
219
|
+
* This type can be used to avoid this problem. This union represents the same
|
|
220
|
+
* value space as `unknown`.
|
|
221
221
|
*/
|
|
222
222
|
|
|
223
223
|
// https://github.com/microsoft/TypeScript/issues/23182#issuecomment-379091887
|
|
224
224
|
|
|
225
225
|
// @TODO: Replace with native `NoInfer` when TS issue gets fixed:
|
|
226
226
|
// https://github.com/microsoft/TypeScript/pull/57673
|
|
227
|
+
/** @deprecated Use the built-in `NoInfer` type instead */
|
|
228
|
+
/** The full definition of an event, with a string `type`. */
|
|
227
229
|
/**
|
|
228
|
-
*
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* The full definition of an event, with a string `type`.
|
|
232
|
-
*/
|
|
233
|
-
/**
|
|
234
|
-
* The string or object representing the state value relative to the parent state node.
|
|
230
|
+
* The string or object representing the state value relative to the parent
|
|
231
|
+
* state node.
|
|
235
232
|
*
|
|
236
233
|
* @remarks
|
|
237
|
-
*
|
|
238
234
|
* - For a child atomic state node, this is a string, e.g., `"pending"`.
|
|
239
|
-
*
|
|
240
|
-
*
|
|
235
|
+
* - For complex state nodes, this is an object, e.g., `{ success:
|
|
236
|
+
* "someChildState" }`.
|
|
241
237
|
*/
|
|
242
238
|
// TODO: remove once TS fixes this type-widening issue
|
|
243
|
-
/** @deprecated
|
|
239
|
+
/** @deprecated Use `AnyMachineSnapshot` instead */
|
|
244
240
|
// TODO: possibly refactor this somehow, use even a simpler type, and maybe even make `machine.options` private or something
|
|
245
|
-
/**
|
|
246
|
-
* @hidden
|
|
247
|
-
*/
|
|
241
|
+
/** @ignore */
|
|
248
242
|
let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
249
243
|
SpecialTargets["Parent"] = "#_parent";
|
|
250
244
|
SpecialTargets["Internal"] = "#_internal";
|
|
251
245
|
return SpecialTargets;
|
|
252
246
|
}({});
|
|
253
247
|
|
|
254
|
-
/**
|
|
255
|
-
* @deprecated Use `AnyActor` instead.
|
|
256
|
-
*/
|
|
248
|
+
/** @deprecated Use `AnyActor` instead. */
|
|
257
249
|
|
|
258
250
|
// Based on RxJS types
|
|
259
251
|
|
|
260
|
-
/**
|
|
261
|
-
* @deprecated Use `Actor<T>` instead.
|
|
262
|
-
*/
|
|
263
|
-
|
|
264
|
-
// only meant to be used internally for debugging purposes
|
|
252
|
+
/** @deprecated Use `Actor<T>` instead. */
|
|
265
253
|
|
|
266
254
|
/**
|
|
267
255
|
* Represents logic which can be used by an actor.
|
|
@@ -272,6 +260,8 @@ let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
|
272
260
|
* @template TSystem - The type of the actor system.
|
|
273
261
|
*/
|
|
274
262
|
|
|
263
|
+
/** @deprecated */
|
|
264
|
+
|
|
275
265
|
function resolveSendTo(actorScope, snapshot, args, actionParams, {
|
|
276
266
|
to,
|
|
277
267
|
event: eventOrExpr,
|
|
@@ -346,10 +336,12 @@ function executeSendTo(actorScope, params) {
|
|
|
346
336
|
* Sends an event to an actor.
|
|
347
337
|
*
|
|
348
338
|
* @param actor The `ActorRef` to send the event to.
|
|
349
|
-
* @param event The event to send, or an expression that evaluates to the event
|
|
339
|
+
* @param event The event to send, or an expression that evaluates to the event
|
|
340
|
+
* to send
|
|
350
341
|
* @param options Send action options
|
|
351
|
-
*
|
|
352
|
-
*
|
|
342
|
+
*
|
|
343
|
+
* - `id` - The unique send event identifier (used with `cancel()`).
|
|
344
|
+
* - `delay` - The number of milliseconds to delay the sending of the event.
|
|
353
345
|
*/
|
|
354
346
|
function sendTo(to, eventOrExpr, options) {
|
|
355
347
|
if (executingCustomAction) {
|
|
@@ -445,24 +437,26 @@ function resolveEnqueueActions(actorScope, snapshot, args, actionParams, {
|
|
|
445
437
|
return [snapshot, undefined, actions];
|
|
446
438
|
}
|
|
447
439
|
/**
|
|
448
|
-
* Creates an action object that will execute actions that are queued by the
|
|
440
|
+
* Creates an action object that will execute actions that are queued by the
|
|
441
|
+
* `enqueue(action)` function.
|
|
449
442
|
*
|
|
450
443
|
* @example
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
444
|
+
*
|
|
445
|
+
* ```ts
|
|
446
|
+
* import { createMachine, enqueueActions } from 'xstate';
|
|
447
|
+
*
|
|
448
|
+
* const machine = createMachine({
|
|
449
|
+
* entry: enqueueActions(({ enqueue, check }) => {
|
|
450
|
+
* enqueue.assign({ count: 0 });
|
|
451
|
+
*
|
|
452
|
+
* if (check('someGuard')) {
|
|
453
|
+
* enqueue.assign({ count: 1 });
|
|
454
|
+
* }
|
|
455
|
+
*
|
|
456
|
+
* enqueue('someAction');
|
|
457
|
+
* })
|
|
458
|
+
* });
|
|
459
|
+
* ```
|
|
466
460
|
*/
|
|
467
461
|
function enqueueActions(collect) {
|
|
468
462
|
function enqueueActions(args, params) {
|
|
@@ -498,11 +492,12 @@ function executeLog({
|
|
|
498
492
|
}
|
|
499
493
|
}
|
|
500
494
|
/**
|
|
495
|
+
* @param expr The expression function to evaluate which will be logged. Takes
|
|
496
|
+
* in 2 arguments:
|
|
497
|
+
*
|
|
498
|
+
* - `ctx` - the current state context
|
|
499
|
+
* - `event` - the event that caused this action to be executed.
|
|
501
500
|
*
|
|
502
|
-
* @param expr The expression function to evaluate which will be logged.
|
|
503
|
-
* Takes in 2 arguments:
|
|
504
|
-
* - `ctx` - the current state context
|
|
505
|
-
* - `event` - the event that caused this action to be executed.
|
|
506
501
|
* @param label The label to give to the logged expression.
|
|
507
502
|
*/
|
|
508
503
|
function log(value = ({
|