xstate 4.35.2 → 5.0.0-alpha.1

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 (203) hide show
  1. package/README.md +25 -16
  2. package/actions/dist/xstate-actions.cjs.d.ts +1 -0
  3. package/actions/dist/xstate-actions.cjs.dev.js +30 -0
  4. package/actions/dist/xstate-actions.cjs.js +7 -0
  5. package/actions/dist/xstate-actions.cjs.prod.js +30 -0
  6. package/actions/dist/xstate-actions.esm.js +2 -0
  7. package/actions/dist/xstate-actions.umd.min.js +2 -0
  8. package/actions/dist/xstate-actions.umd.min.js.map +1 -0
  9. package/actions/dynamicAction.ts +34 -0
  10. package/actions/package.json +8 -0
  11. package/actors/dist/xstate-actors.cjs.d.ts +1 -0
  12. package/actors/dist/xstate-actors.cjs.dev.js +20 -0
  13. package/actors/dist/xstate-actors.cjs.js +7 -0
  14. package/actors/dist/xstate-actors.cjs.prod.js +20 -0
  15. package/actors/dist/xstate-actors.esm.js +2 -0
  16. package/actors/dist/xstate-actors.umd.min.js +2 -0
  17. package/actors/dist/xstate-actors.umd.min.js.map +1 -0
  18. package/actors/package.json +8 -0
  19. package/dev/dist/xstate-dev.cjs.d.ts +1 -0
  20. package/dev/dist/xstate-dev.cjs.dev.js +11 -0
  21. package/dev/dist/xstate-dev.cjs.js +7 -0
  22. package/{lib/devTools.js → dev/dist/xstate-dev.cjs.prod.js} +17 -10
  23. package/dev/dist/xstate-dev.esm.js +1 -0
  24. package/dev/dist/xstate-dev.umd.min.js +2 -0
  25. package/dev/dist/xstate-dev.umd.min.js.map +1 -0
  26. package/dev/package.json +8 -0
  27. package/dist/actions-7ea9280f.cjs.prod.js +4674 -0
  28. package/dist/actions-b08d0da8.cjs.dev.js +4718 -0
  29. package/dist/actions-b673cb13.esm.js +4660 -0
  30. package/dist/declarations/actions/dynamicAction.d.ts +5 -0
  31. package/dist/declarations/src/Machine.d.ts +4 -0
  32. package/dist/declarations/src/Mailbox.d.ts +12 -0
  33. package/{es → dist/declarations/src}/SimulatedClock.d.ts +16 -17
  34. package/dist/declarations/src/State.d.ts +97 -0
  35. package/dist/declarations/src/StateMachine.d.ts +120 -0
  36. package/dist/declarations/src/StateNode.d.ts +127 -0
  37. package/{es → dist/declarations/src}/actionTypes.d.ts +16 -20
  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 +51 -0
  46. package/dist/declarations/src/actions/stop.d.ts +7 -0
  47. package/dist/declarations/src/actions.d.ts +43 -0
  48. package/dist/declarations/src/actors.d.ts +37 -0
  49. package/dist/declarations/src/constants.d.ts +5 -0
  50. package/{lib/devTools.d.ts → dist/declarations/src/dev/index.d.ts} +14 -14
  51. package/{es → dist/declarations/src}/environment.d.ts +1 -2
  52. package/dist/declarations/src/guards.d.ts +8 -0
  53. package/dist/declarations/src/index.d.ts +44 -0
  54. package/dist/declarations/src/interpreter.d.ts +108 -0
  55. package/{es → dist/declarations/src}/mapState.d.ts +3 -4
  56. package/dist/declarations/src/memo.d.ts +2 -0
  57. package/dist/declarations/src/registry.d.ts +8 -0
  58. package/{es → dist/declarations/src}/schema.d.ts +2 -3
  59. package/dist/declarations/src/spawn.d.ts +2 -0
  60. package/dist/declarations/src/stateUtils.d.ts +70 -0
  61. package/dist/declarations/src/symbolObservable.d.ts +1 -0
  62. package/{lib → dist/declarations/src}/typegenTypes.d.ts +132 -133
  63. package/dist/declarations/src/types.d.ts +1001 -0
  64. package/dist/declarations/src/utils.d.ts +54 -0
  65. package/{es/devTools.js → dist/index-20b364c4.esm.js} +18 -6
  66. package/dist/index-2a564d03.cjs.dev.js +64 -0
  67. package/dist/xstate.cjs.d.ts +1 -0
  68. package/dist/xstate.cjs.dev.js +993 -0
  69. package/dist/xstate.cjs.js +7 -0
  70. package/dist/xstate.cjs.prod.js +993 -0
  71. package/dist/xstate.esm.js +952 -0
  72. package/dist/xstate.umd.min.js +2 -0
  73. package/dist/xstate.umd.min.js.map +1 -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/dist/xstate-guards.umd.min.js +2 -0
  80. package/guards/dist/xstate-guards.umd.min.js.map +1 -0
  81. package/guards/package.json +8 -0
  82. package/invoke/package.json +4 -0
  83. package/package.json +44 -30
  84. package/dist/xstate.interpreter.js +0 -15
  85. package/dist/xstate.js +0 -15
  86. package/dist/xstate.web.js +0 -15
  87. package/es/Actor.d.ts +0 -25
  88. package/es/Actor.js +0 -99
  89. package/es/Machine.d.ts +0 -12
  90. package/es/Machine.js +0 -21
  91. package/es/SimulatedClock.js +0 -81
  92. package/es/State.d.ts +0 -123
  93. package/es/State.js +0 -274
  94. package/es/StateNode.d.ts +0 -282
  95. package/es/StateNode.js +0 -1587
  96. package/es/_virtual/_tslib.js +0 -78
  97. package/es/actionTypes.js +0 -22
  98. package/es/actions.d.ts +0 -157
  99. package/es/actions.js +0 -630
  100. package/es/behaviors.d.ts +0 -37
  101. package/es/behaviors.js +0 -131
  102. package/es/constants.d.ts +0 -6
  103. package/es/constants.js +0 -6
  104. package/es/devTools.d.ts +0 -14
  105. package/es/each.d.ts +0 -4
  106. package/es/each.js +0 -13
  107. package/es/environment.js +0 -3
  108. package/es/index.d.ts +0 -22
  109. package/es/index.js +0 -25
  110. package/es/interpreter.d.ts +0 -217
  111. package/es/interpreter.js +0 -1488
  112. package/es/invoke.d.ts +0 -11
  113. package/es/invokeUtils.d.ts +0 -7
  114. package/es/invokeUtils.js +0 -40
  115. package/es/json.d.ts +0 -31
  116. package/es/json.js +0 -86
  117. package/es/mapState.js +0 -32
  118. package/es/match.d.ts +0 -9
  119. package/es/match.js +0 -34
  120. package/es/model.d.ts +0 -8
  121. package/es/model.js +0 -50
  122. package/es/model.types.d.ts +0 -56
  123. package/es/patterns.d.ts +0 -14
  124. package/es/patterns.js +0 -48
  125. package/es/registry.d.ts +0 -9
  126. package/es/registry.js +0 -19
  127. package/es/scheduler.d.ts +0 -17
  128. package/es/scheduler.js +0 -79
  129. package/es/schema.js +0 -6
  130. package/es/scxml.d.ts +0 -6
  131. package/es/serviceScope.d.ts +0 -4
  132. package/es/serviceScope.js +0 -16
  133. package/es/stateUtils.d.ts +0 -18
  134. package/es/stateUtils.js +0 -262
  135. package/es/typegenTypes.d.ts +0 -133
  136. package/es/types.d.ts +0 -1040
  137. package/es/types.js +0 -33
  138. package/es/utils.d.ts +0 -72
  139. package/es/utils.js +0 -622
  140. package/es/waitFor.d.ts +0 -34
  141. package/es/waitFor.js +0 -73
  142. package/lib/Actor.d.ts +0 -25
  143. package/lib/Actor.js +0 -108
  144. package/lib/Machine.d.ts +0 -12
  145. package/lib/Machine.js +0 -26
  146. package/lib/SimulatedClock.d.ts +0 -17
  147. package/lib/SimulatedClock.js +0 -85
  148. package/lib/State.d.ts +0 -123
  149. package/lib/State.js +0 -282
  150. package/lib/StateNode.d.ts +0 -282
  151. package/lib/StateNode.js +0 -1591
  152. package/lib/_virtual/_tslib.js +0 -85
  153. package/lib/actionTypes.d.ts +0 -20
  154. package/lib/actionTypes.js +0 -43
  155. package/lib/actions.d.ts +0 -157
  156. package/lib/actions.js +0 -662
  157. package/lib/behaviors.d.ts +0 -37
  158. package/lib/behaviors.js +0 -137
  159. package/lib/constants.d.ts +0 -6
  160. package/lib/constants.js +0 -13
  161. package/lib/each.d.ts +0 -4
  162. package/lib/each.js +0 -17
  163. package/lib/environment.d.ts +0 -2
  164. package/lib/environment.js +0 -7
  165. package/lib/index.d.ts +0 -22
  166. package/lib/index.js +0 -64
  167. package/lib/interpreter.d.ts +0 -217
  168. package/lib/interpreter.js +0 -1494
  169. package/lib/invoke.d.ts +0 -11
  170. package/lib/invoke.js +0 -20
  171. package/lib/invokeUtils.d.ts +0 -7
  172. package/lib/invokeUtils.js +0 -45
  173. package/lib/json.d.ts +0 -31
  174. package/lib/json.js +0 -94
  175. package/lib/mapState.d.ts +0 -4
  176. package/lib/mapState.js +0 -36
  177. package/lib/match.d.ts +0 -9
  178. package/lib/match.js +0 -38
  179. package/lib/model.d.ts +0 -8
  180. package/lib/model.js +0 -54
  181. package/lib/model.types.d.ts +0 -56
  182. package/lib/model.types.js +0 -2
  183. package/lib/patterns.d.ts +0 -14
  184. package/lib/patterns.js +0 -53
  185. package/lib/registry.d.ts +0 -9
  186. package/lib/registry.js +0 -23
  187. package/lib/scheduler.d.ts +0 -17
  188. package/lib/scheduler.js +0 -83
  189. package/lib/schema.d.ts +0 -3
  190. package/lib/schema.js +0 -11
  191. package/lib/scxml.d.ts +0 -6
  192. package/lib/scxml.js +0 -350
  193. package/lib/serviceScope.d.ts +0 -4
  194. package/lib/serviceScope.js +0 -21
  195. package/lib/stateUtils.d.ts +0 -18
  196. package/lib/stateUtils.js +0 -277
  197. package/lib/typegenTypes.js +0 -2
  198. package/lib/types.d.ts +0 -1040
  199. package/lib/types.js +0 -35
  200. package/lib/utils.d.ts +0 -72
  201. package/lib/utils.js +0 -669
  202. package/lib/waitFor.d.ts +0 -34
  203. package/lib/waitFor.js +0 -77
package/es/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
@@ -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
package/es/invokeUtils.js DELETED
@@ -1,40 +0,0 @@
1
- import { __assign, __rest } from './_virtual/_tslib.js';
2
- import './types.js';
3
- import { invoke } from './actionTypes.js';
4
- import './utils.js';
5
- import './environment.js';
6
-
7
- function toInvokeSource(src) {
8
- if (typeof src === 'string') {
9
- var simpleSrc = {
10
- type: src
11
- };
12
-
13
- simpleSrc.toString = function () {
14
- return src;
15
- }; // v4 compat - TODO: remove in v5
16
-
17
-
18
- return simpleSrc;
19
- }
20
-
21
- return src;
22
- }
23
- function toInvokeDefinition(invokeConfig) {
24
- return __assign(__assign({
25
- type: invoke
26
- }, invokeConfig), {
27
- toJSON: function () {
28
- invokeConfig.onDone;
29
- invokeConfig.onError;
30
- var invokeDef = __rest(invokeConfig, ["onDone", "onError"]);
31
-
32
- return __assign(__assign({}, invokeDef), {
33
- type: invoke,
34
- src: toInvokeSource(invokeConfig.src)
35
- });
36
- }
37
- });
38
- }
39
-
40
- export { toInvokeDefinition, toInvokeSource };
package/es/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/es/json.js DELETED
@@ -1,86 +0,0 @@
1
- import { mapValues, isFunction } from './utils.js';
2
-
3
- function stringifyFunction(fn) {
4
- return {
5
- $function: fn.toString()
6
- };
7
- }
8
-
9
- function getStateNodeId(stateNode) {
10
- return "#".concat(stateNode.id);
11
- } // derive config from machine
12
-
13
-
14
- function machineToJSON(stateNode) {
15
- var config = {
16
- type: stateNode.type,
17
- initial: stateNode.initial === undefined ? undefined : String(stateNode.initial),
18
- id: stateNode.id,
19
- key: stateNode.key,
20
- entry: stateNode.onEntry,
21
- exit: stateNode.onExit,
22
- on: mapValues(stateNode.on, function (transition) {
23
- return transition.map(function (t) {
24
- return {
25
- target: t.target ? t.target.map(getStateNodeId) : [],
26
- source: getStateNodeId(t.source),
27
- actions: t.actions,
28
- cond: t.cond,
29
- eventType: t.eventType
30
- };
31
- });
32
- }),
33
- invoke: stateNode.invoke,
34
- states: {}
35
- };
36
- Object.values(stateNode.states).forEach(function (sn) {
37
- config.states[sn.key] = machineToJSON(sn);
38
- });
39
- return config;
40
- }
41
- function stringify(machine) {
42
- return JSON.stringify(machineToJSON(machine), function (_, value) {
43
- if (isFunction(value)) {
44
- return {
45
- $function: value.toString()
46
- };
47
- }
48
-
49
- return value;
50
- });
51
- }
52
- function parse(machineString) {
53
- var config = JSON.parse(machineString, function (_, value) {
54
- if (typeof value === 'object' && '$function' in value) {
55
- return new Function(value.value);
56
- }
57
-
58
- return value;
59
- });
60
- return config;
61
- }
62
- function jsonify(value) {
63
- Object.defineProperty(value, 'toJSON', {
64
- value: function () {
65
- return mapValues(value, function (subValue) {
66
- if (isFunction(subValue)) {
67
- return stringifyFunction(subValue);
68
- } else if (typeof subValue === 'object' && !Array.isArray(subValue)) {
69
- // mostly for assignments
70
- return mapValues(subValue, function (subSubValue) {
71
- if (isFunction(subSubValue)) {
72
- return stringifyFunction(subSubValue);
73
- }
74
-
75
- return subSubValue;
76
- });
77
- }
78
-
79
- return subValue;
80
- });
81
- }
82
- });
83
- return value;
84
- }
85
-
86
- export { jsonify, machineToJSON, parse, stringify, stringifyFunction };
package/es/mapState.js DELETED
@@ -1,32 +0,0 @@
1
- import { __values } from './_virtual/_tslib.js';
2
- import { matchesState } from './utils.js';
3
-
4
- function mapState(stateMap, stateId) {
5
- var e_1, _a;
6
-
7
- var foundStateId;
8
-
9
- try {
10
- for (var _b = __values(Object.keys(stateMap)), _c = _b.next(); !_c.done; _c = _b.next()) {
11
- var mappedStateId = _c.value;
12
-
13
- if (matchesState(mappedStateId, stateId) && (!foundStateId || stateId.length > foundStateId.length)) {
14
- foundStateId = mappedStateId;
15
- }
16
- }
17
- } catch (e_1_1) {
18
- e_1 = {
19
- error: e_1_1
20
- };
21
- } finally {
22
- try {
23
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
24
- } finally {
25
- if (e_1) throw e_1.error;
26
- }
27
- }
28
-
29
- return stateMap[foundStateId];
30
- }
31
-
32
- export { mapState };
package/es/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/es/match.js DELETED
@@ -1,34 +0,0 @@
1
- import { __values, __read } from './_virtual/_tslib.js';
2
- import { State } from './State.js';
3
-
4
- function matchState(state, patterns, defaultValue) {
5
- var e_1, _a;
6
-
7
- var resolvedState = State.from(state, state instanceof State ? state.context : undefined);
8
-
9
- try {
10
- for (var patterns_1 = __values(patterns), patterns_1_1 = patterns_1.next(); !patterns_1_1.done; patterns_1_1 = patterns_1.next()) {
11
- var _b = __read(patterns_1_1.value, 2),
12
- stateValue = _b[0],
13
- getValue = _b[1];
14
-
15
- if (resolvedState.matches(stateValue)) {
16
- return getValue(resolvedState);
17
- }
18
- }
19
- } catch (e_1_1) {
20
- e_1 = {
21
- error: e_1_1
22
- };
23
- } finally {
24
- try {
25
- if (patterns_1_1 && !patterns_1_1.done && (_a = patterns_1.return)) _a.call(patterns_1);
26
- } finally {
27
- if (e_1) throw e_1.error;
28
- }
29
- }
30
-
31
- return defaultValue(resolvedState);
32
- }
33
-
34
- export { matchState };
package/es/model.d.ts DELETED
@@ -1,8 +0,0 @@
1
- import type { Cast, EventObject, BaseActionObject, Prop, IsNever } from './types';
2
- import { UnionFromCreatorsReturnTypes, FinalModelCreators, Model, ModelCreators } from './model.types';
3
- /**
4
- * @deprecated Use [Typegen](https://stately.ai/blog/introducing-typescript-typegen-for-xstate) instead.
5
- */
6
- export declare function createModel<TContext, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject>(initialContext: TContext): Model<TContext, TEvent, TAction, void>;
7
- 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>;
8
- //# sourceMappingURL=model.d.ts.map
package/es/model.js DELETED
@@ -1,50 +0,0 @@
1
- import { __assign, __spreadArray, __read } from './_virtual/_tslib.js';
2
- import { assign } from './actions.js';
3
- import { createMachine } from './Machine.js';
4
- import { mapValues } from './utils.js';
5
-
6
- function createModel(initialContext, creators) {
7
- var eventCreators = creators === null || creators === void 0 ? void 0 : creators.events;
8
- var actionCreators = creators === null || creators === void 0 ? void 0 : creators.actions;
9
- var model = {
10
- initialContext: initialContext,
11
- assign: assign,
12
- events: eventCreators ? mapValues(eventCreators, function (fn, eventType) {
13
- return function () {
14
- var args = [];
15
-
16
- for (var _i = 0; _i < arguments.length; _i++) {
17
- args[_i] = arguments[_i];
18
- }
19
-
20
- return __assign(__assign({}, fn.apply(void 0, __spreadArray([], __read(args), false))), {
21
- type: eventType
22
- });
23
- };
24
- }) : undefined,
25
- actions: actionCreators ? mapValues(actionCreators, function (fn, actionType) {
26
- return function () {
27
- var args = [];
28
-
29
- for (var _i = 0; _i < arguments.length; _i++) {
30
- args[_i] = arguments[_i];
31
- }
32
-
33
- return __assign(__assign({}, fn.apply(void 0, __spreadArray([], __read(args), false))), {
34
- type: actionType
35
- });
36
- };
37
- }) : undefined,
38
- reset: function () {
39
- return assign(initialContext);
40
- },
41
- createMachine: function (config, implementations) {
42
- return createMachine('context' in config ? config : __assign(__assign({}, config), {
43
- context: initialContext
44
- }), implementations);
45
- }
46
- };
47
- return model;
48
- }
49
-
50
- export { createModel };
@@ -1,56 +0,0 @@
1
- import { AnyFunction, AssignAction, Assigner, BaseActionObject, Compute, EventObject, MachineConfig, Prop, PropertyAssigner, StateMachine, InternalMachineOptions, ServiceMap } from './types';
2
- import { ResolveTypegenMeta, TypegenConstraint, TypegenDisabled } from './typegenTypes';
3
- declare type SimplisticExtractEvent<TEvent extends EventObject, TEventType extends TEvent['type']> = TEvent extends {
4
- type: TEventType;
5
- } ? TEvent : never;
6
- export interface Model<TContext, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject, TModelCreators = void> {
7
- initialContext: TContext;
8
- assign: <TEventType extends TEvent['type'] = TEvent['type']>(assigner: Assigner<TContext, SimplisticExtractEvent<TEvent, TEventType>> | PropertyAssigner<TContext, SimplisticExtractEvent<TEvent, TEventType>>, eventType?: TEventType) => AssignAction<TContext, SimplisticExtractEvent<TEvent, TEventType>>;
9
- events: Prop<TModelCreators, 'events'>;
10
- actions: Prop<TModelCreators, 'actions'>;
11
- reset: () => AssignAction<TContext, any>;
12
- createMachine: {
13
- <TServiceMap extends ServiceMap = ServiceMap, TTypesMeta extends TypegenConstraint = TypegenDisabled>(config: MachineConfig<TContext, any, TEvent, TAction, TServiceMap, TTypesMeta>, implementations?: InternalMachineOptions<TContext, TEvent, ResolveTypegenMeta<TTypesMeta, TEvent, TAction, TServiceMap>>): StateMachine<TContext, any, TEvent, {
14
- value: any;
15
- context: TContext;
16
- }, TAction, TServiceMap, ResolveTypegenMeta<TTypesMeta, TEvent, TAction, TServiceMap>>;
17
- };
18
- }
19
- export declare type ModelContextFrom<TModel extends Model<any, any, any, any>> = TModel extends Model<infer TContext, any, any, any> ? TContext : never;
20
- export declare type ModelEventsFrom<TModel extends Model<any, any, any, any> | undefined> = TModel extends Model<any, infer TEvent, any, any> ? TEvent : EventObject;
21
- export declare type ModelActionsFrom<TModel extends Model<any, any, any, any>> = TModel extends Model<any, any, infer TAction, any> ? TAction : never;
22
- export declare type EventCreator<Self extends AnyFunction, Return = ReturnType<Self>> = Return extends object ? Return extends {
23
- type: any;
24
- } ? "An event creator can't return an object with a type property" : Self : 'An event creator must return an object';
25
- export declare type EventCreators<Self> = {
26
- [K in keyof Self]: Self[K] extends AnyFunction ? EventCreator<Self[K]> : 'An event creator must be a function';
27
- };
28
- export declare type FinalEventCreators<Self> = {
29
- [K in keyof Self]: Self[K] extends AnyFunction ? (...args: Parameters<Self[K]>) => Compute<ReturnType<Self[K]> & {
30
- type: K;
31
- }> : never;
32
- };
33
- export declare type ActionCreator<Self extends AnyFunction, Return = ReturnType<Self>> = Return extends object ? Return extends {
34
- type: any;
35
- } ? "An action creator can't return an object with a type property" : Self : 'An action creator must return an object';
36
- export declare type ActionCreators<Self> = {
37
- [K in keyof Self]: Self[K] extends AnyFunction ? ActionCreator<Self[K]> : 'An action creator must be a function';
38
- };
39
- export declare type FinalActionCreators<Self> = {
40
- [K in keyof Self]: Self[K] extends AnyFunction ? (...args: Parameters<Self[K]>) => Compute<ReturnType<Self[K]> & {
41
- type: K;
42
- }> : never;
43
- };
44
- export interface ModelCreators<Self> {
45
- events?: EventCreators<Prop<Self, 'events'>>;
46
- actions?: ActionCreators<Prop<Self, 'actions'>>;
47
- }
48
- export interface FinalModelCreators<Self> {
49
- events: FinalEventCreators<Prop<Self, 'events'>>;
50
- actions: FinalActionCreators<Prop<Self, 'actions'>>;
51
- }
52
- export declare type UnionFromCreatorsReturnTypes<TCreators> = {
53
- [K in keyof TCreators]: TCreators[K] extends AnyFunction ? ReturnType<TCreators[K]> : never;
54
- }[keyof TCreators];
55
- export {};
56
- //# sourceMappingURL=model.types.d.ts.map
package/es/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/es/patterns.js DELETED
@@ -1,48 +0,0 @@
1
- import { __assign } from './_virtual/_tslib.js';
2
- import { toEventObject } from './utils.js';
3
-
4
- function toggle(onState, offState, eventType) {
5
- var _a, _b, _c;
6
-
7
- return _a = {}, _a[onState] = {
8
- on: (_b = {}, _b[eventType] = offState, _b)
9
- }, _a[offState] = {
10
- on: (_c = {}, _c[eventType] = onState, _c)
11
- }, _a;
12
- }
13
- var defaultSequencePatternOptions = {
14
- nextEvent: 'NEXT',
15
- prevEvent: 'PREV'
16
- };
17
- function sequence(items, options) {
18
- var resolvedOptions = __assign(__assign({}, defaultSequencePatternOptions), options);
19
-
20
- var states = {};
21
- var nextEventObject = resolvedOptions.nextEvent === undefined ? undefined : toEventObject(resolvedOptions.nextEvent);
22
- var prevEventObject = resolvedOptions.prevEvent === undefined ? undefined : toEventObject(resolvedOptions.prevEvent);
23
- items.forEach(function (item, i) {
24
- var state = {
25
- on: {}
26
- };
27
-
28
- if (i + 1 === items.length) {
29
- state.type = 'final';
30
- }
31
-
32
- if (nextEventObject && i + 1 < items.length) {
33
- state.on[nextEventObject.type] = items[i + 1];
34
- }
35
-
36
- if (prevEventObject && i > 0) {
37
- state.on[prevEventObject.type] = items[i - 1];
38
- }
39
-
40
- states[item] = state;
41
- });
42
- return {
43
- initial: items[0],
44
- states: states
45
- };
46
- }
47
-
48
- export { sequence, toggle };
package/es/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/es/registry.js DELETED
@@ -1,19 +0,0 @@
1
- var children = /*#__PURE__*/new Map();
2
- var sessionIdIndex = 0;
3
- var registry = {
4
- bookId: function () {
5
- return "x:".concat(sessionIdIndex++);
6
- },
7
- register: function (id, actor) {
8
- children.set(id, actor);
9
- return id;
10
- },
11
- get: function (id) {
12
- return children.get(id);
13
- },
14
- free: function (id) {
15
- children.delete(id);
16
- }
17
- };
18
-
19
- export { registry };
package/es/scheduler.d.ts DELETED
@@ -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/es/scheduler.js DELETED
@@ -1,79 +0,0 @@
1
- import { __assign } from './_virtual/_tslib.js';
2
-
3
- var defaultOptions = {
4
- deferEvents: false
5
- };
6
-
7
- var Scheduler =
8
- /*#__PURE__*/
9
-
10
- /** @class */
11
- function () {
12
- function Scheduler(options) {
13
- this.processingEvent = false;
14
- this.queue = [];
15
- this.initialized = false;
16
- this.options = __assign(__assign({}, defaultOptions), options);
17
- }
18
-
19
- Scheduler.prototype.initialize = function (callback) {
20
- this.initialized = true;
21
-
22
- if (callback) {
23
- if (!this.options.deferEvents) {
24
- this.schedule(callback);
25
- return;
26
- }
27
-
28
- this.process(callback);
29
- }
30
-
31
- this.flushEvents();
32
- };
33
-
34
- Scheduler.prototype.schedule = function (task) {
35
- if (!this.initialized || this.processingEvent) {
36
- this.queue.push(task);
37
- return;
38
- }
39
-
40
- if (this.queue.length !== 0) {
41
- throw new Error('Event queue should be empty when it is not processing events');
42
- }
43
-
44
- this.process(task);
45
- this.flushEvents();
46
- };
47
-
48
- Scheduler.prototype.clear = function () {
49
- this.queue = [];
50
- };
51
-
52
- Scheduler.prototype.flushEvents = function () {
53
- var nextCallback = this.queue.shift();
54
-
55
- while (nextCallback) {
56
- this.process(nextCallback);
57
- nextCallback = this.queue.shift();
58
- }
59
- };
60
-
61
- Scheduler.prototype.process = function (callback) {
62
- this.processingEvent = true;
63
-
64
- try {
65
- callback();
66
- } catch (e) {
67
- // there is no use to keep the future events
68
- // as the situation is not anymore the same
69
- this.clear();
70
- throw e;
71
- } finally {
72
- this.processingEvent = false;
73
- }
74
- };
75
-
76
- return Scheduler;
77
- }();
78
-
79
- export { Scheduler };
package/es/schema.js DELETED
@@ -1,6 +0,0 @@
1
- function createSchema(schema) {
2
- return schema;
3
- }
4
- var t = createSchema;
5
-
6
- export { createSchema, t };
package/es/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
@@ -1,4 +0,0 @@
1
- import { AnyInterpreter } from './types';
2
- export declare const provide: <T, TService extends AnyInterpreter>(service: TService | undefined, fn: (service: TService | undefined) => T) => T;
3
- export declare const consume: <T, TService extends AnyInterpreter>(fn: (service: TService) => T) => T;
4
- //# sourceMappingURL=serviceScope.d.ts.map
@@ -1,16 +0,0 @@
1
- /**
2
- * Maintains a stack of the current service in scope.
3
- * This is used to provide the correct service to spawn().
4
- */
5
- var serviceStack = [];
6
- var provide = function (service, fn) {
7
- serviceStack.push(service);
8
- var result = fn(service);
9
- serviceStack.pop();
10
- return result;
11
- };
12
- var consume = function (fn) {
13
- return fn(serviceStack[serviceStack.length - 1]);
14
- };
15
-
16
- export { consume, provide };
@@ -1,18 +0,0 @@
1
- import { EventObject, StateValue } from './types';
2
- import { StateNode } from './StateNode';
3
- declare type Configuration<TC, TE extends EventObject> = Iterable<StateNode<TC, any, TE>>;
4
- declare type AdjList<TC, TE extends EventObject> = Map<StateNode<TC, any, TE>, Array<StateNode<TC, any, TE>>>;
5
- export declare const isLeafNode: (stateNode: StateNode<any, any, any, any, any, any>) => boolean;
6
- export declare function getAllChildren<TC, TE extends EventObject>(stateNode: StateNode<TC, any, TE>): Array<StateNode<TC, any, TE>>;
7
- export declare function getChildren<TC, TE extends EventObject>(stateNode: StateNode<TC, any, TE>): Array<StateNode<TC, any, TE>>;
8
- export declare function getAllStateNodes<TC, TE extends EventObject>(stateNode: StateNode<TC, any, TE, any, any, any>): Array<StateNode<TC, any, TE, any, any, any>>;
9
- export declare function getConfiguration<TC, TE extends EventObject>(prevStateNodes: Iterable<StateNode<TC, any, TE, any, any, any>>, stateNodes: Iterable<StateNode<TC, any, TE, any, any, any>>): Set<StateNode<TC, any, TE, any, any, any>>;
10
- export declare function getAdjList<TC, TE extends EventObject>(configuration: Configuration<TC, TE>): AdjList<TC, TE>;
11
- export declare function getValue<TC, TE extends EventObject>(rootNode: StateNode<TC, any, TE, any>, configuration: Configuration<TC, TE>): StateValue;
12
- export declare function has<T>(iterable: Iterable<T>, item: T): boolean;
13
- export declare function nextEvents<TC, TE extends EventObject>(configuration: Array<StateNode<TC, any, TE>>): Array<TE['type']>;
14
- export declare function isInFinalState<TC, TE extends EventObject>(configuration: Array<StateNode<TC, any, TE, any, any, any>>, stateNode: StateNode<TC, any, TE, any, any, any>): boolean;
15
- export declare function getMeta(configuration?: StateNode[]): Record<string, any>;
16
- export declare function getTagsFromConfiguration(configuration: StateNode<any, any, any, any>[]): Set<string>;
17
- export {};
18
- //# sourceMappingURL=stateUtils.d.ts.map