xstate 5.14.0 → 5.16.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 +272 -65
- package/actors/dist/xstate-actors.development.cjs.js +272 -65
- package/actors/dist/xstate-actors.development.esm.js +272 -65
- package/actors/dist/xstate-actors.esm.js +272 -65
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/declarations/src/State.d.ts +23 -27
- package/dist/declarations/src/StateMachine.d.ts +19 -31
- 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 +21 -18
- 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 +65 -26
- package/dist/declarations/src/actors/index.d.ts +4 -4
- package/dist/declarations/src/actors/observable.d.ts +65 -22
- package/dist/declarations/src/actors/promise.d.ts +86 -9
- package/dist/declarations/src/actors/transition.d.ts +89 -15
- 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 +1 -2
- 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/toPromise.d.ts +1 -0
- package/dist/declarations/src/types.d.ts +164 -189
- package/dist/declarations/src/waitFor.d.ts +9 -9
- package/dist/{log-c943e6aa.development.esm.js → log-17f4495d.development.esm.js} +115 -117
- package/dist/{log-505687fd.development.cjs.js → log-31321d85.development.cjs.js} +115 -117
- package/dist/{log-b87cb6bd.esm.js → log-8320f5e6.esm.js} +115 -117
- package/dist/{log-7ae0ddf8.cjs.js → log-f9587b82.cjs.js} +115 -117
- package/dist/{raise-4e39e875.esm.js → raise-2cfe6b8f.esm.js} +164 -154
- package/dist/{raise-0f400094.development.esm.js → raise-7d030497.development.esm.js} +164 -154
- package/dist/{raise-f79d2832.cjs.js → raise-a6298350.cjs.js} +164 -154
- package/dist/{raise-0cd7e521.development.cjs.js → raise-bad6a97b.development.cjs.js} +164 -154
- 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-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) {
|
|
@@ -396,6 +388,9 @@ function resolveEnqueueActions(actorScope, snapshot, args, actionParams, {
|
|
|
396
388
|
// then it fails to typecheck that because `...args` use `string` in place of `TDelay
|
|
397
389
|
actions.push(sendTo(...args));
|
|
398
390
|
};
|
|
391
|
+
enqueue.sendParent = (...args) => {
|
|
392
|
+
actions.push(sendParent(...args));
|
|
393
|
+
};
|
|
399
394
|
enqueue.spawnChild = (...args) => {
|
|
400
395
|
actions.push(guards_dist_xstateGuards.spawnChild(...args));
|
|
401
396
|
};
|
|
@@ -416,24 +411,26 @@ function resolveEnqueueActions(actorScope, snapshot, args, actionParams, {
|
|
|
416
411
|
return [snapshot, undefined, actions];
|
|
417
412
|
}
|
|
418
413
|
/**
|
|
419
|
-
* Creates an action object that will execute actions that are queued by the
|
|
414
|
+
* Creates an action object that will execute actions that are queued by the
|
|
415
|
+
* `enqueue(action)` function.
|
|
420
416
|
*
|
|
421
417
|
* @example
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
418
|
+
*
|
|
419
|
+
* ```ts
|
|
420
|
+
* import { createMachine, enqueueActions } from 'xstate';
|
|
421
|
+
*
|
|
422
|
+
* const machine = createMachine({
|
|
423
|
+
* entry: enqueueActions(({ enqueue, check }) => {
|
|
424
|
+
* enqueue.assign({ count: 0 });
|
|
425
|
+
*
|
|
426
|
+
* if (check('someGuard')) {
|
|
427
|
+
* enqueue.assign({ count: 1 });
|
|
428
|
+
* }
|
|
429
|
+
*
|
|
430
|
+
* enqueue('someAction');
|
|
431
|
+
* })
|
|
432
|
+
* });
|
|
433
|
+
* ```
|
|
437
434
|
*/
|
|
438
435
|
function enqueueActions(collect) {
|
|
439
436
|
function enqueueActions(args, params) {
|
|
@@ -466,11 +463,12 @@ function executeLog({
|
|
|
466
463
|
}
|
|
467
464
|
}
|
|
468
465
|
/**
|
|
466
|
+
* @param expr The expression function to evaluate which will be logged. Takes
|
|
467
|
+
* in 2 arguments:
|
|
468
|
+
*
|
|
469
|
+
* - `ctx` - the current state context
|
|
470
|
+
* - `event` - the event that caused this action to be executed.
|
|
469
471
|
*
|
|
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
472
|
* @param label The label to give to the logged expression.
|
|
475
473
|
*/
|
|
476
474
|
function log(value = ({
|