xstate 4.31.0 → 5.0.0-alpha.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 (206) hide show
  1. package/CHANGELOG.md +526 -0
  2. package/actions/ExecutableAction.ts +58 -0
  3. package/actions/dist/xstate-actions.cjs.d.ts +1 -0
  4. package/actions/dist/xstate-actions.cjs.dev.js +32 -0
  5. package/actions/dist/xstate-actions.cjs.js +7 -0
  6. package/actions/dist/xstate-actions.cjs.prod.js +32 -0
  7. package/actions/dist/xstate-actions.esm.js +2 -0
  8. package/actions/dynamicAction.ts +34 -0
  9. package/actions/package.json +4 -0
  10. package/actors/dist/xstate-actors.cjs.d.ts +1 -0
  11. package/actors/dist/xstate-actors.cjs.dev.js +21 -0
  12. package/actors/dist/xstate-actors.cjs.js +7 -0
  13. package/actors/dist/xstate-actors.cjs.prod.js +21 -0
  14. package/actors/dist/xstate-actors.esm.js +2 -0
  15. package/actors/package.json +4 -0
  16. package/dev/dist/xstate-dev.cjs.d.ts +1 -0
  17. package/dev/dist/xstate-dev.cjs.dev.js +11 -0
  18. package/dev/dist/xstate-dev.cjs.js +7 -0
  19. package/{lib/devTools.js → dev/dist/xstate-dev.cjs.prod.js} +17 -10
  20. package/dev/dist/xstate-dev.esm.js +1 -0
  21. package/dev/package.json +4 -0
  22. package/dist/Machine-9ce74c11.cjs.dev.js +755 -0
  23. package/dist/Machine-dca041dc.cjs.prod.js +749 -0
  24. package/dist/Machine-fb2f47f5.esm.js +751 -0
  25. package/dist/actions-6b86876d.cjs.dev.js +4815 -0
  26. package/dist/actions-70094c93.cjs.prod.js +4765 -0
  27. package/dist/actions-ff512f16.esm.js +4757 -0
  28. package/dist/declarations/actions/ExecutableAction.d.ts +23 -0
  29. package/dist/declarations/actions/dynamicAction.d.ts +3 -0
  30. package/dist/declarations/src/Machine.d.ts +4 -0
  31. package/dist/declarations/src/Mailbox.d.ts +12 -0
  32. package/dist/declarations/src/ObservableActorRef.d.ts +25 -0
  33. package/{lib → dist/declarations/src}/SimulatedClock.d.ts +0 -1
  34. package/dist/declarations/src/State.d.ts +104 -0
  35. package/dist/declarations/src/StateMachine.d.ts +112 -0
  36. package/dist/declarations/src/StateNode.d.ts +127 -0
  37. package/{es → dist/declarations/src}/actionTypes.d.ts +0 -3
  38. package/dist/declarations/src/actions/assign.d.ts +7 -0
  39. package/dist/declarations/src/actions/cancel.d.ts +10 -0
  40. package/dist/declarations/src/actions/choose.d.ts +3 -0
  41. package/dist/declarations/src/actions/invoke.d.ts +3 -0
  42. package/dist/declarations/src/actions/log.d.ts +11 -0
  43. package/dist/declarations/src/actions/pure.d.ts +3 -0
  44. package/dist/declarations/src/actions/raise.d.ts +9 -0
  45. package/dist/declarations/src/actions/send.d.ts +55 -0
  46. package/dist/declarations/src/actions/stop.d.ts +8 -0
  47. package/dist/declarations/src/actions.d.ts +44 -0
  48. package/dist/declarations/src/actors.d.ts +38 -0
  49. package/dist/declarations/src/constants.d.ts +5 -0
  50. package/{lib/devTools.d.ts → dist/declarations/src/dev/index.d.ts} +2 -2
  51. package/{es → dist/declarations/src}/environment.d.ts +0 -1
  52. package/dist/declarations/src/guards.d.ts +9 -0
  53. package/dist/declarations/src/index.d.ts +47 -0
  54. package/dist/declarations/src/interpreter.d.ts +147 -0
  55. package/{es → dist/declarations/src}/mapState.d.ts +0 -1
  56. package/dist/declarations/src/match.d.ts +5 -0
  57. package/dist/declarations/src/memo.d.ts +1 -0
  58. package/dist/declarations/src/model.d.ts +5 -0
  59. package/{lib → dist/declarations/src}/model.types.d.ts +10 -9
  60. package/dist/declarations/src/registry.d.ts +8 -0
  61. package/{es → dist/declarations/src}/schema.d.ts +0 -1
  62. package/dist/declarations/src/spawn.d.ts +2 -0
  63. package/dist/declarations/src/stateUtils.d.ts +85 -0
  64. package/{lib → dist/declarations/src}/typegenTypes.d.ts +28 -26
  65. package/dist/declarations/src/types.d.ts +1026 -0
  66. package/dist/declarations/src/utils.d.ts +56 -0
  67. package/{es/devTools.js → dist/index-20b364c4.esm.js} +18 -6
  68. package/dist/index-2a564d03.cjs.dev.js +64 -0
  69. package/dist/xstate.cjs.d.ts +1 -0
  70. package/dist/xstate.cjs.dev.js +217 -0
  71. package/dist/xstate.cjs.js +7 -0
  72. package/dist/xstate.cjs.prod.js +217 -0
  73. package/dist/xstate.esm.js +172 -0
  74. package/guards/dist/xstate-guards.cjs.d.ts +1 -0
  75. package/guards/dist/xstate-guards.cjs.dev.js +15 -0
  76. package/guards/dist/xstate-guards.cjs.js +7 -0
  77. package/guards/dist/xstate-guards.cjs.prod.js +15 -0
  78. package/guards/dist/xstate-guards.esm.js +2 -0
  79. package/guards/package.json +4 -0
  80. package/invoke/package.json +4 -0
  81. package/model/dist/xstate-model.cjs.d.ts +1 -0
  82. package/model/dist/xstate-model.cjs.dev.js +41 -0
  83. package/model/dist/xstate-model.cjs.js +7 -0
  84. package/model/dist/xstate-model.cjs.prod.js +41 -0
  85. package/model/dist/xstate-model.esm.js +37 -0
  86. package/model/package.json +4 -0
  87. package/package.json +21 -30
  88. package/dist/xstate.interpreter.js +0 -15
  89. package/dist/xstate.js +0 -15
  90. package/dist/xstate.web.js +0 -15
  91. package/es/Actor.d.ts +0 -25
  92. package/es/Actor.js +0 -99
  93. package/es/Machine.d.ts +0 -12
  94. package/es/Machine.js +0 -14
  95. package/es/SimulatedClock.d.ts +0 -17
  96. package/es/SimulatedClock.js +0 -81
  97. package/es/State.d.ts +0 -123
  98. package/es/State.js +0 -274
  99. package/es/StateNode.d.ts +0 -287
  100. package/es/StateNode.js +0 -1566
  101. package/es/_virtual/_tslib.js +0 -78
  102. package/es/actionTypes.js +0 -22
  103. package/es/actions.d.ts +0 -154
  104. package/es/actions.js +0 -520
  105. package/es/behaviors.d.ts +0 -37
  106. package/es/behaviors.js +0 -131
  107. package/es/constants.d.ts +0 -6
  108. package/es/constants.js +0 -6
  109. package/es/devTools.d.ts +0 -14
  110. package/es/each.d.ts +0 -4
  111. package/es/each.js +0 -13
  112. package/es/environment.js +0 -3
  113. package/es/index.d.ts +0 -22
  114. package/es/index.js +0 -23
  115. package/es/interpreter.d.ts +0 -209
  116. package/es/interpreter.js +0 -1402
  117. package/es/invoke.d.ts +0 -11
  118. package/es/invokeUtils.d.ts +0 -7
  119. package/es/invokeUtils.js +0 -40
  120. package/es/json.d.ts +0 -31
  121. package/es/json.js +0 -86
  122. package/es/mapState.js +0 -32
  123. package/es/match.d.ts +0 -9
  124. package/es/match.js +0 -34
  125. package/es/model.d.ts +0 -5
  126. package/es/model.js +0 -50
  127. package/es/model.types.d.ts +0 -52
  128. package/es/patterns.d.ts +0 -14
  129. package/es/patterns.js +0 -48
  130. package/es/registry.d.ts +0 -9
  131. package/es/registry.js +0 -19
  132. package/es/scheduler.d.ts +0 -17
  133. package/es/scheduler.js +0 -79
  134. package/es/schema.js +0 -6
  135. package/es/scxml.d.ts +0 -6
  136. package/es/serviceScope.d.ts +0 -4
  137. package/es/serviceScope.js +0 -16
  138. package/es/stateUtils.d.ts +0 -17
  139. package/es/stateUtils.js +0 -259
  140. package/es/typegenTypes.d.ts +0 -130
  141. package/es/types.d.ts +0 -1037
  142. package/es/types.js +0 -33
  143. package/es/utils.d.ts +0 -72
  144. package/es/utils.js +0 -626
  145. package/es/waitFor.d.ts +0 -32
  146. package/es/waitFor.js +0 -66
  147. package/lib/Actor.d.ts +0 -25
  148. package/lib/Actor.js +0 -108
  149. package/lib/Machine.d.ts +0 -12
  150. package/lib/Machine.js +0 -19
  151. package/lib/SimulatedClock.js +0 -85
  152. package/lib/State.d.ts +0 -123
  153. package/lib/State.js +0 -282
  154. package/lib/StateNode.d.ts +0 -287
  155. package/lib/StateNode.js +0 -1570
  156. package/lib/_virtual/_tslib.js +0 -85
  157. package/lib/actionTypes.d.ts +0 -20
  158. package/lib/actionTypes.js +0 -43
  159. package/lib/actions.d.ts +0 -154
  160. package/lib/actions.js +0 -552
  161. package/lib/behaviors.d.ts +0 -37
  162. package/lib/behaviors.js +0 -137
  163. package/lib/constants.d.ts +0 -6
  164. package/lib/constants.js +0 -13
  165. package/lib/each.d.ts +0 -4
  166. package/lib/each.js +0 -17
  167. package/lib/environment.d.ts +0 -2
  168. package/lib/environment.js +0 -7
  169. package/lib/index.d.ts +0 -22
  170. package/lib/index.js +0 -60
  171. package/lib/interpreter.d.ts +0 -209
  172. package/lib/interpreter.js +0 -1408
  173. package/lib/invoke.d.ts +0 -11
  174. package/lib/invoke.js +0 -20
  175. package/lib/invokeUtils.d.ts +0 -7
  176. package/lib/invokeUtils.js +0 -45
  177. package/lib/json.d.ts +0 -31
  178. package/lib/json.js +0 -94
  179. package/lib/mapState.d.ts +0 -4
  180. package/lib/mapState.js +0 -36
  181. package/lib/match.d.ts +0 -9
  182. package/lib/match.js +0 -38
  183. package/lib/model.d.ts +0 -5
  184. package/lib/model.js +0 -54
  185. package/lib/model.types.js +0 -2
  186. package/lib/patterns.d.ts +0 -14
  187. package/lib/patterns.js +0 -53
  188. package/lib/registry.d.ts +0 -9
  189. package/lib/registry.js +0 -23
  190. package/lib/scheduler.d.ts +0 -17
  191. package/lib/scheduler.js +0 -83
  192. package/lib/schema.d.ts +0 -3
  193. package/lib/schema.js +0 -11
  194. package/lib/scxml.d.ts +0 -6
  195. package/lib/scxml.js +0 -350
  196. package/lib/serviceScope.d.ts +0 -4
  197. package/lib/serviceScope.js +0 -21
  198. package/lib/stateUtils.d.ts +0 -17
  199. package/lib/stateUtils.js +0 -273
  200. package/lib/typegenTypes.js +0 -2
  201. package/lib/types.d.ts +0 -1037
  202. package/lib/types.js +0 -35
  203. package/lib/utils.d.ts +0 -72
  204. package/lib/utils.js +0 -673
  205. package/lib/waitFor.d.ts +0 -32
  206. package/lib/waitFor.js +0 -70
package/lib/Actor.d.ts DELETED
@@ -1,25 +0,0 @@
1
- import { EventObject, Subscribable, InvokeDefinition, AnyEventObject, StateMachine, Spawnable, SCXML, ActorRef, BaseActorRef } from './types';
2
- export interface Actor<TContext = any, TEvent extends EventObject = AnyEventObject> extends Subscribable<TContext> {
3
- id: string;
4
- send: (event: TEvent) => any;
5
- stop?: () => any | undefined;
6
- toJSON: () => {
7
- id: string;
8
- };
9
- meta?: InvokeDefinition<TContext, TEvent>;
10
- state?: any;
11
- deferred?: boolean;
12
- }
13
- export declare function createNullActor(id: string): ActorRef<any>;
14
- /**
15
- * Creates a deferred actor that is able to be invoked given the provided
16
- * invocation information in its `.meta` value.
17
- *
18
- * @param invokeDefinition The meta information needed to invoke the actor.
19
- */
20
- export declare function createInvocableActor<TC, TE extends EventObject>(invokeDefinition: InvokeDefinition<TC, TE>, machine: StateMachine<TC, any, TE, any>, context: TC, _event: SCXML.Event<TE>): ActorRef<any>;
21
- export declare function createDeferredActor(entity: Spawnable, id: string, data?: any): ActorRef<any, undefined>;
22
- export declare function isActor(item: any): item is ActorRef<any>;
23
- export declare function isSpawnedActor(item: any): item is ActorRef<any>;
24
- export declare function toActorRef<TEvent extends EventObject, TEmitted = any, TActorRefLike extends BaseActorRef<TEvent> = BaseActorRef<TEvent>>(actorRefLike: TActorRefLike): ActorRef<TEvent, TEmitted> & Omit<TActorRefLike, keyof ActorRef<any, any>>;
25
- //# sourceMappingURL=Actor.d.ts.map
package/lib/Actor.js DELETED
@@ -1,108 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var _tslib = require('./_virtual/_tslib.js');
6
- var utils = require('./utils.js');
7
- var serviceScope = require('./serviceScope.js');
8
-
9
- function createNullActor(id) {
10
- var _a;
11
-
12
- return _a = {
13
- id: id,
14
- send: function () {
15
- return void 0;
16
- },
17
- subscribe: function () {
18
- return {
19
- unsubscribe: function () {
20
- return void 0;
21
- }
22
- };
23
- },
24
- getSnapshot: function () {
25
- return undefined;
26
- },
27
- toJSON: function () {
28
- return {
29
- id: id
30
- };
31
- }
32
- }, _a[utils.symbolObservable] = function () {
33
- return this;
34
- }, _a;
35
- }
36
- /**
37
- * Creates a deferred actor that is able to be invoked given the provided
38
- * invocation information in its `.meta` value.
39
- *
40
- * @param invokeDefinition The meta information needed to invoke the actor.
41
- */
42
-
43
- function createInvocableActor(invokeDefinition, machine, context, _event) {
44
- var _a;
45
-
46
- var invokeSrc = utils.toInvokeSource(invokeDefinition.src);
47
- var serviceCreator = (_a = machine === null || machine === void 0 ? void 0 : machine.options.services) === null || _a === void 0 ? void 0 : _a[invokeSrc.type];
48
- var resolvedData = invokeDefinition.data ? utils.mapContext(invokeDefinition.data, context, _event) : undefined;
49
- var tempActor = serviceCreator ? createDeferredActor(serviceCreator, invokeDefinition.id, resolvedData) : createNullActor(invokeDefinition.id); // @ts-ignore
50
-
51
- tempActor.meta = invokeDefinition;
52
- return tempActor;
53
- }
54
- function createDeferredActor(entity, id, data) {
55
- var tempActor = createNullActor(id); // @ts-ignore
56
-
57
- tempActor.deferred = true;
58
-
59
- if (utils.isMachine(entity)) {
60
- // "mute" the existing service scope so potential spawned actors within the `.initialState` stay deferred here
61
- var initialState_1 = tempActor.state = serviceScope.provide(undefined, function () {
62
- return (data ? entity.withContext(data) : entity).initialState;
63
- });
64
-
65
- tempActor.getSnapshot = function () {
66
- return initialState_1;
67
- };
68
- }
69
-
70
- return tempActor;
71
- }
72
- function isActor(item) {
73
- try {
74
- return typeof item.send === 'function';
75
- } catch (e) {
76
- return false;
77
- }
78
- }
79
- function isSpawnedActor(item) {
80
- return isActor(item) && 'id' in item;
81
- } // TODO: refactor the return type, this could be written in a better way but it's best to avoid unneccessary breaking changes now
82
-
83
- function toActorRef(actorRefLike) {
84
- var _a;
85
-
86
- return _tslib.__assign((_a = {
87
- subscribe: function () {
88
- return {
89
- unsubscribe: function () {
90
- return void 0;
91
- }
92
- };
93
- },
94
- id: 'anonymous',
95
- getSnapshot: function () {
96
- return undefined;
97
- }
98
- }, _a[utils.symbolObservable] = function () {
99
- return this;
100
- }, _a), actorRefLike);
101
- }
102
-
103
- exports.createDeferredActor = createDeferredActor;
104
- exports.createInvocableActor = createInvocableActor;
105
- exports.createNullActor = createNullActor;
106
- exports.isActor = isActor;
107
- exports.isSpawnedActor = isSpawnedActor;
108
- exports.toActorRef = toActorRef;
package/lib/Machine.d.ts DELETED
@@ -1,12 +0,0 @@
1
- import { AnyEventObject, BaseActionObject, DefaultContext, EventObject, MachineConfig, InternalMachineOptions, StateMachine, StateSchema, Typestate, ServiceMap } from './types';
2
- import { TypegenConstraint, TypegenDisabled, ResolveTypegenMeta } from './typegenTypes';
3
- /**
4
- * @deprecated Use `createMachine(...)` instead.
5
- */
6
- export declare function Machine<TContext = any, TEvent extends EventObject = AnyEventObject>(config: MachineConfig<TContext, any, TEvent>, options?: InternalMachineOptions<TContext, TEvent, ResolveTypegenMeta<TypegenDisabled, TEvent, BaseActionObject, ServiceMap>>, initialContext?: TContext): StateMachine<TContext, any, TEvent, any, BaseActionObject, ServiceMap, ResolveTypegenMeta<TypegenDisabled, TEvent, BaseActionObject, ServiceMap>>;
7
- export declare function Machine<TContext = DefaultContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = AnyEventObject>(config: MachineConfig<TContext, TStateSchema, TEvent>, options?: InternalMachineOptions<TContext, TEvent, ResolveTypegenMeta<TypegenDisabled, TEvent, BaseActionObject, ServiceMap>>, initialContext?: TContext): StateMachine<TContext, TStateSchema, TEvent, any, BaseActionObject, ServiceMap, ResolveTypegenMeta<TypegenDisabled, TEvent, BaseActionObject, ServiceMap>>;
8
- export declare function createMachine<TContext, TEvent extends EventObject = AnyEventObject, TTypestate extends Typestate<TContext> = {
9
- value: any;
10
- context: TContext;
11
- }, TServiceMap extends ServiceMap = ServiceMap, TTypesMeta extends TypegenConstraint = TypegenDisabled>(config: MachineConfig<TContext, any, TEvent, BaseActionObject, TServiceMap, TTypesMeta>, options?: InternalMachineOptions<TContext, TEvent, ResolveTypegenMeta<TTypesMeta, TEvent, BaseActionObject, TServiceMap>>): StateMachine<TContext, any, TEvent, TTypestate, BaseActionObject, TServiceMap, ResolveTypegenMeta<TTypesMeta, TEvent, BaseActionObject, TServiceMap>>;
12
- //# sourceMappingURL=Machine.d.ts.map
package/lib/Machine.js DELETED
@@ -1,19 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var StateNode = require('./StateNode.js');
6
-
7
- function Machine(config, options, initialContext) {
8
- if (initialContext === void 0) {
9
- initialContext = config.context;
10
- }
11
-
12
- return new StateNode.StateNode(config, options, initialContext);
13
- }
14
- function createMachine(config, options) {
15
- return new StateNode.StateNode(config, options);
16
- }
17
-
18
- exports.Machine = Machine;
19
- exports.createMachine = createMachine;
@@ -1,85 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var _tslib = require('./_virtual/_tslib.js');
6
-
7
- var SimulatedClock =
8
- /*#__PURE__*/
9
-
10
- /** @class */
11
- function () {
12
- function SimulatedClock() {
13
- this.timeouts = new Map();
14
- this._now = 0;
15
- this._id = 0;
16
- }
17
-
18
- SimulatedClock.prototype.now = function () {
19
- return this._now;
20
- };
21
-
22
- SimulatedClock.prototype.getId = function () {
23
- return this._id++;
24
- };
25
-
26
- SimulatedClock.prototype.setTimeout = function (fn, timeout) {
27
- var id = this.getId();
28
- this.timeouts.set(id, {
29
- start: this.now(),
30
- timeout: timeout,
31
- fn: fn
32
- });
33
- return id;
34
- };
35
-
36
- SimulatedClock.prototype.clearTimeout = function (id) {
37
- this.timeouts.delete(id);
38
- };
39
-
40
- SimulatedClock.prototype.set = function (time) {
41
- if (this._now > time) {
42
- throw new Error('Unable to travel back in time');
43
- }
44
-
45
- this._now = time;
46
- this.flushTimeouts();
47
- };
48
-
49
- SimulatedClock.prototype.flushTimeouts = function () {
50
- var _this = this;
51
-
52
- _tslib.__spreadArray([], _tslib.__read(this.timeouts), false).sort(function (_a, _b) {
53
- var _c = _tslib.__read(_a, 2);
54
- _c[0];
55
- var timeoutA = _c[1];
56
-
57
- var _d = _tslib.__read(_b, 2);
58
- _d[0];
59
- var timeoutB = _d[1];
60
-
61
- var endA = timeoutA.start + timeoutA.timeout;
62
- var endB = timeoutB.start + timeoutB.timeout;
63
- return endB > endA ? -1 : 1;
64
- }).forEach(function (_a) {
65
- var _b = _tslib.__read(_a, 2),
66
- id = _b[0],
67
- timeout = _b[1];
68
-
69
- if (_this.now() - timeout.start >= timeout.timeout) {
70
- _this.timeouts.delete(id);
71
-
72
- timeout.fn.call(null);
73
- }
74
- });
75
- };
76
-
77
- SimulatedClock.prototype.increment = function (ms) {
78
- this._now += ms;
79
- this.flushTimeouts();
80
- };
81
-
82
- return SimulatedClock;
83
- }();
84
-
85
- exports.SimulatedClock = SimulatedClock;
package/lib/State.d.ts DELETED
@@ -1,123 +0,0 @@
1
- import { StateValue, ActivityMap, EventObject, HistoryValue, ActionObject, EventType, StateConfig, SCXML, StateSchema, TransitionDefinition, Typestate, ActorRef, StateMachine, SimpleEventsOf } from './types';
2
- import { StateNode } from './StateNode';
3
- import { TypegenDisabled, TypegenEnabled } from './typegenTypes';
4
- import { BaseActionObject, Prop } from './types';
5
- export declare function stateValuesEqual(a: StateValue | undefined, b: StateValue | undefined): boolean;
6
- export declare function isStateConfig<TContext, TEvent extends EventObject>(state: any): state is StateConfig<TContext, TEvent>;
7
- /**
8
- * @deprecated Use `isStateConfig(object)` or `state instanceof State` instead.
9
- */
10
- export declare const isState: typeof isStateConfig;
11
- export declare function bindActionToState<TC, TE extends EventObject>(action: ActionObject<TC, TE>, state: State<TC, TE, any, any, any>): ActionObject<TC, TE>;
12
- export declare class State<TContext, TEvent extends EventObject = EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
13
- value: any;
14
- context: TContext;
15
- }, TResolvedTypesMeta = TypegenDisabled> {
16
- value: StateValue;
17
- context: TContext;
18
- historyValue?: HistoryValue | undefined;
19
- history?: State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
20
- actions: Array<ActionObject<TContext, TEvent>>;
21
- activities: ActivityMap;
22
- meta: any;
23
- events: TEvent[];
24
- event: TEvent;
25
- _event: SCXML.Event<TEvent>;
26
- _sessionid: string | null;
27
- /**
28
- * Indicates whether the state has changed from the previous state. A state is considered "changed" if:
29
- *
30
- * - Its value is not equal to its previous value, or:
31
- * - It has any new actions (side-effects) to execute.
32
- *
33
- * An initial state (with no history) will return `undefined`.
34
- */
35
- changed: boolean | undefined;
36
- /**
37
- * Indicates whether the state is a final state.
38
- */
39
- done: boolean | undefined;
40
- /**
41
- * The enabled state nodes representative of the state value.
42
- */
43
- configuration: Array<StateNode<TContext, any, TEvent, any, any>>;
44
- /**
45
- * The next events that will cause a transition from the current state.
46
- */
47
- nextEvents: EventType[];
48
- /**
49
- * The transition definitions that resulted in this state.
50
- */
51
- transitions: Array<TransitionDefinition<TContext, TEvent>>;
52
- /**
53
- * An object mapping actor IDs to spawned actors/invoked services.
54
- */
55
- children: Record<string, ActorRef<any>>;
56
- tags: Set<string>;
57
- machine: StateMachine<TContext, any, TEvent, TTypestate, BaseActionObject, any, TResolvedTypesMeta> | undefined;
58
- /**
59
- * Creates a new State instance for the given `stateValue` and `context`.
60
- * @param stateValue
61
- * @param context
62
- */
63
- static from<TC, TE extends EventObject = EventObject>(stateValue: State<TC, TE, any, any, any> | StateValue, context?: TC | undefined): State<TC, TE, any, any, any>;
64
- /**
65
- * Creates a new State instance for the given `config`.
66
- * @param config The state config
67
- */
68
- static create<TC, TE extends EventObject = EventObject>(config: StateConfig<TC, TE>): State<TC, TE, any, any, any>;
69
- /**
70
- * Creates a new `State` instance for the given `stateValue` and `context` with no actions (side-effects).
71
- * @param stateValue
72
- * @param context
73
- */
74
- static inert<TC, TE extends EventObject = EventObject>(stateValue: State<TC, TE, any, any, any> | StateValue, context: TC): State<TC, TE>;
75
- /**
76
- * Creates a new State instance.
77
- * @param value The state value
78
- * @param context The extended state
79
- * @param historyValue The tree representing historical values of the state nodes
80
- * @param history The previous state
81
- * @param actions An array of action objects to execute as side-effects
82
- * @param activities A mapping of activities and whether they are started (`true`) or stopped (`false`).
83
- * @param meta
84
- * @param events Internal event queue. Should be empty with run-to-completion semantics.
85
- * @param configuration
86
- */
87
- constructor(config: StateConfig<TContext, TEvent>);
88
- /**
89
- * Returns an array of all the string leaf state node paths.
90
- * @param stateValue
91
- * @param delimiter The character(s) that separate each subpath in the string state node path.
92
- */
93
- toStrings(stateValue?: StateValue, delimiter?: string): string[];
94
- toJSON(): Omit<this, "machine" | "tags" | "transitions" | "configuration"> & {
95
- tags: string[];
96
- };
97
- /**
98
- * Whether the current state value is a subset of the given parent state value.
99
- * @param parentStateValue
100
- */
101
- matches<TSV extends TResolvedTypesMeta extends TypegenEnabled ? Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'matchesStates'> : never>(parentStateValue: TSV): boolean;
102
- matches<TSV extends TResolvedTypesMeta extends TypegenDisabled ? TTypestate['value'] : never>(parentStateValue: TSV): this is State<(TTypestate extends any ? {
103
- value: TSV;
104
- context: any;
105
- } extends TTypestate ? TTypestate : never : never)['context'], TEvent, TStateSchema, TTypestate, TResolvedTypesMeta> & {
106
- value: TSV;
107
- };
108
- /**
109
- * Whether the current state configuration has a state node with the specified `tag`.
110
- * @param tag
111
- */
112
- hasTag(tag: TResolvedTypesMeta extends TypegenEnabled ? Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'tags'> : string): boolean;
113
- /**
114
- * Determines whether sending the `event` will cause a non-forbidden transition
115
- * to be selected, even if the transitions have no actions nor
116
- * change the state value.
117
- *
118
- * @param event The event to test
119
- * @returns Whether the event will cause a transition
120
- */
121
- can(event: TEvent | SimpleEventsOf<TEvent>['type']): boolean;
122
- }
123
- //# sourceMappingURL=State.d.ts.map
package/lib/State.js DELETED
@@ -1,282 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var _tslib = require('./_virtual/_tslib.js');
6
- var constants = require('./constants.js');
7
- var utils = require('./utils.js');
8
- var stateUtils = require('./stateUtils.js');
9
- var actions = require('./actions.js');
10
- var environment = require('./environment.js');
11
-
12
- function stateValuesEqual(a, b) {
13
- if (a === b) {
14
- return true;
15
- }
16
-
17
- if (a === undefined || b === undefined) {
18
- return false;
19
- }
20
-
21
- if (utils.isString(a) || utils.isString(b)) {
22
- return a === b;
23
- }
24
-
25
- var aKeys = Object.keys(a);
26
- var bKeys = Object.keys(b);
27
- return aKeys.length === bKeys.length && aKeys.every(function (key) {
28
- return stateValuesEqual(a[key], b[key]);
29
- });
30
- }
31
- function isStateConfig(state) {
32
- if (typeof state !== 'object' || state === null) {
33
- return false;
34
- }
35
-
36
- return 'value' in state && '_event' in state;
37
- }
38
- /**
39
- * @deprecated Use `isStateConfig(object)` or `state instanceof State` instead.
40
- */
41
-
42
- var isState = isStateConfig;
43
- function bindActionToState(action, state) {
44
- var exec = action.exec;
45
-
46
- var boundAction = _tslib.__assign(_tslib.__assign({}, action), {
47
- exec: exec !== undefined ? function () {
48
- return exec(state.context, state.event, {
49
- action: action,
50
- state: state,
51
- _event: state._event
52
- });
53
- } : undefined
54
- });
55
-
56
- return boundAction;
57
- }
58
-
59
- var State =
60
- /*#__PURE__*/
61
-
62
- /** @class */
63
- function () {
64
- /**
65
- * Creates a new State instance.
66
- * @param value The state value
67
- * @param context The extended state
68
- * @param historyValue The tree representing historical values of the state nodes
69
- * @param history The previous state
70
- * @param actions An array of action objects to execute as side-effects
71
- * @param activities A mapping of activities and whether they are started (`true`) or stopped (`false`).
72
- * @param meta
73
- * @param events Internal event queue. Should be empty with run-to-completion semantics.
74
- * @param configuration
75
- */
76
- function State(config) {
77
- var _this = this;
78
-
79
- var _a;
80
-
81
- this.actions = [];
82
- this.activities = constants.EMPTY_ACTIVITY_MAP;
83
- this.meta = {};
84
- this.events = [];
85
- this.value = config.value;
86
- this.context = config.context;
87
- this._event = config._event;
88
- this._sessionid = config._sessionid;
89
- this.event = this._event.data;
90
- this.historyValue = config.historyValue;
91
- this.history = config.history;
92
- this.actions = config.actions || [];
93
- this.activities = config.activities || constants.EMPTY_ACTIVITY_MAP;
94
- this.meta = stateUtils.getMeta(config.configuration);
95
- this.events = config.events || [];
96
- this.matches = this.matches.bind(this);
97
- this.toStrings = this.toStrings.bind(this);
98
- this.configuration = config.configuration;
99
- this.transitions = config.transitions;
100
- this.children = config.children;
101
- this.done = !!config.done;
102
- this.tags = (_a = Array.isArray(config.tags) ? new Set(config.tags) : config.tags) !== null && _a !== void 0 ? _a : new Set();
103
- this.machine = config.machine;
104
- Object.defineProperty(this, 'nextEvents', {
105
- get: function () {
106
- return stateUtils.nextEvents(_this.configuration);
107
- }
108
- });
109
- }
110
- /**
111
- * Creates a new State instance for the given `stateValue` and `context`.
112
- * @param stateValue
113
- * @param context
114
- */
115
-
116
-
117
- State.from = function (stateValue, context) {
118
- if (stateValue instanceof State) {
119
- if (stateValue.context !== context) {
120
- return new State({
121
- value: stateValue.value,
122
- context: context,
123
- _event: stateValue._event,
124
- _sessionid: null,
125
- historyValue: stateValue.historyValue,
126
- history: stateValue.history,
127
- actions: [],
128
- activities: stateValue.activities,
129
- meta: {},
130
- events: [],
131
- configuration: [],
132
- transitions: [],
133
- children: {}
134
- });
135
- }
136
-
137
- return stateValue;
138
- }
139
-
140
- var _event = actions.initEvent;
141
- return new State({
142
- value: stateValue,
143
- context: context,
144
- _event: _event,
145
- _sessionid: null,
146
- historyValue: undefined,
147
- history: undefined,
148
- actions: [],
149
- activities: undefined,
150
- meta: undefined,
151
- events: [],
152
- configuration: [],
153
- transitions: [],
154
- children: {}
155
- });
156
- };
157
- /**
158
- * Creates a new State instance for the given `config`.
159
- * @param config The state config
160
- */
161
-
162
-
163
- State.create = function (config) {
164
- return new State(config);
165
- };
166
- /**
167
- * Creates a new `State` instance for the given `stateValue` and `context` with no actions (side-effects).
168
- * @param stateValue
169
- * @param context
170
- */
171
-
172
-
173
- State.inert = function (stateValue, context) {
174
- if (stateValue instanceof State) {
175
- if (!stateValue.actions.length) {
176
- return stateValue;
177
- }
178
-
179
- var _event = actions.initEvent;
180
- return new State({
181
- value: stateValue.value,
182
- context: context,
183
- _event: _event,
184
- _sessionid: null,
185
- historyValue: stateValue.historyValue,
186
- history: stateValue.history,
187
- activities: stateValue.activities,
188
- configuration: stateValue.configuration,
189
- transitions: [],
190
- children: {}
191
- });
192
- }
193
-
194
- return State.from(stateValue, context);
195
- };
196
- /**
197
- * Returns an array of all the string leaf state node paths.
198
- * @param stateValue
199
- * @param delimiter The character(s) that separate each subpath in the string state node path.
200
- */
201
-
202
-
203
- State.prototype.toStrings = function (stateValue, delimiter) {
204
- var _this = this;
205
-
206
- if (stateValue === void 0) {
207
- stateValue = this.value;
208
- }
209
-
210
- if (delimiter === void 0) {
211
- delimiter = '.';
212
- }
213
-
214
- if (utils.isString(stateValue)) {
215
- return [stateValue];
216
- }
217
-
218
- var valueKeys = Object.keys(stateValue);
219
- return valueKeys.concat.apply(valueKeys, _tslib.__spreadArray([], _tslib.__read(valueKeys.map(function (key) {
220
- return _this.toStrings(stateValue[key], delimiter).map(function (s) {
221
- return key + delimiter + s;
222
- });
223
- })), false));
224
- };
225
-
226
- State.prototype.toJSON = function () {
227
- var _a = this;
228
- _a.configuration;
229
- _a.transitions;
230
- var tags = _a.tags;
231
- _a.machine;
232
- var jsonValues = _tslib.__rest(_a, ["configuration", "transitions", "tags", "machine"]);
233
-
234
- return _tslib.__assign(_tslib.__assign({}, jsonValues), {
235
- tags: Array.from(tags)
236
- });
237
- };
238
-
239
- State.prototype.matches = function (parentStateValue) {
240
- return utils.matchesState(parentStateValue, this.value);
241
- };
242
- /**
243
- * Whether the current state configuration has a state node with the specified `tag`.
244
- * @param tag
245
- */
246
-
247
-
248
- State.prototype.hasTag = function (tag) {
249
- return this.tags.has(tag);
250
- };
251
- /**
252
- * Determines whether sending the `event` will cause a non-forbidden transition
253
- * to be selected, even if the transitions have no actions nor
254
- * change the state value.
255
- *
256
- * @param event The event to test
257
- * @returns Whether the event will cause a transition
258
- */
259
-
260
-
261
- State.prototype.can = function (event) {
262
- var _a;
263
-
264
- if (environment.IS_PRODUCTION) {
265
- utils.warn(!!this.machine, "state.can(...) used outside of a machine-created State object; this will always return false.");
266
- }
267
-
268
- var transitionData = (_a = this.machine) === null || _a === void 0 ? void 0 : _a.getTransitionData(this, event);
269
- return !!(transitionData === null || transitionData === void 0 ? void 0 : transitionData.transitions.length) && // Check that at least one transition is not forbidden
270
- transitionData.transitions.some(function (t) {
271
- return t.target !== undefined || t.actions.length;
272
- });
273
- };
274
-
275
- return State;
276
- }();
277
-
278
- exports.State = State;
279
- exports.bindActionToState = bindActionToState;
280
- exports.isState = isState;
281
- exports.isStateConfig = isStateConfig;
282
- exports.stateValuesEqual = stateValuesEqual;