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/lib/invoke.d.ts DELETED
@@ -1,11 +0,0 @@
1
- export interface InvokedPromiseOptions {
2
- id?: string;
3
- }
4
- export interface PromiseMachineSchema {
5
- states: {
6
- pending: {};
7
- resolved: {};
8
- rejected: {};
9
- };
10
- }
11
- //# sourceMappingURL=invoke.d.ts.map
package/lib/invoke.js DELETED
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- // export function fromPromise<T>(
4
- // promise: Promise<T>,
5
- // options?: InvokedPromiseOptions
6
- // ): any {
7
- // const optionsWithDefaults = {
8
- // id: 'promise',
9
- // ...options
10
- // };
11
- // return Machine<T, PromiseMachineSchema>({
12
- // id: optionsWithDefaults.id,
13
- // initial: 'pending',
14
- // states: {
15
- // pending: {},
16
- // resolved: {},
17
- // rejected: {}
18
- // }
19
- // });
20
- // }
@@ -1,7 +0,0 @@
1
- import { EventObject, InvokeConfig, InvokeDefinition, InvokeSourceDefinition } from './types';
2
- export declare function toInvokeSource(src: string | InvokeSourceDefinition): InvokeSourceDefinition;
3
- export declare function toInvokeDefinition<TContext, TEvent extends EventObject>(invokeConfig: InvokeConfig<TContext, TEvent> & {
4
- src: string | InvokeSourceDefinition;
5
- id: string;
6
- }): InvokeDefinition<TContext, TEvent>;
7
- //# sourceMappingURL=invokeUtils.d.ts.map
@@ -1,45 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var _tslib = require('./_virtual/_tslib.js');
6
- require('./types.js');
7
- var actionTypes = require('./actionTypes.js');
8
- require('./utils.js');
9
- require('./environment.js');
10
-
11
- function toInvokeSource(src) {
12
- if (typeof src === 'string') {
13
- var simpleSrc = {
14
- type: src
15
- };
16
-
17
- simpleSrc.toString = function () {
18
- return src;
19
- }; // v4 compat - TODO: remove in v5
20
-
21
-
22
- return simpleSrc;
23
- }
24
-
25
- return src;
26
- }
27
- function toInvokeDefinition(invokeConfig) {
28
- return _tslib.__assign(_tslib.__assign({
29
- type: actionTypes.invoke
30
- }, invokeConfig), {
31
- toJSON: function () {
32
- invokeConfig.onDone;
33
- invokeConfig.onError;
34
- var invokeDef = _tslib.__rest(invokeConfig, ["onDone", "onError"]);
35
-
36
- return _tslib.__assign(_tslib.__assign({}, invokeDef), {
37
- type: actionTypes.invoke,
38
- src: toInvokeSource(invokeConfig.src)
39
- });
40
- }
41
- });
42
- }
43
-
44
- exports.toInvokeDefinition = toInvokeDefinition;
45
- exports.toInvokeSource = toInvokeSource;
package/lib/json.d.ts DELETED
@@ -1,31 +0,0 @@
1
- import { StateNode, ActionObject, Guard, InvokeDefinition } from './';
2
- interface JSONFunction {
3
- $function: string;
4
- }
5
- export declare function stringifyFunction(fn: Function): JSONFunction;
6
- interface TransitionConfig {
7
- target: string[];
8
- source: string;
9
- actions: Array<ActionObject<any, any>>;
10
- cond: Guard<any, any> | undefined;
11
- eventType: string;
12
- }
13
- interface StateNodeConfig {
14
- type: StateNode['type'];
15
- id: string;
16
- key: string;
17
- initial?: string;
18
- entry: Array<ActionObject<any, any>>;
19
- exit: Array<ActionObject<any, any>>;
20
- on: {
21
- [key: string]: TransitionConfig[];
22
- };
23
- invoke: Array<InvokeDefinition<any, any>>;
24
- states: Record<string, StateNodeConfig>;
25
- }
26
- export declare function machineToJSON(stateNode: StateNode): StateNodeConfig;
27
- export declare function stringify(machine: StateNode): string;
28
- export declare function parse(machineString: string): StateNodeConfig;
29
- export declare function jsonify<T extends Record<string, any>>(value: T): T;
30
- export {};
31
- //# sourceMappingURL=json.d.ts.map
package/lib/json.js DELETED
@@ -1,94 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var utils = require('./utils.js');
6
-
7
- function stringifyFunction(fn) {
8
- return {
9
- $function: fn.toString()
10
- };
11
- }
12
-
13
- function getStateNodeId(stateNode) {
14
- return "#".concat(stateNode.id);
15
- } // derive config from machine
16
-
17
-
18
- function machineToJSON(stateNode) {
19
- var config = {
20
- type: stateNode.type,
21
- initial: stateNode.initial === undefined ? undefined : String(stateNode.initial),
22
- id: stateNode.id,
23
- key: stateNode.key,
24
- entry: stateNode.onEntry,
25
- exit: stateNode.onExit,
26
- on: utils.mapValues(stateNode.on, function (transition) {
27
- return transition.map(function (t) {
28
- return {
29
- target: t.target ? t.target.map(getStateNodeId) : [],
30
- source: getStateNodeId(t.source),
31
- actions: t.actions,
32
- cond: t.cond,
33
- eventType: t.eventType
34
- };
35
- });
36
- }),
37
- invoke: stateNode.invoke,
38
- states: {}
39
- };
40
- Object.values(stateNode.states).forEach(function (sn) {
41
- config.states[sn.key] = machineToJSON(sn);
42
- });
43
- return config;
44
- }
45
- function stringify(machine) {
46
- return JSON.stringify(machineToJSON(machine), function (_, value) {
47
- if (utils.isFunction(value)) {
48
- return {
49
- $function: value.toString()
50
- };
51
- }
52
-
53
- return value;
54
- });
55
- }
56
- function parse(machineString) {
57
- var config = JSON.parse(machineString, function (_, value) {
58
- if (typeof value === 'object' && '$function' in value) {
59
- return new Function(value.value);
60
- }
61
-
62
- return value;
63
- });
64
- return config;
65
- }
66
- function jsonify(value) {
67
- Object.defineProperty(value, 'toJSON', {
68
- value: function () {
69
- return utils.mapValues(value, function (subValue) {
70
- if (utils.isFunction(subValue)) {
71
- return stringifyFunction(subValue);
72
- } else if (typeof subValue === 'object' && !Array.isArray(subValue)) {
73
- // mostly for assignments
74
- return utils.mapValues(subValue, function (subSubValue) {
75
- if (utils.isFunction(subSubValue)) {
76
- return stringifyFunction(subSubValue);
77
- }
78
-
79
- return subSubValue;
80
- });
81
- }
82
-
83
- return subValue;
84
- });
85
- }
86
- });
87
- return value;
88
- }
89
-
90
- exports.jsonify = jsonify;
91
- exports.machineToJSON = machineToJSON;
92
- exports.parse = parse;
93
- exports.stringify = stringify;
94
- exports.stringifyFunction = stringifyFunction;
package/lib/mapState.d.ts DELETED
@@ -1,4 +0,0 @@
1
- export declare function mapState(stateMap: {
2
- [stateId: string]: any;
3
- }, stateId: string): any;
4
- //# sourceMappingURL=mapState.d.ts.map
package/lib/mapState.js DELETED
@@ -1,36 +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
-
8
- function mapState(stateMap, stateId) {
9
- var e_1, _a;
10
-
11
- var foundStateId;
12
-
13
- try {
14
- for (var _b = _tslib.__values(Object.keys(stateMap)), _c = _b.next(); !_c.done; _c = _b.next()) {
15
- var mappedStateId = _c.value;
16
-
17
- if (utils.matchesState(mappedStateId, stateId) && (!foundStateId || stateId.length > foundStateId.length)) {
18
- foundStateId = mappedStateId;
19
- }
20
- }
21
- } catch (e_1_1) {
22
- e_1 = {
23
- error: e_1_1
24
- };
25
- } finally {
26
- try {
27
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
28
- } finally {
29
- if (e_1) throw e_1.error;
30
- }
31
- }
32
-
33
- return stateMap[foundStateId];
34
- }
35
-
36
- exports.mapState = mapState;
package/lib/match.d.ts DELETED
@@ -1,9 +0,0 @@
1
- import { State } from './State';
2
- import { StateValue, EventObject } from './types';
3
- export declare type ValueFromStateGetter<T, TContext, TEvent extends EventObject> = (state: State<TContext, TEvent>) => T;
4
- export declare type StatePatternTuple<T, TContext, TEvent extends EventObject> = [
5
- StateValue,
6
- ValueFromStateGetter<T, TContext, TEvent>
7
- ];
8
- export declare function matchState<T, TContext, TEvent extends EventObject>(state: State<TContext, TEvent> | StateValue, patterns: Array<StatePatternTuple<T, TContext, TEvent>>, defaultValue: ValueFromStateGetter<T, TContext, TEvent>): T;
9
- //# sourceMappingURL=match.d.ts.map
package/lib/match.js DELETED
@@ -1,38 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var _tslib = require('./_virtual/_tslib.js');
6
- var State = require('./State.js');
7
-
8
- function matchState(state, patterns, defaultValue) {
9
- var e_1, _a;
10
-
11
- var resolvedState = State.State.from(state, state instanceof State.State ? state.context : undefined);
12
-
13
- try {
14
- for (var patterns_1 = _tslib.__values(patterns), patterns_1_1 = patterns_1.next(); !patterns_1_1.done; patterns_1_1 = patterns_1.next()) {
15
- var _b = _tslib.__read(patterns_1_1.value, 2),
16
- stateValue = _b[0],
17
- getValue = _b[1];
18
-
19
- if (resolvedState.matches(stateValue)) {
20
- return getValue(resolvedState);
21
- }
22
- }
23
- } catch (e_1_1) {
24
- e_1 = {
25
- error: e_1_1
26
- };
27
- } finally {
28
- try {
29
- if (patterns_1_1 && !patterns_1_1.done && (_a = patterns_1.return)) _a.call(patterns_1);
30
- } finally {
31
- if (e_1) throw e_1.error;
32
- }
33
- }
34
-
35
- return defaultValue(resolvedState);
36
- }
37
-
38
- exports.matchState = matchState;
package/lib/model.d.ts DELETED
@@ -1,5 +0,0 @@
1
- import type { Cast, EventObject, BaseActionObject, Prop, IsNever } from './types';
2
- import { UnionFromCreatorsReturnTypes, FinalModelCreators, Model, ModelCreators } from './model.types';
3
- export declare function createModel<TContext, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject>(initialContext: TContext): Model<TContext, TEvent, TAction, void>;
4
- export declare function createModel<TContext, TModelCreators extends ModelCreators<TModelCreators>, TFinalModelCreators = FinalModelCreators<TModelCreators>, TComputedEvent = UnionFromCreatorsReturnTypes<Prop<TFinalModelCreators, 'events'>>, TComputedAction = UnionFromCreatorsReturnTypes<Prop<TFinalModelCreators, 'actions'>>>(initialContext: TContext, creators: TModelCreators): Model<TContext, Cast<TComputedEvent, EventObject>, IsNever<TComputedAction> extends true ? BaseActionObject : Cast<TComputedAction, BaseActionObject>, TFinalModelCreators>;
5
- //# sourceMappingURL=model.d.ts.map
package/lib/model.js DELETED
@@ -1,54 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var _tslib = require('./_virtual/_tslib.js');
6
- var actions = require('./actions.js');
7
- var Machine = require('./Machine.js');
8
- var utils = require('./utils.js');
9
-
10
- function createModel(initialContext, creators) {
11
- var eventCreators = creators === null || creators === void 0 ? void 0 : creators.events;
12
- var actionCreators = creators === null || creators === void 0 ? void 0 : creators.actions;
13
- var model = {
14
- initialContext: initialContext,
15
- assign: actions.assign,
16
- events: eventCreators ? utils.mapValues(eventCreators, function (fn, eventType) {
17
- return function () {
18
- var args = [];
19
-
20
- for (var _i = 0; _i < arguments.length; _i++) {
21
- args[_i] = arguments[_i];
22
- }
23
-
24
- return _tslib.__assign(_tslib.__assign({}, fn.apply(void 0, _tslib.__spreadArray([], _tslib.__read(args), false))), {
25
- type: eventType
26
- });
27
- };
28
- }) : undefined,
29
- actions: actionCreators ? utils.mapValues(actionCreators, function (fn, actionType) {
30
- return function () {
31
- var args = [];
32
-
33
- for (var _i = 0; _i < arguments.length; _i++) {
34
- args[_i] = arguments[_i];
35
- }
36
-
37
- return _tslib.__assign(_tslib.__assign({}, fn.apply(void 0, _tslib.__spreadArray([], _tslib.__read(args), false))), {
38
- type: actionType
39
- });
40
- };
41
- }) : undefined,
42
- reset: function () {
43
- return actions.assign(initialContext);
44
- },
45
- createMachine: function (config, implementations) {
46
- return Machine.createMachine('context' in config ? config : _tslib.__assign(_tslib.__assign({}, config), {
47
- context: initialContext
48
- }), implementations);
49
- }
50
- };
51
- return model;
52
- }
53
-
54
- exports.createModel = createModel;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
package/lib/patterns.d.ts DELETED
@@ -1,14 +0,0 @@
1
- import { AtomicStateNodeConfig, StatesConfig, Event, EventObject, StateSchema } from './types';
2
- export declare function toggle<TEventType extends string = string>(onState: string, offState: string, eventType: TEventType): Record<string, AtomicStateNodeConfig<any, {
3
- type: TEventType;
4
- }>>;
5
- interface SequencePatternOptions<TEvent extends EventObject> {
6
- nextEvent: Event<TEvent> | undefined;
7
- prevEvent: Event<TEvent> | undefined;
8
- }
9
- export declare function sequence<TStateSchema extends StateSchema, TEvent extends EventObject>(items: Array<keyof TStateSchema['states']>, options?: Partial<SequencePatternOptions<TEvent>>): {
10
- initial: keyof TStateSchema['states'];
11
- states: StatesConfig<any, TStateSchema, TEvent>;
12
- };
13
- export {};
14
- //# sourceMappingURL=patterns.d.ts.map
package/lib/patterns.js DELETED
@@ -1,53 +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
-
8
- function toggle(onState, offState, eventType) {
9
- var _a, _b, _c;
10
-
11
- return _a = {}, _a[onState] = {
12
- on: (_b = {}, _b[eventType] = offState, _b)
13
- }, _a[offState] = {
14
- on: (_c = {}, _c[eventType] = onState, _c)
15
- }, _a;
16
- }
17
- var defaultSequencePatternOptions = {
18
- nextEvent: 'NEXT',
19
- prevEvent: 'PREV'
20
- };
21
- function sequence(items, options) {
22
- var resolvedOptions = _tslib.__assign(_tslib.__assign({}, defaultSequencePatternOptions), options);
23
-
24
- var states = {};
25
- var nextEventObject = resolvedOptions.nextEvent === undefined ? undefined : utils.toEventObject(resolvedOptions.nextEvent);
26
- var prevEventObject = resolvedOptions.prevEvent === undefined ? undefined : utils.toEventObject(resolvedOptions.prevEvent);
27
- items.forEach(function (item, i) {
28
- var state = {
29
- on: {}
30
- };
31
-
32
- if (i + 1 === items.length) {
33
- state.type = 'final';
34
- }
35
-
36
- if (nextEventObject && i + 1 < items.length) {
37
- state.on[nextEventObject.type] = items[i + 1];
38
- }
39
-
40
- if (prevEventObject && i > 0) {
41
- state.on[prevEventObject.type] = items[i - 1];
42
- }
43
-
44
- states[item] = state;
45
- });
46
- return {
47
- initial: items[0],
48
- states: states
49
- };
50
- }
51
-
52
- exports.sequence = sequence;
53
- exports.toggle = toggle;
package/lib/registry.d.ts DELETED
@@ -1,9 +0,0 @@
1
- import { Actor } from './Actor';
2
- export interface Registry {
3
- bookId(): string;
4
- register(id: string, actor: Actor): string;
5
- get(id: string): Actor | undefined;
6
- free(id: string): void;
7
- }
8
- export declare const registry: Registry;
9
- //# sourceMappingURL=registry.d.ts.map
package/lib/registry.js DELETED
@@ -1,23 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var children = /*#__PURE__*/new Map();
6
- var sessionIdIndex = 0;
7
- var registry = {
8
- bookId: function () {
9
- return "x:".concat(sessionIdIndex++);
10
- },
11
- register: function (id, actor) {
12
- children.set(id, actor);
13
- return id;
14
- },
15
- get: function (id) {
16
- return children.get(id);
17
- },
18
- free: function (id) {
19
- children.delete(id);
20
- }
21
- };
22
-
23
- exports.registry = registry;
@@ -1,17 +0,0 @@
1
- interface SchedulerOptions {
2
- deferEvents: boolean;
3
- }
4
- export declare class Scheduler {
5
- private processingEvent;
6
- private queue;
7
- private initialized;
8
- private options;
9
- constructor(options?: Partial<SchedulerOptions>);
10
- initialize(callback?: () => void): void;
11
- schedule(task: () => void): void;
12
- clear(): void;
13
- private flushEvents;
14
- private process;
15
- }
16
- export {};
17
- //# sourceMappingURL=scheduler.d.ts.map
package/lib/scheduler.js DELETED
@@ -1,83 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var _tslib = require('./_virtual/_tslib.js');
6
-
7
- var defaultOptions = {
8
- deferEvents: false
9
- };
10
-
11
- var Scheduler =
12
- /*#__PURE__*/
13
-
14
- /** @class */
15
- function () {
16
- function Scheduler(options) {
17
- this.processingEvent = false;
18
- this.queue = [];
19
- this.initialized = false;
20
- this.options = _tslib.__assign(_tslib.__assign({}, defaultOptions), options);
21
- }
22
-
23
- Scheduler.prototype.initialize = function (callback) {
24
- this.initialized = true;
25
-
26
- if (callback) {
27
- if (!this.options.deferEvents) {
28
- this.schedule(callback);
29
- return;
30
- }
31
-
32
- this.process(callback);
33
- }
34
-
35
- this.flushEvents();
36
- };
37
-
38
- Scheduler.prototype.schedule = function (task) {
39
- if (!this.initialized || this.processingEvent) {
40
- this.queue.push(task);
41
- return;
42
- }
43
-
44
- if (this.queue.length !== 0) {
45
- throw new Error('Event queue should be empty when it is not processing events');
46
- }
47
-
48
- this.process(task);
49
- this.flushEvents();
50
- };
51
-
52
- Scheduler.prototype.clear = function () {
53
- this.queue = [];
54
- };
55
-
56
- Scheduler.prototype.flushEvents = function () {
57
- var nextCallback = this.queue.shift();
58
-
59
- while (nextCallback) {
60
- this.process(nextCallback);
61
- nextCallback = this.queue.shift();
62
- }
63
- };
64
-
65
- Scheduler.prototype.process = function (callback) {
66
- this.processingEvent = true;
67
-
68
- try {
69
- callback();
70
- } catch (e) {
71
- // there is no use to keep the future events
72
- // as the situation is not anymore the same
73
- this.clear();
74
- throw e;
75
- } finally {
76
- this.processingEvent = false;
77
- }
78
- };
79
-
80
- return Scheduler;
81
- }();
82
-
83
- exports.Scheduler = Scheduler;
package/lib/schema.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export declare function createSchema<T>(schema?: any): T;
2
- export declare const t: typeof createSchema;
3
- //# sourceMappingURL=schema.d.ts.map
package/lib/schema.js DELETED
@@ -1,11 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- function createSchema(schema) {
6
- return schema;
7
- }
8
- var t = createSchema;
9
-
10
- exports.createSchema = createSchema;
11
- exports.t = t;
package/lib/scxml.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import { AnyStateMachine } from './index';
2
- export interface ScxmlToMachineOptions {
3
- delimiter?: string;
4
- }
5
- export declare function toMachine(xml: string, options: ScxmlToMachineOptions): AnyStateMachine;
6
- //# sourceMappingURL=scxml.d.ts.map