xstate 4.32.1 → 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 +483 -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 +6 -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 +16 -17
  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 -56
  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 -133
  141. package/es/types.d.ts +0 -1031
  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 -71
  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 -1031
  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 -75
package/es/waitFor.js DELETED
@@ -1,71 +0,0 @@
1
- import { __assign } from './_virtual/_tslib.js';
2
-
3
- var defaultWaitForOptions = {
4
- timeout: 10000 // 10 seconds
5
-
6
- };
7
- /**
8
- * Subscribes to an actor ref and waits for its emitted value to satisfy
9
- * a predicate, and then resolves with that value.
10
- *
11
- * @example
12
- * ```js
13
- * const state = await waitFor(someService, state => {
14
- * return state.hasTag('loaded');
15
- * });
16
- *
17
- * state.hasTag('loaded'); // true
18
- * ```
19
- *
20
- * @param actorRef The actor ref to subscribe to
21
- * @param predicate Determines if a value matches the condition to wait for
22
- * @param options
23
- * @returns A promise that eventually resolves to the emitted value
24
- * that matches the condition
25
- */
26
-
27
- function waitFor(actorRef, predicate, options) {
28
- var resolvedOptions = __assign(__assign({}, defaultWaitForOptions), options);
29
-
30
- return new Promise(function (res, rej) {
31
- var done = false;
32
-
33
- if (process.env.NODE_ENV !== 'production' && resolvedOptions.timeout < 0) {
34
- console.error('`timeout` passed to `waitFor` is negative and it will reject its internal promise immediately.');
35
- }
36
-
37
- var handle = resolvedOptions.timeout === Infinity ? undefined : setTimeout(function () {
38
- sub.unsubscribe();
39
- rej(new Error("Timeout of ".concat(resolvedOptions.timeout, " ms exceeded")));
40
- }, resolvedOptions.timeout);
41
-
42
- var dispose = function () {
43
- clearTimeout(handle);
44
- done = true;
45
- sub === null || sub === void 0 ? void 0 : sub.unsubscribe();
46
- };
47
-
48
- var sub = actorRef.subscribe({
49
- next: function (emitted) {
50
- if (predicate(emitted)) {
51
- dispose();
52
- res(emitted);
53
- }
54
- },
55
- error: function (err) {
56
- dispose();
57
- rej(err);
58
- },
59
- complete: function () {
60
- dispose();
61
- rej(new Error("Actor terminated without satisfying predicate"));
62
- }
63
- });
64
-
65
- if (done) {
66
- sub.unsubscribe();
67
- }
68
- });
69
- }
70
-
71
- export { waitFor };
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" | "configuration" | "transitions" | "tags"> & {
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