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.
Files changed (59) hide show
  1. package/actions/dist/xstate-actions.cjs.js +2 -2
  2. package/actions/dist/xstate-actions.development.cjs.js +2 -2
  3. package/actions/dist/xstate-actions.development.esm.js +2 -2
  4. package/actions/dist/xstate-actions.esm.js +2 -2
  5. package/actions/dist/xstate-actions.umd.min.js +1 -1
  6. package/actions/dist/xstate-actions.umd.min.js.map +1 -1
  7. package/actors/dist/xstate-actors.cjs.js +272 -65
  8. package/actors/dist/xstate-actors.development.cjs.js +272 -65
  9. package/actors/dist/xstate-actors.development.esm.js +272 -65
  10. package/actors/dist/xstate-actors.esm.js +272 -65
  11. package/actors/dist/xstate-actors.umd.min.js.map +1 -1
  12. package/dist/declarations/src/State.d.ts +23 -27
  13. package/dist/declarations/src/StateMachine.d.ts +19 -31
  14. package/dist/declarations/src/StateNode.d.ts +29 -51
  15. package/dist/declarations/src/actions/assign.d.ts +29 -27
  16. package/dist/declarations/src/actions/cancel.d.ts +28 -22
  17. package/dist/declarations/src/actions/emit.d.ts +33 -33
  18. package/dist/declarations/src/actions/enqueueActions.d.ts +21 -18
  19. package/dist/declarations/src/actions/log.d.ts +5 -4
  20. package/dist/declarations/src/actions/send.d.ts +5 -3
  21. package/dist/declarations/src/actors/callback.d.ts +65 -26
  22. package/dist/declarations/src/actors/index.d.ts +4 -4
  23. package/dist/declarations/src/actors/observable.d.ts +65 -22
  24. package/dist/declarations/src/actors/promise.d.ts +86 -9
  25. package/dist/declarations/src/actors/transition.d.ts +89 -15
  26. package/dist/declarations/src/assert.d.ts +21 -20
  27. package/dist/declarations/src/createActor.d.ts +51 -42
  28. package/dist/declarations/src/createMachine.d.ts +40 -54
  29. package/dist/declarations/src/getNextSnapshot.d.ts +27 -24
  30. package/dist/declarations/src/guards.d.ts +67 -66
  31. package/dist/declarations/src/index.d.ts +1 -2
  32. package/dist/declarations/src/inspection.d.ts +1 -0
  33. package/dist/declarations/src/setup.d.ts +1 -2
  34. package/dist/declarations/src/spawn.d.ts +2 -5
  35. package/dist/declarations/src/stateUtils.d.ts +5 -10
  36. package/dist/declarations/src/toPromise.d.ts +1 -0
  37. package/dist/declarations/src/types.d.ts +164 -189
  38. package/dist/declarations/src/waitFor.d.ts +9 -9
  39. package/dist/{log-c943e6aa.development.esm.js → log-17f4495d.development.esm.js} +115 -117
  40. package/dist/{log-505687fd.development.cjs.js → log-31321d85.development.cjs.js} +115 -117
  41. package/dist/{log-b87cb6bd.esm.js → log-8320f5e6.esm.js} +115 -117
  42. package/dist/{log-7ae0ddf8.cjs.js → log-f9587b82.cjs.js} +115 -117
  43. package/dist/{raise-4e39e875.esm.js → raise-2cfe6b8f.esm.js} +164 -154
  44. package/dist/{raise-0f400094.development.esm.js → raise-7d030497.development.esm.js} +164 -154
  45. package/dist/{raise-f79d2832.cjs.js → raise-a6298350.cjs.js} +164 -154
  46. package/dist/{raise-0cd7e521.development.cjs.js → raise-bad6a97b.development.cjs.js} +164 -154
  47. package/dist/xstate.cjs.js +134 -157
  48. package/dist/xstate.development.cjs.js +134 -157
  49. package/dist/xstate.development.esm.js +136 -159
  50. package/dist/xstate.esm.js +136 -159
  51. package/dist/xstate.umd.min.js +1 -1
  52. package/dist/xstate.umd.min.js.map +1 -1
  53. package/guards/dist/xstate-guards.cjs.js +1 -1
  54. package/guards/dist/xstate-guards.development.cjs.js +1 -1
  55. package/guards/dist/xstate-guards.development.esm.js +1 -1
  56. package/guards/dist/xstate-guards.esm.js +1 -1
  57. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  58. package/package.json +1 -1
  59. 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-f79d2832.cjs.js');
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
- ```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
- ```
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, handler)`.
147
+ * Emits an event to event handlers registered on the actor via `actor.on(event,
148
+ * handler)`.
149
149
  *
150
150
  * @example
151
- ```ts
152
- import { emit } from 'xstate';
153
-
154
- const machine = createMachine({
155
- // ...
156
- on: {
157
- something: {
158
- actions: emit({
159
- type: 'emitted',
160
- some: 'data'
161
- })
162
- }
163
- }
164
- // ...
165
- });
166
-
167
- const actor = createActor(machine).start();
168
-
169
- actor.on('emitted', (event) => {
170
- console.log(event);
171
- });
172
-
173
- actor.send({ type: 'something' });
174
- // logs:
175
- // {
176
- // type: 'emitted',
177
- // some: 'data'
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
- * `T | unknown` reduces to `unknown` and that can be problematic when it comes to contextual typing.
200
- * It especially is a problem when the union has a function member, like here:
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(cbOrVal: ((arg: number) => unknown) | unknown): void;
204
- * test((arg) => {}) // oops, implicit any
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 value space as `unknown`.
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
- * @deprecated Use the built-in `NoInfer` type instead
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
- * - For complex state nodes, this is an object, e.g., `{ success: "someChildState" }`.
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 use `AnyMachineSnapshot` instead */
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 to send
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
- * - `id` - The unique send event identifier (used with `cancel()`).
339
- * - `delay` - The number of milliseconds to delay the sending of the event.
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 `enqueue(action)` function.
414
+ * Creates an action object that will execute actions that are queued by the
415
+ * `enqueue(action)` function.
420
416
  *
421
417
  * @example
422
- ```ts
423
- import { createMachine, enqueueActions } from 'xstate';
424
-
425
- const machine = createMachine({
426
- entry: enqueueActions(({ enqueue, check }) => {
427
- enqueue.assign({ count: 0 });
428
-
429
- if (check('someGuard')) {
430
- enqueue.assign({ count: 1 });
431
- }
432
-
433
- enqueue('someAction');
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 = ({