xstate 4.20.0 → 4.23.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 (94) hide show
  1. package/CHANGELOG.md +205 -0
  2. package/dist/xstate.interpreter.js +1 -1
  3. package/dist/xstate.js +1 -1
  4. package/dist/xstate.web.js +2 -2
  5. package/es/Actor.d.ts +6 -5
  6. package/es/Actor.js +22 -7
  7. package/es/Machine.d.ts +10 -5
  8. package/es/Machine.js +3 -6
  9. package/es/State.js +3 -5
  10. package/es/StateNode.d.ts +4 -3
  11. package/es/StateNode.js +34 -28
  12. package/es/_virtual/_tslib.js +59 -73
  13. package/es/actionTypes.js +3 -2
  14. package/es/actions.d.ts +1 -1
  15. package/es/actions.js +51 -37
  16. package/es/behaviors.d.ts +37 -0
  17. package/es/behaviors.js +65 -0
  18. package/es/constants.js +2 -1
  19. package/es/devTools.js +1 -1
  20. package/es/environment.js +2 -1
  21. package/es/index.js +3 -1
  22. package/es/interpreter.d.ts +15 -8
  23. package/es/interpreter.js +48 -22
  24. package/es/invokeUtils.js +4 -3
  25. package/es/mapState.js +1 -1
  26. package/es/match.js +1 -1
  27. package/es/model.d.ts +2 -36
  28. package/es/model.types.d.ts +37 -0
  29. package/es/registry.js +2 -1
  30. package/es/scheduler.js +2 -1
  31. package/es/schema.js +1 -1
  32. package/es/serviceScope.js +1 -3
  33. package/es/stateUtils.d.ts +1 -0
  34. package/es/stateUtils.js +14 -8
  35. package/es/types.d.ts +35 -9
  36. package/es/types.js +1 -1
  37. package/es/utils.d.ts +3 -2
  38. package/es/utils.js +4 -40
  39. package/lib/Actor.d.ts +25 -24
  40. package/lib/Actor.js +87 -53
  41. package/lib/Machine.d.ts +17 -12
  42. package/lib/Machine.js +14 -14
  43. package/lib/SimulatedClock.d.ts +16 -16
  44. package/lib/State.d.ts +108 -108
  45. package/lib/State.js +246 -236
  46. package/lib/StateNode.d.ts +279 -278
  47. package/lib/StateNode.js +1535 -1350
  48. package/lib/_virtual/_tslib.js +81 -0
  49. package/lib/actionTypes.d.ts +19 -19
  50. package/lib/actionTypes.js +43 -23
  51. package/lib/actions.d.ts +138 -138
  52. package/lib/actions.js +465 -387
  53. package/lib/behaviors.d.ts +37 -0
  54. package/lib/behaviors.js +69 -0
  55. package/lib/constants.d.ts +5 -5
  56. package/lib/constants.js +13 -7
  57. package/lib/devTools.d.ts +15 -15
  58. package/lib/devTools.js +37 -26
  59. package/lib/each.d.ts +3 -3
  60. package/lib/environment.d.ts +1 -1
  61. package/lib/environment.js +7 -4
  62. package/lib/index.d.ts +30 -30
  63. package/lib/index.js +67 -57
  64. package/lib/interpreter.d.ts +205 -198
  65. package/lib/interpreter.js +1307 -1052
  66. package/lib/invoke.d.ts +10 -10
  67. package/lib/invokeUtils.d.ts +6 -6
  68. package/lib/invokeUtils.js +40 -37
  69. package/lib/json.d.ts +30 -30
  70. package/lib/mapState.d.ts +3 -3
  71. package/lib/mapState.js +31 -32
  72. package/lib/match.d.ts +8 -8
  73. package/lib/match.js +33 -47
  74. package/lib/model.d.ts +4 -38
  75. package/lib/model.js +5 -1
  76. package/lib/model.types.d.ts +37 -0
  77. package/lib/model.types.js +2 -0
  78. package/lib/patterns.d.ts +13 -13
  79. package/lib/registry.d.ts +8 -8
  80. package/lib/registry.js +21 -18
  81. package/lib/scheduler.d.ts +16 -16
  82. package/lib/scheduler.js +79 -70
  83. package/lib/schema.d.ts +1 -1
  84. package/lib/schema.js +6 -4
  85. package/lib/scxml.d.ts +5 -5
  86. package/lib/serviceScope.d.ts +3 -3
  87. package/lib/serviceScope.js +16 -12
  88. package/lib/stateUtils.d.ts +14 -13
  89. package/lib/stateUtils.js +232 -190
  90. package/lib/types.d.ts +928 -902
  91. package/lib/types.js +29 -29
  92. package/lib/utils.d.ts +68 -67
  93. package/lib/utils.js +530 -529
  94. package/package.json +5 -5
@@ -0,0 +1,81 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ /*! *****************************************************************************
6
+ Copyright (c) Microsoft Corporation.
7
+
8
+ Permission to use, copy, modify, and/or distribute this software for any
9
+ purpose with or without fee is hereby granted.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
+ PERFORMANCE OF THIS SOFTWARE.
18
+ ***************************************************************************** */
19
+
20
+ exports.__assign = function() {
21
+ exports.__assign = Object.assign || function __assign(t) {
22
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
23
+ s = arguments[i];
24
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
25
+ }
26
+ return t;
27
+ };
28
+ return exports.__assign.apply(this, arguments);
29
+ };
30
+
31
+ function __rest(s, e) {
32
+ var t = {};
33
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
34
+ t[p] = s[p];
35
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
36
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
37
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
38
+ t[p[i]] = s[p[i]];
39
+ }
40
+ return t;
41
+ }
42
+
43
+ function __values(o) {
44
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
45
+ if (m) return m.call(o);
46
+ if (o && typeof o.length === "number") return {
47
+ next: function () {
48
+ if (o && i >= o.length) o = void 0;
49
+ return { value: o && o[i++], done: !o };
50
+ }
51
+ };
52
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
53
+ }
54
+
55
+ function __read(o, n) {
56
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
57
+ if (!m) return o;
58
+ var i = m.call(o), r, ar = [], e;
59
+ try {
60
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
61
+ }
62
+ catch (error) { e = { error: error }; }
63
+ finally {
64
+ try {
65
+ if (r && !r.done && (m = i["return"])) m.call(i);
66
+ }
67
+ finally { if (e) throw e.error; }
68
+ }
69
+ return ar;
70
+ }
71
+
72
+ function __spreadArray(to, from) {
73
+ for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
74
+ to[j] = from[i];
75
+ return to;
76
+ }
77
+
78
+ exports.__read = __read;
79
+ exports.__rest = __rest;
80
+ exports.__spreadArray = __spreadArray;
81
+ exports.__values = __values;
@@ -1,20 +1,20 @@
1
- import { ActionTypes } from './types';
2
- export declare const start = ActionTypes.Start;
3
- export declare const stop = ActionTypes.Stop;
4
- export declare const raise = ActionTypes.Raise;
5
- export declare const send = ActionTypes.Send;
6
- export declare const cancel = ActionTypes.Cancel;
7
- export declare const nullEvent = ActionTypes.NullEvent;
8
- export declare const assign = ActionTypes.Assign;
9
- export declare const after = ActionTypes.After;
10
- export declare const doneState = ActionTypes.DoneState;
11
- export declare const log = ActionTypes.Log;
12
- export declare const init = ActionTypes.Init;
13
- export declare const invoke = ActionTypes.Invoke;
14
- export declare const errorExecution = ActionTypes.ErrorExecution;
15
- export declare const errorPlatform = ActionTypes.ErrorPlatform;
16
- export declare const error = ActionTypes.ErrorCustom;
17
- export declare const update = ActionTypes.Update;
18
- export declare const choose = ActionTypes.Choose;
19
- export declare const pure = ActionTypes.Pure;
1
+ import { ActionTypes } from './types';
2
+ export declare const start = ActionTypes.Start;
3
+ export declare const stop = ActionTypes.Stop;
4
+ export declare const raise = ActionTypes.Raise;
5
+ export declare const send = ActionTypes.Send;
6
+ export declare const cancel = ActionTypes.Cancel;
7
+ export declare const nullEvent = ActionTypes.NullEvent;
8
+ export declare const assign = ActionTypes.Assign;
9
+ export declare const after = ActionTypes.After;
10
+ export declare const doneState = ActionTypes.DoneState;
11
+ export declare const log = ActionTypes.Log;
12
+ export declare const init = ActionTypes.Init;
13
+ export declare const invoke = ActionTypes.Invoke;
14
+ export declare const errorExecution = ActionTypes.ErrorExecution;
15
+ export declare const errorPlatform = ActionTypes.ErrorPlatform;
16
+ export declare const error = ActionTypes.ErrorCustom;
17
+ export declare const update = ActionTypes.Update;
18
+ export declare const choose = ActionTypes.Choose;
19
+ export declare const pure = ActionTypes.Pure;
20
20
  //# sourceMappingURL=actionTypes.d.ts.map
@@ -1,23 +1,43 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pure = exports.choose = exports.update = exports.error = exports.errorPlatform = exports.errorExecution = exports.invoke = exports.init = exports.log = exports.doneState = exports.after = exports.assign = exports.nullEvent = exports.cancel = exports.send = exports.raise = exports.stop = exports.start = void 0;
4
- var types_1 = require("./types");
5
- // xstate-specific action types
6
- exports.start = types_1.ActionTypes.Start;
7
- exports.stop = types_1.ActionTypes.Stop;
8
- exports.raise = types_1.ActionTypes.Raise;
9
- exports.send = types_1.ActionTypes.Send;
10
- exports.cancel = types_1.ActionTypes.Cancel;
11
- exports.nullEvent = types_1.ActionTypes.NullEvent;
12
- exports.assign = types_1.ActionTypes.Assign;
13
- exports.after = types_1.ActionTypes.After;
14
- exports.doneState = types_1.ActionTypes.DoneState;
15
- exports.log = types_1.ActionTypes.Log;
16
- exports.init = types_1.ActionTypes.Init;
17
- exports.invoke = types_1.ActionTypes.Invoke;
18
- exports.errorExecution = types_1.ActionTypes.ErrorExecution;
19
- exports.errorPlatform = types_1.ActionTypes.ErrorPlatform;
20
- exports.error = types_1.ActionTypes.ErrorCustom;
21
- exports.update = types_1.ActionTypes.Update;
22
- exports.choose = types_1.ActionTypes.Choose;
23
- exports.pure = types_1.ActionTypes.Pure;
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var types = require('./types.js');
6
+
7
+ var start = types.ActionTypes.Start;
8
+ var stop = types.ActionTypes.Stop;
9
+ var raise = types.ActionTypes.Raise;
10
+ var send = types.ActionTypes.Send;
11
+ var cancel = types.ActionTypes.Cancel;
12
+ var nullEvent = types.ActionTypes.NullEvent;
13
+ var assign = types.ActionTypes.Assign;
14
+ var after = types.ActionTypes.After;
15
+ var doneState = types.ActionTypes.DoneState;
16
+ var log = types.ActionTypes.Log;
17
+ var init = types.ActionTypes.Init;
18
+ var invoke = types.ActionTypes.Invoke;
19
+ var errorExecution = types.ActionTypes.ErrorExecution;
20
+ var errorPlatform = types.ActionTypes.ErrorPlatform;
21
+ var error = types.ActionTypes.ErrorCustom;
22
+ var update = types.ActionTypes.Update;
23
+ var choose = types.ActionTypes.Choose;
24
+ var pure = types.ActionTypes.Pure;
25
+
26
+ exports.after = after;
27
+ exports.assign = assign;
28
+ exports.cancel = cancel;
29
+ exports.choose = choose;
30
+ exports.doneState = doneState;
31
+ exports.error = error;
32
+ exports.errorExecution = errorExecution;
33
+ exports.errorPlatform = errorPlatform;
34
+ exports.init = init;
35
+ exports.invoke = invoke;
36
+ exports.log = log;
37
+ exports.nullEvent = nullEvent;
38
+ exports.pure = pure;
39
+ exports.raise = raise;
40
+ exports.send = send;
41
+ exports.start = start;
42
+ exports.stop = stop;
43
+ exports.update = update;
package/lib/actions.d.ts CHANGED
@@ -1,139 +1,139 @@
1
- import { Action, Event, EventObject, SingleOrArray, SendAction, SendActionOptions, CancelAction, ActionObject, ActionType, Assigner, PropertyAssigner, AssignAction, ActionFunction, ActionFunctionMap, ActivityActionObject, ActionTypes, ActivityDefinition, RaiseAction, RaiseActionObject, DoneEvent, ErrorPlatformEvent, DoneEventObject, SendExpr, SendActionObject, PureAction, LogExpr, LogAction, LogActionObject, DelayFunctionMap, SCXML, ExprWithMeta, ChooseConditon, ChooseAction, AnyEventObject, Expr } from './types';
2
- import * as actionTypes from './actionTypes';
3
- import { State } from './State';
4
- import { StateNode } from './StateNode';
5
- import { StopAction, StopActionObject } from '.';
6
- export { actionTypes };
7
- export declare const initEvent: SCXML.Event<{
8
- type: ActionTypes;
9
- }>;
10
- export declare function getActionFunction<TContext, TEvent extends EventObject>(actionType: ActionType, actionFunctionMap?: ActionFunctionMap<TContext, TEvent>): ActionObject<TContext, TEvent> | ActionFunction<TContext, TEvent> | undefined;
11
- export declare function toActionObject<TContext, TEvent extends EventObject>(action: Action<TContext, TEvent>, actionFunctionMap?: ActionFunctionMap<TContext, TEvent>): ActionObject<TContext, TEvent>;
12
- export declare const toActionObjects: <TContext, TEvent extends EventObject>(action?: SingleOrArray<Action<TContext, TEvent>> | undefined, actionFunctionMap?: ActionFunctionMap<TContext, TEvent> | undefined) => ActionObject<TContext, TEvent>[];
13
- export declare function toActivityDefinition<TContext, TEvent extends EventObject>(action: string | ActivityDefinition<TContext, TEvent>): ActivityDefinition<TContext, TEvent>;
14
- /**
15
- * Raises an event. This places the event in the internal event queue, so that
16
- * the event is immediately consumed by the machine in the current step.
17
- *
18
- * @param eventType The event to raise.
19
- */
20
- export declare function raise<TContext, TEvent extends EventObject>(event: Event<TEvent>): RaiseAction<TEvent> | SendAction<TContext, AnyEventObject, TEvent>;
21
- export declare function resolveRaise<TEvent extends EventObject>(action: RaiseAction<TEvent>): RaiseActionObject<TEvent>;
22
- /**
23
- * Sends an event. This returns an action that will be read by an interpreter to
24
- * send the event in the next step, after the current step is finished executing.
25
- *
26
- * @param event The event to send.
27
- * @param options Options to pass into the send event:
28
- * - `id` - The unique send event identifier (used with `cancel()`).
29
- * - `delay` - The number of milliseconds to delay the sending of the event.
30
- * - `to` - The target of this event (by default, the machine the event was sent from).
31
- */
32
- export declare function send<TContext, TEvent extends EventObject, TSentEvent extends EventObject = AnyEventObject>(event: Event<TSentEvent> | SendExpr<TContext, TEvent, TSentEvent>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, TSentEvent>;
33
- export declare function resolveSend<TContext, TEvent extends EventObject, TSentEvent extends EventObject>(action: SendAction<TContext, TEvent, TSentEvent>, ctx: TContext, _event: SCXML.Event<TEvent>, delaysMap?: DelayFunctionMap<TContext, TEvent>): SendActionObject<TContext, TEvent, TSentEvent>;
34
- /**
35
- * Sends an event to this machine's parent.
36
- *
37
- * @param event The event to send to the parent machine.
38
- * @param options Options to pass into the send event.
39
- */
40
- export declare function sendParent<TContext, TEvent extends EventObject, TSentEvent extends EventObject = AnyEventObject>(event: Event<TSentEvent> | SendExpr<TContext, TEvent, TSentEvent>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, TSentEvent>;
41
- /**
42
- * Sends an update event to this machine's parent.
43
- */
44
- export declare function sendUpdate<TContext, TEvent extends EventObject>(): SendAction<TContext, TEvent, {
45
- type: ActionTypes.Update;
46
- }>;
47
- /**
48
- * Sends an event back to the sender of the original event.
49
- *
50
- * @param event The event to send back to the sender
51
- * @param options Options to pass into the send event
52
- */
53
- export declare function respond<TContext, TEvent extends EventObject, TSentEvent extends EventObject = AnyEventObject>(event: Event<TEvent> | SendExpr<TContext, TEvent, TSentEvent>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, AnyEventObject>;
54
- /**
55
- *
56
- * @param expr The expression function to evaluate which will be logged.
57
- * Takes in 2 arguments:
58
- * - `ctx` - the current state context
59
- * - `event` - the event that caused this action to be executed.
60
- * @param label The label to give to the logged expression.
61
- */
62
- export declare function log<TContext, TEvent extends EventObject>(expr?: string | LogExpr<TContext, TEvent>, label?: string): LogAction<TContext, TEvent>;
63
- export declare const resolveLog: <TContext, TEvent extends EventObject>(action: LogAction<TContext, TEvent>, ctx: TContext, _event: SCXML.Event<TEvent>) => LogActionObject<TContext, TEvent>;
64
- /**
65
- * Cancels an in-flight `send(...)` action. A canceled sent action will not
66
- * be executed, nor will its event be sent, unless it has already been sent
67
- * (e.g., if `cancel(...)` is called after the `send(...)` action's `delay`).
68
- *
69
- * @param sendId The `id` of the `send(...)` action to cancel.
70
- */
71
- export declare const cancel: (sendId: string | number) => CancelAction;
72
- /**
73
- * Starts an activity.
74
- *
75
- * @param activity The activity to start.
76
- */
77
- export declare function start<TContext, TEvent extends EventObject>(activity: string | ActivityDefinition<TContext, TEvent>): ActivityActionObject<TContext, TEvent>;
78
- /**
79
- * Stops an activity.
80
- *
81
- * @param actorRef The activity to stop.
82
- */
83
- export declare function stop<TContext, TEvent extends EventObject>(actorRef: string | ActivityDefinition<TContext, TEvent> | Expr<TContext, TEvent, string | {
84
- id: string;
85
- }>): StopAction<TContext, TEvent>;
86
- export declare function resolveStop<TContext, TEvent extends EventObject>(action: StopAction<TContext, TEvent>, context: TContext, _event: SCXML.Event<TEvent>): StopActionObject;
87
- /**
88
- * Updates the current context of the machine.
89
- *
90
- * @param assignment An object that represents the partial context to update.
91
- */
92
- export declare const assign: <TContext, TEvent extends EventObject = EventObject>(assignment: Assigner<TContext, TEvent> | PropertyAssigner<TContext, TEvent>) => AssignAction<TContext, TEvent>;
93
- export declare function isActionObject<TContext, TEvent extends EventObject>(action: Action<TContext, TEvent>): action is ActionObject<TContext, TEvent>;
94
- /**
95
- * Returns an event type that represents an implicit event that
96
- * is sent after the specified `delay`.
97
- *
98
- * @param delayRef The delay in milliseconds
99
- * @param id The state node ID where this event is handled
100
- */
101
- export declare function after(delayRef: number | string, id?: string): string;
102
- /**
103
- * Returns an event that represents that a final state node
104
- * has been reached in the parent state node.
105
- *
106
- * @param id The final state node's parent state node `id`
107
- * @param data The data to pass into the event
108
- */
109
- export declare function done(id: string, data?: any): DoneEventObject;
110
- /**
111
- * Returns an event that represents that an invoked service has terminated.
112
- *
113
- * An invoked service is terminated when it has reached a top-level final state node,
114
- * but not when it is canceled.
115
- *
116
- * @param id The final state node ID
117
- * @param data The data to pass into the event
118
- */
119
- export declare function doneInvoke(id: string, data?: any): DoneEvent;
120
- export declare function error(id: string, data?: any): ErrorPlatformEvent & string;
121
- export declare function pure<TContext, TEvent extends EventObject>(getActions: (context: TContext, event: TEvent) => SingleOrArray<ActionObject<TContext, TEvent>> | undefined): PureAction<TContext, TEvent>;
122
- /**
123
- * Forwards (sends) an event to a specified service.
124
- *
125
- * @param target The target service to forward the event to.
126
- * @param options Options to pass into the send action creator.
127
- */
128
- export declare function forwardTo<TContext, TEvent extends EventObject>(target: Required<SendActionOptions<TContext, TEvent>>['to'], options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, AnyEventObject>;
129
- /**
130
- * Escalates an error by sending it as an event to this machine's parent.
131
- *
132
- * @param errorData The error data to send, or the expression function that
133
- * takes in the `context`, `event`, and `meta`, and returns the error data to send.
134
- * @param options Options to pass into the send action creator.
135
- */
136
- export declare function escalate<TContext, TEvent extends EventObject, TErrorData = any>(errorData: TErrorData | ExprWithMeta<TContext, TEvent, TErrorData>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, AnyEventObject>;
137
- export declare function choose<TContext, TEvent extends EventObject>(conds: Array<ChooseConditon<TContext, TEvent>>): ChooseAction<TContext, TEvent>;
138
- export declare function resolveActions<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any>, currentState: State<TContext, TEvent> | undefined, currentContext: TContext, _event: SCXML.Event<TEvent>, actions: Array<ActionObject<TContext, TEvent>>): [Array<ActionObject<TContext, TEvent>>, TContext];
1
+ import { Action, Event, EventObject, SingleOrArray, SendAction, SendActionOptions, CancelAction, ActionObject, ActionType, Assigner, PropertyAssigner, AssignAction, ActionFunction, ActionFunctionMap, ActivityActionObject, ActionTypes, ActivityDefinition, RaiseAction, RaiseActionObject, DoneEvent, ErrorPlatformEvent, DoneEventObject, SendExpr, SendActionObject, PureAction, LogExpr, LogAction, LogActionObject, DelayFunctionMap, SCXML, ExprWithMeta, ChooseConditon, ChooseAction, AnyEventObject, Expr } from './types';
2
+ import * as actionTypes from './actionTypes';
3
+ import { State } from './State';
4
+ import { StateNode } from './StateNode';
5
+ import { StopAction, StopActionObject } from '.';
6
+ export { actionTypes };
7
+ export declare const initEvent: SCXML.Event<{
8
+ type: ActionTypes;
9
+ }>;
10
+ export declare function getActionFunction<TContext, TEvent extends EventObject>(actionType: ActionType, actionFunctionMap?: ActionFunctionMap<TContext, TEvent>): ActionObject<TContext, TEvent> | ActionFunction<TContext, TEvent> | undefined;
11
+ export declare function toActionObject<TContext, TEvent extends EventObject>(action: Action<TContext, TEvent>, actionFunctionMap?: ActionFunctionMap<TContext, TEvent>): ActionObject<TContext, TEvent>;
12
+ export declare const toActionObjects: <TContext, TEvent extends EventObject>(action?: SingleOrArray<Action<TContext, TEvent>> | undefined, actionFunctionMap?: ActionFunctionMap<TContext, TEvent> | undefined) => ActionObject<TContext, TEvent>[];
13
+ export declare function toActivityDefinition<TContext, TEvent extends EventObject>(action: string | ActivityDefinition<TContext, TEvent>): ActivityDefinition<TContext, TEvent>;
14
+ /**
15
+ * Raises an event. This places the event in the internal event queue, so that
16
+ * the event is immediately consumed by the machine in the current step.
17
+ *
18
+ * @param eventType The event to raise.
19
+ */
20
+ export declare function raise<TContext, TEvent extends EventObject>(event: Event<TEvent>): RaiseAction<TEvent> | SendAction<TContext, AnyEventObject, TEvent>;
21
+ export declare function resolveRaise<TEvent extends EventObject>(action: RaiseAction<TEvent>): RaiseActionObject<TEvent>;
22
+ /**
23
+ * Sends an event. This returns an action that will be read by an interpreter to
24
+ * send the event in the next step, after the current step is finished executing.
25
+ *
26
+ * @param event The event to send.
27
+ * @param options Options to pass into the send event:
28
+ * - `id` - The unique send event identifier (used with `cancel()`).
29
+ * - `delay` - The number of milliseconds to delay the sending of the event.
30
+ * - `to` - The target of this event (by default, the machine the event was sent from).
31
+ */
32
+ export declare function send<TContext, TEvent extends EventObject, TSentEvent extends EventObject = AnyEventObject>(event: Event<TSentEvent> | SendExpr<TContext, TEvent, TSentEvent>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, TSentEvent>;
33
+ export declare function resolveSend<TContext, TEvent extends EventObject, TSentEvent extends EventObject>(action: SendAction<TContext, TEvent, TSentEvent>, ctx: TContext, _event: SCXML.Event<TEvent>, delaysMap?: DelayFunctionMap<TContext, TEvent>): SendActionObject<TContext, TEvent, TSentEvent>;
34
+ /**
35
+ * Sends an event to this machine's parent.
36
+ *
37
+ * @param event The event to send to the parent machine.
38
+ * @param options Options to pass into the send event.
39
+ */
40
+ export declare function sendParent<TContext, TEvent extends EventObject, TSentEvent extends EventObject = AnyEventObject>(event: Event<TSentEvent> | SendExpr<TContext, TEvent, TSentEvent>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, TSentEvent>;
41
+ /**
42
+ * Sends an update event to this machine's parent.
43
+ */
44
+ export declare function sendUpdate<TContext, TEvent extends EventObject>(): SendAction<TContext, TEvent, {
45
+ type: ActionTypes.Update;
46
+ }>;
47
+ /**
48
+ * Sends an event back to the sender of the original event.
49
+ *
50
+ * @param event The event to send back to the sender
51
+ * @param options Options to pass into the send event
52
+ */
53
+ export declare function respond<TContext, TEvent extends EventObject, TSentEvent extends EventObject = AnyEventObject>(event: Event<TEvent> | SendExpr<TContext, TEvent, TSentEvent>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, AnyEventObject>;
54
+ /**
55
+ *
56
+ * @param expr The expression function to evaluate which will be logged.
57
+ * Takes in 2 arguments:
58
+ * - `ctx` - the current state context
59
+ * - `event` - the event that caused this action to be executed.
60
+ * @param label The label to give to the logged expression.
61
+ */
62
+ export declare function log<TContext, TEvent extends EventObject>(expr?: string | LogExpr<TContext, TEvent>, label?: string): LogAction<TContext, TEvent>;
63
+ export declare const resolveLog: <TContext, TEvent extends EventObject>(action: LogAction<TContext, TEvent>, ctx: TContext, _event: SCXML.Event<TEvent>) => LogActionObject<TContext, TEvent>;
64
+ /**
65
+ * Cancels an in-flight `send(...)` action. A canceled sent action will not
66
+ * be executed, nor will its event be sent, unless it has already been sent
67
+ * (e.g., if `cancel(...)` is called after the `send(...)` action's `delay`).
68
+ *
69
+ * @param sendId The `id` of the `send(...)` action to cancel.
70
+ */
71
+ export declare const cancel: (sendId: string | number) => CancelAction;
72
+ /**
73
+ * Starts an activity.
74
+ *
75
+ * @param activity The activity to start.
76
+ */
77
+ export declare function start<TContext, TEvent extends EventObject>(activity: string | ActivityDefinition<TContext, TEvent>): ActivityActionObject<TContext, TEvent>;
78
+ /**
79
+ * Stops an activity.
80
+ *
81
+ * @param actorRef The activity to stop.
82
+ */
83
+ export declare function stop<TContext, TEvent extends EventObject>(actorRef: string | ActivityDefinition<TContext, TEvent> | Expr<TContext, TEvent, string | {
84
+ id: string;
85
+ }>): StopAction<TContext, TEvent>;
86
+ export declare function resolveStop<TContext, TEvent extends EventObject>(action: StopAction<TContext, TEvent>, context: TContext, _event: SCXML.Event<TEvent>): StopActionObject;
87
+ /**
88
+ * Updates the current context of the machine.
89
+ *
90
+ * @param assignment An object that represents the partial context to update.
91
+ */
92
+ export declare const assign: <TContext, TEvent extends EventObject = EventObject>(assignment: Assigner<TContext, TEvent> | PropertyAssigner<TContext, TEvent>) => AssignAction<TContext, TEvent>;
93
+ export declare function isActionObject<TContext, TEvent extends EventObject>(action: Action<TContext, TEvent>): action is ActionObject<TContext, TEvent>;
94
+ /**
95
+ * Returns an event type that represents an implicit event that
96
+ * is sent after the specified `delay`.
97
+ *
98
+ * @param delayRef The delay in milliseconds
99
+ * @param id The state node ID where this event is handled
100
+ */
101
+ export declare function after(delayRef: number | string, id?: string): string;
102
+ /**
103
+ * Returns an event that represents that a final state node
104
+ * has been reached in the parent state node.
105
+ *
106
+ * @param id The final state node's parent state node `id`
107
+ * @param data The data to pass into the event
108
+ */
109
+ export declare function done(id: string, data?: any): DoneEventObject;
110
+ /**
111
+ * Returns an event that represents that an invoked service has terminated.
112
+ *
113
+ * An invoked service is terminated when it has reached a top-level final state node,
114
+ * but not when it is canceled.
115
+ *
116
+ * @param id The final state node ID
117
+ * @param data The data to pass into the event
118
+ */
119
+ export declare function doneInvoke(id: string, data?: any): DoneEvent;
120
+ export declare function error(id: string, data?: any): ErrorPlatformEvent & string;
121
+ export declare function pure<TContext, TEvent extends EventObject>(getActions: (context: TContext, event: TEvent) => SingleOrArray<ActionObject<TContext, TEvent>> | undefined): PureAction<TContext, TEvent>;
122
+ /**
123
+ * Forwards (sends) an event to a specified service.
124
+ *
125
+ * @param target The target service to forward the event to.
126
+ * @param options Options to pass into the send action creator.
127
+ */
128
+ export declare function forwardTo<TContext, TEvent extends EventObject>(target: Required<SendActionOptions<TContext, TEvent>>['to'], options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, AnyEventObject>;
129
+ /**
130
+ * Escalates an error by sending it as an event to this machine's parent.
131
+ *
132
+ * @param errorData The error data to send, or the expression function that
133
+ * takes in the `context`, `event`, and `meta`, and returns the error data to send.
134
+ * @param options Options to pass into the send action creator.
135
+ */
136
+ export declare function escalate<TContext, TEvent extends EventObject, TErrorData = any>(errorData: TErrorData | ExprWithMeta<TContext, TEvent, TErrorData>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, AnyEventObject>;
137
+ export declare function choose<TContext, TEvent extends EventObject>(conds: Array<ChooseConditon<TContext, TEvent>>): ChooseAction<TContext, TEvent>;
138
+ export declare function resolveActions<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any>, currentState: State<TContext, TEvent> | undefined, currentContext: TContext, _event: SCXML.Event<TEvent>, actions: Array<ActionObject<TContext, TEvent>>, preserveActionOrder?: boolean): [Array<ActionObject<TContext, TEvent>>, TContext];
139
139
  //# sourceMappingURL=actions.d.ts.map