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,22 +1,22 @@
|
|
|
1
1
|
import { AnyActorRef, SnapshotFrom } from "./types.js";
|
|
2
2
|
interface WaitForOptions {
|
|
3
3
|
/**
|
|
4
|
-
* How long to wait before rejecting, if no emitted
|
|
5
|
-
*
|
|
4
|
+
* How long to wait before rejecting, if no emitted state satisfies the
|
|
5
|
+
* predicate.
|
|
6
6
|
*
|
|
7
7
|
* @defaultValue Infinity
|
|
8
8
|
*/
|
|
9
9
|
timeout: number;
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
|
-
* Subscribes to an actor ref and waits for its emitted value to satisfy
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* (defaults to Infinity).
|
|
12
|
+
* Subscribes to an actor ref and waits for its emitted value to satisfy a
|
|
13
|
+
* predicate, and then resolves with that value. Will throw if the desired state
|
|
14
|
+
* is not reached after an optional timeout. (defaults to Infinity).
|
|
16
15
|
*
|
|
17
16
|
* @example
|
|
17
|
+
*
|
|
18
18
|
* ```js
|
|
19
|
-
* const state = await waitFor(someService, state => {
|
|
19
|
+
* const state = await waitFor(someService, (state) => {
|
|
20
20
|
* return state.hasTag('loaded');
|
|
21
21
|
* });
|
|
22
22
|
*
|
|
@@ -26,8 +26,8 @@ interface WaitForOptions {
|
|
|
26
26
|
* @param actorRef The actor ref to subscribe to
|
|
27
27
|
* @param predicate Determines if a value matches the condition to wait for
|
|
28
28
|
* @param options
|
|
29
|
-
* @returns A promise that eventually resolves to the emitted value
|
|
30
|
-
*
|
|
29
|
+
* @returns A promise that eventually resolves to the emitted value that matches
|
|
30
|
+
* the condition
|
|
31
31
|
*/
|
|
32
32
|
export declare function waitFor<TActorRef extends AnyActorRef>(actorRef: TActorRef, predicate: (emitted: SnapshotFrom<TActorRef>) => boolean, options?: Partial<WaitForOptions>): Promise<SnapshotFrom<TActorRef>>;
|
|
33
33
|
export {};
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { T as ProcessingStatus, z as resolveReferencedActor, A as createActor, U as cloneMachineSnapshot, V as XSTATE_ERROR, W 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 XSTATE_ERROR, W as createErrorActorEvent, e as evaluateGuard, M as cancel, O as raise, P as spawnChild, R as stopChild } from './raise-2cfe6b8f.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
|
function assign(args, params) {
|
|
@@ -143,43 +142,42 @@ function executeEmit(actorScope, {
|
|
|
143
142
|
actorScope.defer(() => actorScope.emit(event));
|
|
144
143
|
}
|
|
145
144
|
/**
|
|
146
|
-
* Emits an event to event handlers registered on the actor via `actor.on(event,
|
|
145
|
+
* Emits an event to event handlers registered on the actor via `actor.on(event,
|
|
146
|
+
* handler)`.
|
|
147
147
|
*
|
|
148
148
|
* @example
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
function emit(
|
|
180
|
-
/**
|
|
181
|
-
* The event to emit, or an expression that returns an event to emit.
|
|
149
|
+
*
|
|
150
|
+
* ```ts
|
|
151
|
+
* import { emit } from 'xstate';
|
|
152
|
+
*
|
|
153
|
+
* const machine = createMachine({
|
|
154
|
+
* // ...
|
|
155
|
+
* on: {
|
|
156
|
+
* something: {
|
|
157
|
+
* actions: emit({
|
|
158
|
+
* type: 'emitted',
|
|
159
|
+
* some: 'data'
|
|
160
|
+
* })
|
|
161
|
+
* }
|
|
162
|
+
* }
|
|
163
|
+
* // ...
|
|
164
|
+
* });
|
|
165
|
+
*
|
|
166
|
+
* const actor = createActor(machine).start();
|
|
167
|
+
*
|
|
168
|
+
* actor.on('emitted', (event) => {
|
|
169
|
+
* console.log(event);
|
|
170
|
+
* });
|
|
171
|
+
*
|
|
172
|
+
* actor.send({ type: 'something' });
|
|
173
|
+
* // logs:
|
|
174
|
+
* // {
|
|
175
|
+
* // type: 'emitted',
|
|
176
|
+
* // some: 'data'
|
|
177
|
+
* // }
|
|
178
|
+
* ```
|
|
182
179
|
*/
|
|
180
|
+
function emit( /** The event to emit, or an expression that returns an event to emit. */
|
|
183
181
|
eventOrExpr) {
|
|
184
182
|
function emit(args, params) {
|
|
185
183
|
}
|
|
@@ -191,62 +189,52 @@ eventOrExpr) {
|
|
|
191
189
|
}
|
|
192
190
|
|
|
193
191
|
/**
|
|
194
|
-
*
|
|
195
192
|
* @remarks
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
193
|
+
* `T | unknown` reduces to `unknown` and that can be problematic when it comes
|
|
194
|
+
* to contextual typing. It especially is a problem when the union has a
|
|
195
|
+
* function member, like here:
|
|
199
196
|
*
|
|
200
197
|
* ```ts
|
|
201
|
-
* declare function test(
|
|
202
|
-
*
|
|
198
|
+
* declare function test(
|
|
199
|
+
* cbOrVal: ((arg: number) => unknown) | unknown
|
|
200
|
+
* ): void;
|
|
201
|
+
* test((arg) => {}); // oops, implicit any
|
|
203
202
|
* ```
|
|
204
203
|
*
|
|
205
|
-
* This type can be used to avoid this problem. This union represents the same
|
|
204
|
+
* This type can be used to avoid this problem. This union represents the same
|
|
205
|
+
* value space as `unknown`.
|
|
206
206
|
*/
|
|
207
207
|
|
|
208
208
|
// https://github.com/microsoft/TypeScript/issues/23182#issuecomment-379091887
|
|
209
209
|
|
|
210
210
|
// @TODO: Replace with native `NoInfer` when TS issue gets fixed:
|
|
211
211
|
// https://github.com/microsoft/TypeScript/pull/57673
|
|
212
|
+
/** @deprecated Use the built-in `NoInfer` type instead */
|
|
213
|
+
/** The full definition of an event, with a string `type`. */
|
|
212
214
|
/**
|
|
213
|
-
*
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* The full definition of an event, with a string `type`.
|
|
217
|
-
*/
|
|
218
|
-
/**
|
|
219
|
-
* The string or object representing the state value relative to the parent state node.
|
|
215
|
+
* The string or object representing the state value relative to the parent
|
|
216
|
+
* state node.
|
|
220
217
|
*
|
|
221
218
|
* @remarks
|
|
222
|
-
*
|
|
223
219
|
* - For a child atomic state node, this is a string, e.g., `"pending"`.
|
|
224
|
-
*
|
|
225
|
-
*
|
|
220
|
+
* - For complex state nodes, this is an object, e.g., `{ success:
|
|
221
|
+
* "someChildState" }`.
|
|
226
222
|
*/
|
|
227
223
|
// TODO: remove once TS fixes this type-widening issue
|
|
228
|
-
/** @deprecated
|
|
224
|
+
/** @deprecated Use `AnyMachineSnapshot` instead */
|
|
229
225
|
// TODO: possibly refactor this somehow, use even a simpler type, and maybe even make `machine.options` private or something
|
|
230
|
-
/**
|
|
231
|
-
* @hidden
|
|
232
|
-
*/
|
|
226
|
+
/** @ignore */
|
|
233
227
|
let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
234
228
|
SpecialTargets["Parent"] = "#_parent";
|
|
235
229
|
SpecialTargets["Internal"] = "#_internal";
|
|
236
230
|
return SpecialTargets;
|
|
237
231
|
}({});
|
|
238
232
|
|
|
239
|
-
/**
|
|
240
|
-
* @deprecated Use `AnyActor` instead.
|
|
241
|
-
*/
|
|
233
|
+
/** @deprecated Use `AnyActor` instead. */
|
|
242
234
|
|
|
243
235
|
// Based on RxJS types
|
|
244
236
|
|
|
245
|
-
/**
|
|
246
|
-
* @deprecated Use `Actor<T>` instead.
|
|
247
|
-
*/
|
|
248
|
-
|
|
249
|
-
// only meant to be used internally for debugging purposes
|
|
237
|
+
/** @deprecated Use `Actor<T>` instead. */
|
|
250
238
|
|
|
251
239
|
/**
|
|
252
240
|
* Represents logic which can be used by an actor.
|
|
@@ -257,6 +245,8 @@ let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
|
257
245
|
* @template TSystem - The type of the actor system.
|
|
258
246
|
*/
|
|
259
247
|
|
|
248
|
+
/** @deprecated */
|
|
249
|
+
|
|
260
250
|
function resolveSendTo(actorScope, snapshot, args, actionParams, {
|
|
261
251
|
to,
|
|
262
252
|
event: eventOrExpr,
|
|
@@ -331,10 +321,12 @@ function executeSendTo(actorScope, params) {
|
|
|
331
321
|
* Sends an event to an actor.
|
|
332
322
|
*
|
|
333
323
|
* @param actor The `ActorRef` to send the event to.
|
|
334
|
-
* @param event The event to send, or an expression that evaluates to the event
|
|
324
|
+
* @param event The event to send, or an expression that evaluates to the event
|
|
325
|
+
* to send
|
|
335
326
|
* @param options Send action options
|
|
336
|
-
*
|
|
337
|
-
*
|
|
327
|
+
*
|
|
328
|
+
* - `id` - The unique send event identifier (used with `cancel()`).
|
|
329
|
+
* - `delay` - The number of milliseconds to delay the sending of the event.
|
|
338
330
|
*/
|
|
339
331
|
function sendTo(to, eventOrExpr, options) {
|
|
340
332
|
function sendTo(args, params) {
|
|
@@ -414,24 +406,26 @@ function resolveEnqueueActions(actorScope, snapshot, args, actionParams, {
|
|
|
414
406
|
return [snapshot, undefined, actions];
|
|
415
407
|
}
|
|
416
408
|
/**
|
|
417
|
-
* Creates an action object that will execute actions that are queued by the
|
|
409
|
+
* Creates an action object that will execute actions that are queued by the
|
|
410
|
+
* `enqueue(action)` function.
|
|
418
411
|
*
|
|
419
412
|
* @example
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
413
|
+
*
|
|
414
|
+
* ```ts
|
|
415
|
+
* import { createMachine, enqueueActions } from 'xstate';
|
|
416
|
+
*
|
|
417
|
+
* const machine = createMachine({
|
|
418
|
+
* entry: enqueueActions(({ enqueue, check }) => {
|
|
419
|
+
* enqueue.assign({ count: 0 });
|
|
420
|
+
*
|
|
421
|
+
* if (check('someGuard')) {
|
|
422
|
+
* enqueue.assign({ count: 1 });
|
|
423
|
+
* }
|
|
424
|
+
*
|
|
425
|
+
* enqueue('someAction');
|
|
426
|
+
* })
|
|
427
|
+
* });
|
|
428
|
+
* ```
|
|
435
429
|
*/
|
|
436
430
|
function enqueueActions(collect) {
|
|
437
431
|
function enqueueActions(args, params) {
|
|
@@ -464,11 +458,12 @@ function executeLog({
|
|
|
464
458
|
}
|
|
465
459
|
}
|
|
466
460
|
/**
|
|
461
|
+
* @param expr The expression function to evaluate which will be logged. Takes
|
|
462
|
+
* in 2 arguments:
|
|
463
|
+
*
|
|
464
|
+
* - `ctx` - the current state context
|
|
465
|
+
* - `event` - the event that caused this action to be executed.
|
|
467
466
|
*
|
|
468
|
-
* @param expr The expression function to evaluate which will be logged.
|
|
469
|
-
* Takes in 2 arguments:
|
|
470
|
-
* - `ctx` - the current state context
|
|
471
|
-
* - `event` - the event that caused this action to be executed.
|
|
472
467
|
* @param label The label to give to the logged expression.
|
|
473
468
|
*/
|
|
474
469
|
function log(value = ({
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
3
|
+
var guards_dist_xstateGuards = require('./raise-a6298350.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
|
function assign(args, params) {
|
|
@@ -145,43 +144,42 @@ function executeEmit(actorScope, {
|
|
|
145
144
|
actorScope.defer(() => actorScope.emit(event));
|
|
146
145
|
}
|
|
147
146
|
/**
|
|
148
|
-
* Emits an event to event handlers registered on the actor via `actor.on(event,
|
|
147
|
+
* Emits an event to event handlers registered on the actor via `actor.on(event,
|
|
148
|
+
* handler)`.
|
|
149
149
|
*
|
|
150
150
|
* @example
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
function emit(
|
|
182
|
-
/**
|
|
183
|
-
* The event to emit, or an expression that returns an event to emit.
|
|
151
|
+
*
|
|
152
|
+
* ```ts
|
|
153
|
+
* import { emit } from 'xstate';
|
|
154
|
+
*
|
|
155
|
+
* const machine = createMachine({
|
|
156
|
+
* // ...
|
|
157
|
+
* on: {
|
|
158
|
+
* something: {
|
|
159
|
+
* actions: emit({
|
|
160
|
+
* type: 'emitted',
|
|
161
|
+
* some: 'data'
|
|
162
|
+
* })
|
|
163
|
+
* }
|
|
164
|
+
* }
|
|
165
|
+
* // ...
|
|
166
|
+
* });
|
|
167
|
+
*
|
|
168
|
+
* const actor = createActor(machine).start();
|
|
169
|
+
*
|
|
170
|
+
* actor.on('emitted', (event) => {
|
|
171
|
+
* console.log(event);
|
|
172
|
+
* });
|
|
173
|
+
*
|
|
174
|
+
* actor.send({ type: 'something' });
|
|
175
|
+
* // logs:
|
|
176
|
+
* // {
|
|
177
|
+
* // type: 'emitted',
|
|
178
|
+
* // some: 'data'
|
|
179
|
+
* // }
|
|
180
|
+
* ```
|
|
184
181
|
*/
|
|
182
|
+
function emit( /** The event to emit, or an expression that returns an event to emit. */
|
|
185
183
|
eventOrExpr) {
|
|
186
184
|
function emit(args, params) {
|
|
187
185
|
}
|
|
@@ -193,62 +191,52 @@ eventOrExpr) {
|
|
|
193
191
|
}
|
|
194
192
|
|
|
195
193
|
/**
|
|
196
|
-
*
|
|
197
194
|
* @remarks
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
195
|
+
* `T | unknown` reduces to `unknown` and that can be problematic when it comes
|
|
196
|
+
* to contextual typing. It especially is a problem when the union has a
|
|
197
|
+
* function member, like here:
|
|
201
198
|
*
|
|
202
199
|
* ```ts
|
|
203
|
-
* declare function test(
|
|
204
|
-
*
|
|
200
|
+
* declare function test(
|
|
201
|
+
* cbOrVal: ((arg: number) => unknown) | unknown
|
|
202
|
+
* ): void;
|
|
203
|
+
* test((arg) => {}); // oops, implicit any
|
|
205
204
|
* ```
|
|
206
205
|
*
|
|
207
|
-
* This type can be used to avoid this problem. This union represents the same
|
|
206
|
+
* This type can be used to avoid this problem. This union represents the same
|
|
207
|
+
* value space as `unknown`.
|
|
208
208
|
*/
|
|
209
209
|
|
|
210
210
|
// https://github.com/microsoft/TypeScript/issues/23182#issuecomment-379091887
|
|
211
211
|
|
|
212
212
|
// @TODO: Replace with native `NoInfer` when TS issue gets fixed:
|
|
213
213
|
// https://github.com/microsoft/TypeScript/pull/57673
|
|
214
|
+
/** @deprecated Use the built-in `NoInfer` type instead */
|
|
215
|
+
/** The full definition of an event, with a string `type`. */
|
|
214
216
|
/**
|
|
215
|
-
*
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* The full definition of an event, with a string `type`.
|
|
219
|
-
*/
|
|
220
|
-
/**
|
|
221
|
-
* The string or object representing the state value relative to the parent state node.
|
|
217
|
+
* The string or object representing the state value relative to the parent
|
|
218
|
+
* state node.
|
|
222
219
|
*
|
|
223
220
|
* @remarks
|
|
224
|
-
*
|
|
225
221
|
* - For a child atomic state node, this is a string, e.g., `"pending"`.
|
|
226
|
-
*
|
|
227
|
-
*
|
|
222
|
+
* - For complex state nodes, this is an object, e.g., `{ success:
|
|
223
|
+
* "someChildState" }`.
|
|
228
224
|
*/
|
|
229
225
|
// TODO: remove once TS fixes this type-widening issue
|
|
230
|
-
/** @deprecated
|
|
226
|
+
/** @deprecated Use `AnyMachineSnapshot` instead */
|
|
231
227
|
// TODO: possibly refactor this somehow, use even a simpler type, and maybe even make `machine.options` private or something
|
|
232
|
-
/**
|
|
233
|
-
* @hidden
|
|
234
|
-
*/
|
|
228
|
+
/** @ignore */
|
|
235
229
|
let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
236
230
|
SpecialTargets["Parent"] = "#_parent";
|
|
237
231
|
SpecialTargets["Internal"] = "#_internal";
|
|
238
232
|
return SpecialTargets;
|
|
239
233
|
}({});
|
|
240
234
|
|
|
241
|
-
/**
|
|
242
|
-
* @deprecated Use `AnyActor` instead.
|
|
243
|
-
*/
|
|
235
|
+
/** @deprecated Use `AnyActor` instead. */
|
|
244
236
|
|
|
245
237
|
// Based on RxJS types
|
|
246
238
|
|
|
247
|
-
/**
|
|
248
|
-
* @deprecated Use `Actor<T>` instead.
|
|
249
|
-
*/
|
|
250
|
-
|
|
251
|
-
// only meant to be used internally for debugging purposes
|
|
239
|
+
/** @deprecated Use `Actor<T>` instead. */
|
|
252
240
|
|
|
253
241
|
/**
|
|
254
242
|
* Represents logic which can be used by an actor.
|
|
@@ -259,6 +247,8 @@ let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
|
259
247
|
* @template TSystem - The type of the actor system.
|
|
260
248
|
*/
|
|
261
249
|
|
|
250
|
+
/** @deprecated */
|
|
251
|
+
|
|
262
252
|
function resolveSendTo(actorScope, snapshot, args, actionParams, {
|
|
263
253
|
to,
|
|
264
254
|
event: eventOrExpr,
|
|
@@ -333,10 +323,12 @@ function executeSendTo(actorScope, params) {
|
|
|
333
323
|
* Sends an event to an actor.
|
|
334
324
|
*
|
|
335
325
|
* @param actor The `ActorRef` to send the event to.
|
|
336
|
-
* @param event The event to send, or an expression that evaluates to the event
|
|
326
|
+
* @param event The event to send, or an expression that evaluates to the event
|
|
327
|
+
* to send
|
|
337
328
|
* @param options Send action options
|
|
338
|
-
*
|
|
339
|
-
*
|
|
329
|
+
*
|
|
330
|
+
* - `id` - The unique send event identifier (used with `cancel()`).
|
|
331
|
+
* - `delay` - The number of milliseconds to delay the sending of the event.
|
|
340
332
|
*/
|
|
341
333
|
function sendTo(to, eventOrExpr, options) {
|
|
342
334
|
function sendTo(args, params) {
|
|
@@ -416,24 +408,26 @@ function resolveEnqueueActions(actorScope, snapshot, args, actionParams, {
|
|
|
416
408
|
return [snapshot, undefined, actions];
|
|
417
409
|
}
|
|
418
410
|
/**
|
|
419
|
-
* Creates an action object that will execute actions that are queued by the
|
|
411
|
+
* Creates an action object that will execute actions that are queued by the
|
|
412
|
+
* `enqueue(action)` function.
|
|
420
413
|
*
|
|
421
414
|
* @example
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
415
|
+
*
|
|
416
|
+
* ```ts
|
|
417
|
+
* import { createMachine, enqueueActions } from 'xstate';
|
|
418
|
+
*
|
|
419
|
+
* const machine = createMachine({
|
|
420
|
+
* entry: enqueueActions(({ enqueue, check }) => {
|
|
421
|
+
* enqueue.assign({ count: 0 });
|
|
422
|
+
*
|
|
423
|
+
* if (check('someGuard')) {
|
|
424
|
+
* enqueue.assign({ count: 1 });
|
|
425
|
+
* }
|
|
426
|
+
*
|
|
427
|
+
* enqueue('someAction');
|
|
428
|
+
* })
|
|
429
|
+
* });
|
|
430
|
+
* ```
|
|
437
431
|
*/
|
|
438
432
|
function enqueueActions(collect) {
|
|
439
433
|
function enqueueActions(args, params) {
|
|
@@ -466,11 +460,12 @@ function executeLog({
|
|
|
466
460
|
}
|
|
467
461
|
}
|
|
468
462
|
/**
|
|
463
|
+
* @param expr The expression function to evaluate which will be logged. Takes
|
|
464
|
+
* in 2 arguments:
|
|
465
|
+
*
|
|
466
|
+
* - `ctx` - the current state context
|
|
467
|
+
* - `event` - the event that caused this action to be executed.
|
|
469
468
|
*
|
|
470
|
-
* @param expr The expression function to evaluate which will be logged.
|
|
471
|
-
* Takes in 2 arguments:
|
|
472
|
-
* - `ctx` - the current state context
|
|
473
|
-
* - `event` - the event that caused this action to be executed.
|
|
474
469
|
* @param label The label to give to the logged expression.
|
|
475
470
|
*/
|
|
476
471
|
function log(value = ({
|