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
@@ -0,0 +1,56 @@
1
+ import { NULL_EVENT } from './constants';
2
+ import type { StateNode } from './StateNode';
3
+ import type { Behavior, BehaviorCreator, Event, EventObject, EventType, InvokeConfig, InvokeSourceDefinition, MachineContext, Mapper, Observer, PropertyMapper, SCXML, SCXMLErrorEvent, SingleOrArray, StateLike, StateValue, Subscribable, TransitionConfig, TransitionConfigTarget } from './types';
4
+ import { AnyStateMachine } from './types';
5
+ export declare function keys<T extends object>(value: T): Array<keyof T & string>;
6
+ export declare function matchesState(parentStateId: StateValue, childStateId: StateValue, delimiter?: string): boolean;
7
+ export declare function getEventType<TEvent extends EventObject = EventObject>(event: Event<TEvent>): TEvent['type'];
8
+ export declare function toStatePath(stateId: string | string[], delimiter: string): string[];
9
+ export declare function isStateLike(state: any): state is StateLike<any>;
10
+ export declare function toStateValue(stateValue: StateLike<any> | StateValue | string[], delimiter: string): StateValue;
11
+ export declare function pathToStateValue(statePath: string[]): StateValue;
12
+ export declare function mapValues<P, O extends Record<string, unknown>>(collection: O, iteratee: (item: O[keyof O], key: keyof O, collection: O, i: number) => P): {
13
+ [key in keyof O]: P;
14
+ };
15
+ export declare function mapFilterValues<T, P>(collection: {
16
+ [key: string]: T;
17
+ }, iteratee: (item: T, key: string, collection: {
18
+ [key: string]: T;
19
+ }) => P, predicate: (item: T) => boolean): {
20
+ [key: string]: P;
21
+ };
22
+ /**
23
+ * Retrieves a value at the given path.
24
+ * @param props The deep path to the prop of the desired value
25
+ */
26
+ export declare function path<T extends Record<string, any>>(props: string[]): any;
27
+ export declare function toStatePaths(stateValue: StateValue | undefined): string[][];
28
+ export declare function flatten<T>(array: Array<T | T[]>): T[];
29
+ export declare function toArrayStrict<T>(value: T[] | T): T[];
30
+ export declare function toArray<T>(value: T[] | T | undefined): T[];
31
+ export declare function mapContext<TContext extends MachineContext, TEvent extends EventObject>(mapper: Mapper<TContext, TEvent, any> | PropertyMapper<TContext, TEvent, any>, context: TContext, _event: SCXML.Event<TEvent>): any;
32
+ export declare function isBuiltInEvent(eventType: EventType): boolean;
33
+ export declare function isPromiseLike(value: any): value is PromiseLike<any>;
34
+ export declare function isBehavior(value: any): value is Behavior<any, any>;
35
+ export declare function partition<T, A extends T, B extends T>(items: T[], predicate: (item: T) => item is A): [A[], B[]];
36
+ export declare let warn: (condition: boolean | Error, message: string) => void;
37
+ export declare function isArray(value: any): value is any[];
38
+ export declare function isFunction(value: any): value is Function;
39
+ export declare function isString(value: any): value is string;
40
+ export declare function isObservable<T>(value: any): value is Subscribable<T>;
41
+ export declare const symbolObservable: typeof Symbol.observable;
42
+ export declare function isStateMachine(value: any): value is AnyStateMachine;
43
+ export declare const uniqueId: () => string;
44
+ export declare function toEventObject<TEvent extends EventObject>(event: Event<TEvent>, payload?: Record<string, any>): TEvent;
45
+ export declare function isSCXMLEvent<TEvent extends EventObject>(event: Event<TEvent> | SCXML.Event<TEvent>): event is SCXML.Event<TEvent>;
46
+ export declare function isSCXMLErrorEvent(event: SCXML.Event<any>): event is SCXMLErrorEvent;
47
+ export declare function toSCXMLEvent<TEvent extends EventObject>(event: Event<TEvent> | SCXML.Event<TEvent>, scxmlEvent?: Partial<SCXML.Event<TEvent>>): SCXML.Event<TEvent>;
48
+ export declare function toTransitionConfigArray<TContext extends MachineContext, TEvent extends EventObject>(event: TEvent['type'] | typeof NULL_EVENT | '*', configLike: SingleOrArray<TransitionConfig<TContext, TEvent> | TransitionConfigTarget<TContext, TEvent>>): Array<TransitionConfig<TContext, TEvent> & {
49
+ event: TEvent['type'] | typeof NULL_EVENT | '*';
50
+ }>;
51
+ export declare function normalizeTarget<TContext extends MachineContext, TEvent extends EventObject>(target: SingleOrArray<string | StateNode<TContext, TEvent>> | undefined): Array<string | StateNode<TContext, TEvent>> | undefined;
52
+ export declare function reportUnhandledExceptionOnInvocation(originalError: any, currentError: any, id: string): void;
53
+ export declare function toInvokeConfig<TContext extends MachineContext, TEvent extends EventObject>(invocable: InvokeConfig<TContext, TEvent> | string | BehaviorCreator<TContext, TEvent> | Behavior<any, any>, id: string): InvokeConfig<TContext, TEvent>;
54
+ export declare function toInvokeSource(src: string | InvokeSourceDefinition): InvokeSourceDefinition;
55
+ export declare function toObserver<T>(nextHandler: Observer<T> | ((value: T) => void), errorHandler?: (error: any) => void, completionHandler?: () => void): Observer<T>;
56
+ export declare function createInvokeId(stateNodeId: string, index: number): string;
@@ -1,5 +1,6 @@
1
- import { IS_PRODUCTION } from './environment.js';
1
+ var IS_PRODUCTION = process.env.NODE_ENV === 'production';
2
2
 
3
+ // From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
3
4
  function getGlobal() {
4
5
  if (typeof globalThis !== 'undefined') {
5
6
  return globalThis;
@@ -23,17 +24,17 @@ function getGlobal() {
23
24
  }
24
25
 
25
26
  function getDevTools() {
26
- var global = getGlobal();
27
+ var w = getGlobal();
27
28
 
28
- if (global && '__xstate__' in global) {
29
- return global.__xstate__;
29
+ if (!!w.__xstate__) {
30
+ return w.__xstate__;
30
31
  }
31
32
 
32
33
  return undefined;
33
34
  }
34
35
 
35
36
  function registerService(service) {
36
- if (!getGlobal()) {
37
+ if (typeof window === 'undefined') {
37
38
  return;
38
39
  }
39
40
 
@@ -43,5 +44,16 @@ function registerService(service) {
43
44
  devTools.register(service);
44
45
  }
45
46
  }
47
+ var devToolsAdapter = function devToolsAdapter(service) {
48
+ if (typeof window === 'undefined') {
49
+ return;
50
+ }
51
+
52
+ var devTools = getDevTools();
53
+
54
+ if (devTools) {
55
+ devTools.register(service);
56
+ }
57
+ };
46
58
 
47
- export { getGlobal, registerService };
59
+ export { IS_PRODUCTION as I, devToolsAdapter as d, getGlobal as g, registerService as r };
@@ -0,0 +1,64 @@
1
+ 'use strict';
2
+
3
+ var IS_PRODUCTION = process.env.NODE_ENV === 'production';
4
+
5
+ // From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
6
+ function getGlobal() {
7
+ if (typeof globalThis !== 'undefined') {
8
+ return globalThis;
9
+ }
10
+
11
+ if (typeof self !== 'undefined') {
12
+ return self;
13
+ }
14
+
15
+ if (typeof window !== 'undefined') {
16
+ return window;
17
+ }
18
+
19
+ if (typeof global !== 'undefined') {
20
+ return global;
21
+ }
22
+
23
+ if (!IS_PRODUCTION) {
24
+ console.warn('XState could not find a global object in this environment. Please let the maintainers know and raise an issue here: https://github.com/statelyai/xstate/issues');
25
+ }
26
+ }
27
+
28
+ function getDevTools() {
29
+ var w = getGlobal();
30
+
31
+ if (!!w.__xstate__) {
32
+ return w.__xstate__;
33
+ }
34
+
35
+ return undefined;
36
+ }
37
+
38
+ function registerService(service) {
39
+ if (typeof window === 'undefined') {
40
+ return;
41
+ }
42
+
43
+ var devTools = getDevTools();
44
+
45
+ if (devTools) {
46
+ devTools.register(service);
47
+ }
48
+ }
49
+ var devToolsAdapter = function devToolsAdapter(service) {
50
+ if (typeof window === 'undefined') {
51
+ return;
52
+ }
53
+
54
+ var devTools = getDevTools();
55
+
56
+ if (devTools) {
57
+ devTools.register(service);
58
+ }
59
+ };
60
+
61
+ exports.IS_PRODUCTION = IS_PRODUCTION;
62
+ exports.devToolsAdapter = devToolsAdapter;
63
+ exports.getGlobal = getGlobal;
64
+ exports.registerService = registerService;
@@ -0,0 +1 @@
1
+ export * from "./declarations/src/index";
@@ -0,0 +1,217 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var guards_dist_xstateGuards = require('./actions-6b86876d.cjs.dev.js');
6
+ require('./index-2a564d03.cjs.dev.js');
7
+ var Machine = require('./Machine-9ce74c11.cjs.dev.js');
8
+
9
+ function pure(getActions) {
10
+ return guards_dist_xstateGuards.createDynamicAction(guards_dist_xstateGuards.pure, {
11
+ get: getActions
12
+ }, function (_ref, ctx, _event) {
13
+ var _toArray;
14
+
15
+ var params = _ref.params;
16
+ return {
17
+ type: guards_dist_xstateGuards.pure,
18
+ params: {
19
+ actions: (_toArray = guards_dist_xstateGuards.toArray(params.get(ctx, _event.data))) !== null && _toArray !== void 0 ? _toArray : []
20
+ }
21
+ };
22
+ });
23
+ }
24
+
25
+ function mapState(stateMap, stateId) {
26
+ var foundStateId;
27
+
28
+ for (var _i = 0, _Object$keys = Object.keys(stateMap); _i < _Object$keys.length; _i++) {
29
+ var mappedStateId = _Object$keys[_i];
30
+
31
+ if (guards_dist_xstateGuards.matchesState(mappedStateId, stateId) && (!foundStateId || stateId.length > foundStateId.length)) {
32
+ foundStateId = mappedStateId;
33
+ }
34
+ }
35
+
36
+ return stateMap[foundStateId];
37
+ }
38
+
39
+ function matchState(state, patterns, defaultValue) {
40
+ var resolvedState = guards_dist_xstateGuards.State.from(state, state instanceof guards_dist_xstateGuards.State ? state.context : undefined);
41
+
42
+ var _iterator = guards_dist_xstateGuards._createForOfIteratorHelper(patterns),
43
+ _step;
44
+
45
+ try {
46
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
47
+ var _step$value = guards_dist_xstateGuards._slicedToArray(_step.value, 2),
48
+ stateValue = _step$value[0],
49
+ getValue = _step$value[1];
50
+
51
+ if (resolvedState.matches(stateValue)) {
52
+ return getValue(resolvedState);
53
+ }
54
+ }
55
+ } catch (err) {
56
+ _iterator.e(err);
57
+ } finally {
58
+ _iterator.f();
59
+ }
60
+
61
+ return defaultValue(resolvedState);
62
+ }
63
+
64
+ function createSchema(schema) {
65
+ return schema;
66
+ }
67
+ var t = createSchema;
68
+
69
+ var SimulatedClock = /*#__PURE__*/function () {
70
+ function SimulatedClock() {
71
+ guards_dist_xstateGuards._classCallCheck(this, SimulatedClock);
72
+
73
+ guards_dist_xstateGuards._defineProperty(this, "timeouts", new Map());
74
+
75
+ guards_dist_xstateGuards._defineProperty(this, "_now", 0);
76
+
77
+ guards_dist_xstateGuards._defineProperty(this, "_id", 0);
78
+ }
79
+
80
+ guards_dist_xstateGuards._createClass(SimulatedClock, [{
81
+ key: "now",
82
+ value: function now() {
83
+ return this._now;
84
+ }
85
+ }, {
86
+ key: "getId",
87
+ value: function getId() {
88
+ return this._id++;
89
+ }
90
+ }, {
91
+ key: "setTimeout",
92
+ value: function setTimeout(fn, timeout) {
93
+ var id = this.getId();
94
+ this.timeouts.set(id, {
95
+ start: this.now(),
96
+ timeout: timeout,
97
+ fn: fn
98
+ });
99
+ return id;
100
+ }
101
+ }, {
102
+ key: "clearTimeout",
103
+ value: function clearTimeout(id) {
104
+ this.timeouts["delete"](id);
105
+ }
106
+ }, {
107
+ key: "set",
108
+ value: function set(time) {
109
+ if (this._now > time) {
110
+ throw new Error('Unable to travel back in time');
111
+ }
112
+
113
+ this._now = time;
114
+ this.flushTimeouts();
115
+ }
116
+ }, {
117
+ key: "flushTimeouts",
118
+ value: function flushTimeouts() {
119
+ var _this = this;
120
+
121
+ guards_dist_xstateGuards._toConsumableArray(this.timeouts).sort(function (_ref, _ref2) {
122
+ var _ref3 = guards_dist_xstateGuards._slicedToArray(_ref, 2),
123
+ _idA = _ref3[0],
124
+ timeoutA = _ref3[1];
125
+
126
+ var _ref4 = guards_dist_xstateGuards._slicedToArray(_ref2, 2),
127
+ _idB = _ref4[0],
128
+ timeoutB = _ref4[1];
129
+
130
+ var endA = timeoutA.start + timeoutA.timeout;
131
+ var endB = timeoutB.start + timeoutB.timeout;
132
+ return endB > endA ? -1 : 1;
133
+ }).forEach(function (_ref5) {
134
+ var _ref6 = guards_dist_xstateGuards._slicedToArray(_ref5, 2),
135
+ id = _ref6[0],
136
+ timeout = _ref6[1];
137
+
138
+ if (_this.now() - timeout.start >= timeout.timeout) {
139
+ _this.timeouts["delete"](id);
140
+
141
+ timeout.fn.call(null);
142
+ }
143
+ });
144
+ }
145
+ }, {
146
+ key: "increment",
147
+ value: function increment(ms) {
148
+ this._now += ms;
149
+ this.flushTimeouts();
150
+ }
151
+ }]);
152
+
153
+ return SimulatedClock;
154
+ }();
155
+
156
+ var actions = {
157
+ raise: guards_dist_xstateGuards.raise,
158
+ send: guards_dist_xstateGuards.send,
159
+ sendParent: guards_dist_xstateGuards.sendParent,
160
+ sendTo: guards_dist_xstateGuards.sendTo,
161
+ sendUpdate: guards_dist_xstateGuards.sendUpdate,
162
+ log: guards_dist_xstateGuards.log,
163
+ cancel: guards_dist_xstateGuards.cancel,
164
+ stop: guards_dist_xstateGuards.stop,
165
+ assign: guards_dist_xstateGuards.assign,
166
+ after: guards_dist_xstateGuards.after,
167
+ done: guards_dist_xstateGuards.done,
168
+ respond: guards_dist_xstateGuards.respond,
169
+ forwardTo: guards_dist_xstateGuards.forwardTo,
170
+ escalate: guards_dist_xstateGuards.escalate,
171
+ choose: guards_dist_xstateGuards.choose,
172
+ pure: pure
173
+ };
174
+
175
+ Object.defineProperty(exports, 'ActionTypes', {
176
+ enumerable: true,
177
+ get: function () {
178
+ return guards_dist_xstateGuards.ActionTypes;
179
+ }
180
+ });
181
+ exports.Interpreter = guards_dist_xstateGuards.Interpreter;
182
+ Object.defineProperty(exports, 'InterpreterStatus', {
183
+ enumerable: true,
184
+ get: function () {
185
+ return guards_dist_xstateGuards.InterpreterStatus;
186
+ }
187
+ });
188
+ exports.ObservableActorRef = guards_dist_xstateGuards.ObservableActorRef;
189
+ Object.defineProperty(exports, 'SpecialTargets', {
190
+ enumerable: true,
191
+ get: function () {
192
+ return guards_dist_xstateGuards.SpecialTargets;
193
+ }
194
+ });
195
+ exports.State = guards_dist_xstateGuards.State;
196
+ exports.assign = guards_dist_xstateGuards.assign;
197
+ exports.doneInvoke = guards_dist_xstateGuards.doneInvoke;
198
+ exports.forwardTo = guards_dist_xstateGuards.forwardTo;
199
+ exports.getStateNodes = guards_dist_xstateGuards.getStateNodes;
200
+ exports.interpret = guards_dist_xstateGuards.interpret;
201
+ exports.matchesState = guards_dist_xstateGuards.matchesState;
202
+ exports.pathToStateValue = guards_dist_xstateGuards.pathToStateValue;
203
+ exports.send = guards_dist_xstateGuards.send;
204
+ exports.sendParent = guards_dist_xstateGuards.sendParent;
205
+ exports.sendUpdate = guards_dist_xstateGuards.sendUpdate;
206
+ exports.toEventObject = guards_dist_xstateGuards.toEventObject;
207
+ exports.toObserver = guards_dist_xstateGuards.toObserver;
208
+ exports.toSCXMLEvent = guards_dist_xstateGuards.toSCXMLEvent;
209
+ exports.StateMachine = Machine.StateMachine;
210
+ exports.StateNode = Machine.StateNode;
211
+ exports.createMachine = Machine.createMachine;
212
+ exports.SimulatedClock = SimulatedClock;
213
+ exports.actions = actions;
214
+ exports.createSchema = createSchema;
215
+ exports.mapState = mapState;
216
+ exports.matchState = matchState;
217
+ exports.t = t;
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ if (process.env.NODE_ENV === "production") {
4
+ module.exports = require("./xstate.cjs.prod.js");
5
+ } else {
6
+ module.exports = require("./xstate.cjs.dev.js");
7
+ }
@@ -0,0 +1,217 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var guards_dist_xstateGuards = require('./actions-70094c93.cjs.prod.js');
6
+ require('../dev/dist/xstate-dev.cjs.prod.js');
7
+ var Machine = require('./Machine-dca041dc.cjs.prod.js');
8
+
9
+ function pure(getActions) {
10
+ return guards_dist_xstateGuards.createDynamicAction(guards_dist_xstateGuards.pure, {
11
+ get: getActions
12
+ }, function (_ref, ctx, _event) {
13
+ var _toArray;
14
+
15
+ var params = _ref.params;
16
+ return {
17
+ type: guards_dist_xstateGuards.pure,
18
+ params: {
19
+ actions: (_toArray = guards_dist_xstateGuards.toArray(params.get(ctx, _event.data))) !== null && _toArray !== void 0 ? _toArray : []
20
+ }
21
+ };
22
+ });
23
+ }
24
+
25
+ function mapState(stateMap, stateId) {
26
+ var foundStateId;
27
+
28
+ for (var _i = 0, _Object$keys = Object.keys(stateMap); _i < _Object$keys.length; _i++) {
29
+ var mappedStateId = _Object$keys[_i];
30
+
31
+ if (guards_dist_xstateGuards.matchesState(mappedStateId, stateId) && (!foundStateId || stateId.length > foundStateId.length)) {
32
+ foundStateId = mappedStateId;
33
+ }
34
+ }
35
+
36
+ return stateMap[foundStateId];
37
+ }
38
+
39
+ function matchState(state, patterns, defaultValue) {
40
+ var resolvedState = guards_dist_xstateGuards.State.from(state, state instanceof guards_dist_xstateGuards.State ? state.context : undefined);
41
+
42
+ var _iterator = guards_dist_xstateGuards._createForOfIteratorHelper(patterns),
43
+ _step;
44
+
45
+ try {
46
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
47
+ var _step$value = guards_dist_xstateGuards._slicedToArray(_step.value, 2),
48
+ stateValue = _step$value[0],
49
+ getValue = _step$value[1];
50
+
51
+ if (resolvedState.matches(stateValue)) {
52
+ return getValue(resolvedState);
53
+ }
54
+ }
55
+ } catch (err) {
56
+ _iterator.e(err);
57
+ } finally {
58
+ _iterator.f();
59
+ }
60
+
61
+ return defaultValue(resolvedState);
62
+ }
63
+
64
+ function createSchema(schema) {
65
+ return schema;
66
+ }
67
+ var t = createSchema;
68
+
69
+ var SimulatedClock = /*#__PURE__*/function () {
70
+ function SimulatedClock() {
71
+ guards_dist_xstateGuards._classCallCheck(this, SimulatedClock);
72
+
73
+ guards_dist_xstateGuards._defineProperty(this, "timeouts", new Map());
74
+
75
+ guards_dist_xstateGuards._defineProperty(this, "_now", 0);
76
+
77
+ guards_dist_xstateGuards._defineProperty(this, "_id", 0);
78
+ }
79
+
80
+ guards_dist_xstateGuards._createClass(SimulatedClock, [{
81
+ key: "now",
82
+ value: function now() {
83
+ return this._now;
84
+ }
85
+ }, {
86
+ key: "getId",
87
+ value: function getId() {
88
+ return this._id++;
89
+ }
90
+ }, {
91
+ key: "setTimeout",
92
+ value: function setTimeout(fn, timeout) {
93
+ var id = this.getId();
94
+ this.timeouts.set(id, {
95
+ start: this.now(),
96
+ timeout: timeout,
97
+ fn: fn
98
+ });
99
+ return id;
100
+ }
101
+ }, {
102
+ key: "clearTimeout",
103
+ value: function clearTimeout(id) {
104
+ this.timeouts["delete"](id);
105
+ }
106
+ }, {
107
+ key: "set",
108
+ value: function set(time) {
109
+ if (this._now > time) {
110
+ throw new Error('Unable to travel back in time');
111
+ }
112
+
113
+ this._now = time;
114
+ this.flushTimeouts();
115
+ }
116
+ }, {
117
+ key: "flushTimeouts",
118
+ value: function flushTimeouts() {
119
+ var _this = this;
120
+
121
+ guards_dist_xstateGuards._toConsumableArray(this.timeouts).sort(function (_ref, _ref2) {
122
+ var _ref3 = guards_dist_xstateGuards._slicedToArray(_ref, 2),
123
+ _idA = _ref3[0],
124
+ timeoutA = _ref3[1];
125
+
126
+ var _ref4 = guards_dist_xstateGuards._slicedToArray(_ref2, 2),
127
+ _idB = _ref4[0],
128
+ timeoutB = _ref4[1];
129
+
130
+ var endA = timeoutA.start + timeoutA.timeout;
131
+ var endB = timeoutB.start + timeoutB.timeout;
132
+ return endB > endA ? -1 : 1;
133
+ }).forEach(function (_ref5) {
134
+ var _ref6 = guards_dist_xstateGuards._slicedToArray(_ref5, 2),
135
+ id = _ref6[0],
136
+ timeout = _ref6[1];
137
+
138
+ if (_this.now() - timeout.start >= timeout.timeout) {
139
+ _this.timeouts["delete"](id);
140
+
141
+ timeout.fn.call(null);
142
+ }
143
+ });
144
+ }
145
+ }, {
146
+ key: "increment",
147
+ value: function increment(ms) {
148
+ this._now += ms;
149
+ this.flushTimeouts();
150
+ }
151
+ }]);
152
+
153
+ return SimulatedClock;
154
+ }();
155
+
156
+ var actions = {
157
+ raise: guards_dist_xstateGuards.raise,
158
+ send: guards_dist_xstateGuards.send,
159
+ sendParent: guards_dist_xstateGuards.sendParent,
160
+ sendTo: guards_dist_xstateGuards.sendTo,
161
+ sendUpdate: guards_dist_xstateGuards.sendUpdate,
162
+ log: guards_dist_xstateGuards.log,
163
+ cancel: guards_dist_xstateGuards.cancel,
164
+ stop: guards_dist_xstateGuards.stop,
165
+ assign: guards_dist_xstateGuards.assign,
166
+ after: guards_dist_xstateGuards.after,
167
+ done: guards_dist_xstateGuards.done,
168
+ respond: guards_dist_xstateGuards.respond,
169
+ forwardTo: guards_dist_xstateGuards.forwardTo,
170
+ escalate: guards_dist_xstateGuards.escalate,
171
+ choose: guards_dist_xstateGuards.choose,
172
+ pure: pure
173
+ };
174
+
175
+ Object.defineProperty(exports, 'ActionTypes', {
176
+ enumerable: true,
177
+ get: function () {
178
+ return guards_dist_xstateGuards.ActionTypes;
179
+ }
180
+ });
181
+ exports.Interpreter = guards_dist_xstateGuards.Interpreter;
182
+ Object.defineProperty(exports, 'InterpreterStatus', {
183
+ enumerable: true,
184
+ get: function () {
185
+ return guards_dist_xstateGuards.InterpreterStatus;
186
+ }
187
+ });
188
+ exports.ObservableActorRef = guards_dist_xstateGuards.ObservableActorRef;
189
+ Object.defineProperty(exports, 'SpecialTargets', {
190
+ enumerable: true,
191
+ get: function () {
192
+ return guards_dist_xstateGuards.SpecialTargets;
193
+ }
194
+ });
195
+ exports.State = guards_dist_xstateGuards.State;
196
+ exports.assign = guards_dist_xstateGuards.assign;
197
+ exports.doneInvoke = guards_dist_xstateGuards.doneInvoke;
198
+ exports.forwardTo = guards_dist_xstateGuards.forwardTo;
199
+ exports.getStateNodes = guards_dist_xstateGuards.getStateNodes;
200
+ exports.interpret = guards_dist_xstateGuards.interpret;
201
+ exports.matchesState = guards_dist_xstateGuards.matchesState;
202
+ exports.pathToStateValue = guards_dist_xstateGuards.pathToStateValue;
203
+ exports.send = guards_dist_xstateGuards.send;
204
+ exports.sendParent = guards_dist_xstateGuards.sendParent;
205
+ exports.sendUpdate = guards_dist_xstateGuards.sendUpdate;
206
+ exports.toEventObject = guards_dist_xstateGuards.toEventObject;
207
+ exports.toObserver = guards_dist_xstateGuards.toObserver;
208
+ exports.toSCXMLEvent = guards_dist_xstateGuards.toSCXMLEvent;
209
+ exports.StateMachine = Machine.StateMachine;
210
+ exports.StateNode = Machine.StateNode;
211
+ exports.createMachine = Machine.createMachine;
212
+ exports.SimulatedClock = SimulatedClock;
213
+ exports.actions = actions;
214
+ exports.createSchema = createSchema;
215
+ exports.mapState = mapState;
216
+ exports.matchState = matchState;
217
+ exports.t = t;