xstate 4.12.0 → 4.13.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.
- package/CHANGELOG.md +52 -0
- package/dist/xstate.interpreter.js +1 -1
- package/dist/xstate.js +1 -1
- package/dist/xstate.web.js +1 -1
- package/es/Actor.js +5 -1
- package/es/StateNode.js +11 -11
- package/es/actions.d.ts +1 -1
- package/es/interpreter.d.ts +2 -2
- package/es/interpreter.js +9 -25
- package/es/serviceScope.d.ts +10 -0
- package/es/serviceScope.js +18 -0
- package/es/stateUtils.d.ts +1 -4
- package/es/types.d.ts +11 -12
- package/lib/Actor.js +4 -1
- package/lib/Machine.js +1 -0
- package/lib/SimulatedClock.js +1 -0
- package/lib/State.js +1 -0
- package/lib/StateNode.js +12 -11
- package/lib/actionTypes.js +1 -0
- package/lib/actions.d.ts +1 -1
- package/lib/actions.js +1 -0
- package/lib/constants.js +1 -0
- package/lib/devTools.js +1 -0
- package/lib/each.js +1 -0
- package/lib/environment.js +1 -0
- package/lib/index.js +28 -20
- package/lib/interpreter.d.ts +2 -2
- package/lib/interpreter.js +10 -23
- package/lib/invokeUtils.js +1 -0
- package/lib/json.js +1 -0
- package/lib/mapState.js +1 -0
- package/lib/match.js +1 -0
- package/lib/patterns.js +1 -0
- package/lib/registry.js +1 -0
- package/lib/scheduler.js +1 -0
- package/lib/scxml.js +1 -0
- package/lib/serviceScope.d.ts +10 -0
- package/lib/serviceScope.js +15 -0
- package/lib/stateUtils.d.ts +1 -4
- package/lib/stateUtils.js +1 -0
- package/lib/types.d.ts +11 -12
- package/lib/types.js +1 -0
- package/lib/utils.js +1 -0
- package/package.json +1 -1
package/es/Actor.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { toInvokeSource, mapContext, isMachine } from './utils.js';
|
|
2
|
+
import { provide } from './serviceScope.js';
|
|
2
3
|
|
|
3
4
|
function createNullActor(id) {
|
|
4
5
|
return {
|
|
@@ -44,7 +45,10 @@ function createDeferredActor(entity, id, data) {
|
|
|
44
45
|
tempActor.deferred = true;
|
|
45
46
|
|
|
46
47
|
if (isMachine(entity)) {
|
|
47
|
-
|
|
48
|
+
// "mute" the existing service scope so potential spawned actors within the `.initialState` stay deferred here
|
|
49
|
+
tempActor.state = provide(undefined, function () {
|
|
50
|
+
return (data ? entity.withContext(data) : entity).initialState;
|
|
51
|
+
});
|
|
48
52
|
}
|
|
49
53
|
|
|
50
54
|
return tempActor;
|
package/es/StateNode.js
CHANGED
|
@@ -256,7 +256,7 @@ function () {
|
|
|
256
256
|
invoke: this.invoke
|
|
257
257
|
};
|
|
258
258
|
},
|
|
259
|
-
enumerable:
|
|
259
|
+
enumerable: false,
|
|
260
260
|
configurable: true
|
|
261
261
|
});
|
|
262
262
|
|
|
@@ -280,14 +280,14 @@ function () {
|
|
|
280
280
|
return map;
|
|
281
281
|
}, {});
|
|
282
282
|
},
|
|
283
|
-
enumerable:
|
|
283
|
+
enumerable: false,
|
|
284
284
|
configurable: true
|
|
285
285
|
});
|
|
286
286
|
Object.defineProperty(StateNode.prototype, "after", {
|
|
287
287
|
get: function () {
|
|
288
288
|
return this.__cache.delayedTransitions || (this.__cache.delayedTransitions = this.getDelayedTransitions(), this.__cache.delayedTransitions);
|
|
289
289
|
},
|
|
290
|
-
enumerable:
|
|
290
|
+
enumerable: false,
|
|
291
291
|
configurable: true
|
|
292
292
|
});
|
|
293
293
|
Object.defineProperty(StateNode.prototype, "transitions", {
|
|
@@ -297,7 +297,7 @@ function () {
|
|
|
297
297
|
get: function () {
|
|
298
298
|
return this.__cache.transitions || (this.__cache.transitions = this.formatTransitions(), this.__cache.transitions);
|
|
299
299
|
},
|
|
300
|
-
enumerable:
|
|
300
|
+
enumerable: false,
|
|
301
301
|
configurable: true
|
|
302
302
|
});
|
|
303
303
|
|
|
@@ -1117,7 +1117,7 @@ function () {
|
|
|
1117
1117
|
this.__cache.initialStateValue = initialStateValue;
|
|
1118
1118
|
return this.__cache.initialStateValue;
|
|
1119
1119
|
},
|
|
1120
|
-
enumerable:
|
|
1120
|
+
enumerable: false,
|
|
1121
1121
|
configurable: true
|
|
1122
1122
|
});
|
|
1123
1123
|
|
|
@@ -1150,7 +1150,7 @@ function () {
|
|
|
1150
1150
|
|
|
1151
1151
|
return this.getInitialState(initialStateValue);
|
|
1152
1152
|
},
|
|
1153
|
-
enumerable:
|
|
1153
|
+
enumerable: false,
|
|
1154
1154
|
configurable: true
|
|
1155
1155
|
});
|
|
1156
1156
|
Object.defineProperty(StateNode.prototype, "target", {
|
|
@@ -1173,7 +1173,7 @@ function () {
|
|
|
1173
1173
|
|
|
1174
1174
|
return target;
|
|
1175
1175
|
},
|
|
1176
|
-
enumerable:
|
|
1176
|
+
enumerable: false,
|
|
1177
1177
|
configurable: true
|
|
1178
1178
|
});
|
|
1179
1179
|
/**
|
|
@@ -1214,7 +1214,7 @@ function () {
|
|
|
1214
1214
|
return _this.getFromRelativePath(initialPath);
|
|
1215
1215
|
}));
|
|
1216
1216
|
},
|
|
1217
|
-
enumerable:
|
|
1217
|
+
enumerable: false,
|
|
1218
1218
|
configurable: true
|
|
1219
1219
|
});
|
|
1220
1220
|
/**
|
|
@@ -1316,7 +1316,7 @@ function () {
|
|
|
1316
1316
|
}));
|
|
1317
1317
|
return [this.id].concat(childStateIds);
|
|
1318
1318
|
},
|
|
1319
|
-
enumerable:
|
|
1319
|
+
enumerable: false,
|
|
1320
1320
|
configurable: true
|
|
1321
1321
|
});
|
|
1322
1322
|
Object.defineProperty(StateNode.prototype, "events", {
|
|
@@ -1373,7 +1373,7 @@ function () {
|
|
|
1373
1373
|
|
|
1374
1374
|
return this.__cache.events = Array.from(events);
|
|
1375
1375
|
},
|
|
1376
|
-
enumerable:
|
|
1376
|
+
enumerable: false,
|
|
1377
1377
|
configurable: true
|
|
1378
1378
|
});
|
|
1379
1379
|
Object.defineProperty(StateNode.prototype, "ownEvents", {
|
|
@@ -1390,7 +1390,7 @@ function () {
|
|
|
1390
1390
|
}));
|
|
1391
1391
|
return Array.from(events);
|
|
1392
1392
|
},
|
|
1393
|
-
enumerable:
|
|
1393
|
+
enumerable: false,
|
|
1394
1394
|
configurable: true
|
|
1395
1395
|
});
|
|
1396
1396
|
|
package/es/actions.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export declare const initEvent: SCXML.Event<{
|
|
|
8
8
|
}>;
|
|
9
9
|
export declare function getActionFunction<TContext, TEvent extends EventObject>(actionType: ActionType, actionFunctionMap?: ActionFunctionMap<TContext, TEvent>): ActionObject<TContext, TEvent> | ActionFunction<TContext, TEvent> | undefined;
|
|
10
10
|
export declare function toActionObject<TContext, TEvent extends EventObject>(action: Action<TContext, TEvent>, actionFunctionMap?: ActionFunctionMap<TContext, TEvent>): ActionObject<TContext, TEvent>;
|
|
11
|
-
export declare const toActionObjects: <TContext, TEvent extends EventObject>(action?: string | ActionObject<TContext, TEvent> | ActionFunction<TContext, TEvent> | Action<TContext, TEvent>[] | undefined, actionFunctionMap?: Record<string,
|
|
11
|
+
export declare const toActionObjects: <TContext, TEvent extends EventObject>(action?: string | ActionObject<TContext, TEvent> | ActionFunction<TContext, TEvent> | Action<TContext, TEvent>[] | undefined, actionFunctionMap?: Record<string, ActionObject<TContext, TEvent> | ActionFunction<TContext, TEvent>> | undefined) => ActionObject<TContext, TEvent>[];
|
|
12
12
|
export declare function toActivityDefinition<TContext, TEvent extends EventObject>(action: string | ActivityDefinition<TContext, TEvent>): ActivityDefinition<TContext, TEvent>;
|
|
13
13
|
/**
|
|
14
14
|
* Raises an event. This places the event in the internal event queue, so that
|
package/es/interpreter.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StateMachine, Event, EventObject, DefaultContext, StateSchema, StateValue, InterpreterOptions, DoneEvent, Unsubscribable, MachineOptions, SCXML, EventData, Observer, Spawnable, Typestate } from './types';
|
|
1
|
+
import { StateMachine, Event, EventObject, DefaultContext, StateSchema, StateValue, InterpreterOptions, SingleOrArray, DoneEvent, Unsubscribable, MachineOptions, SCXML, EventData, Observer, Spawnable, Typestate } from './types';
|
|
2
2
|
import { State } from './State';
|
|
3
3
|
import { Actor } from './Actor';
|
|
4
4
|
export declare type StateListener<TContext, TEvent extends EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
|
|
@@ -137,7 +137,7 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
137
137
|
*
|
|
138
138
|
* @param event The event(s) to send
|
|
139
139
|
*/
|
|
140
|
-
send: (event:
|
|
140
|
+
send: (event: SingleOrArray<Event<TEvent>> | SCXML.Event<TEvent>, payload?: EventData | undefined) => State<TContext, TEvent, TStateSchema, TTypestate>;
|
|
141
141
|
private batch;
|
|
142
142
|
/**
|
|
143
143
|
* Returns a send function bound to this interpreter instance.
|
package/es/interpreter.js
CHANGED
|
@@ -6,6 +6,7 @@ import { isInFinalState } from './stateUtils.js';
|
|
|
6
6
|
import { errorPlatform, log, stop, start, cancel, send, update, error as error$1 } from './actionTypes.js';
|
|
7
7
|
import { doneInvoke, initEvent, getActionFunction, error } from './actions.js';
|
|
8
8
|
import { isState, State, bindActionToState } from './State.js';
|
|
9
|
+
import { provide, consume } from './serviceScope.js';
|
|
9
10
|
import { isActor, createDeferredActor } from './Actor.js';
|
|
10
11
|
import { Scheduler } from './scheduler.js';
|
|
11
12
|
import { registry } from './registry.js';
|
|
@@ -14,23 +15,6 @@ var DEFAULT_SPAWN_OPTIONS = {
|
|
|
14
15
|
sync: false,
|
|
15
16
|
autoForward: false
|
|
16
17
|
};
|
|
17
|
-
/**
|
|
18
|
-
* Maintains a stack of the current service in scope.
|
|
19
|
-
* This is used to provide the correct service to spawn().
|
|
20
|
-
*
|
|
21
|
-
* @private
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
var withServiceScope = /*#__PURE__*/function () {
|
|
25
|
-
var serviceStack = [];
|
|
26
|
-
return function (service, fn) {
|
|
27
|
-
service && serviceStack.push(service);
|
|
28
|
-
var result = fn(service || serviceStack[serviceStack.length - 1]);
|
|
29
|
-
service && serviceStack.pop();
|
|
30
|
-
return result;
|
|
31
|
-
};
|
|
32
|
-
}();
|
|
33
|
-
|
|
34
18
|
var InterpreterStatus;
|
|
35
19
|
|
|
36
20
|
(function (InterpreterStatus) {
|
|
@@ -184,12 +168,12 @@ function () {
|
|
|
184
168
|
return this._initialState;
|
|
185
169
|
}
|
|
186
170
|
|
|
187
|
-
return
|
|
171
|
+
return provide(this, function () {
|
|
188
172
|
_this._initialState = _this.machine.initialState;
|
|
189
173
|
return _this._initialState;
|
|
190
174
|
});
|
|
191
175
|
},
|
|
192
|
-
enumerable:
|
|
176
|
+
enumerable: false,
|
|
193
177
|
configurable: true
|
|
194
178
|
});
|
|
195
179
|
Object.defineProperty(Interpreter.prototype, "state", {
|
|
@@ -200,7 +184,7 @@ function () {
|
|
|
200
184
|
|
|
201
185
|
return this._state;
|
|
202
186
|
},
|
|
203
|
-
enumerable:
|
|
187
|
+
enumerable: false,
|
|
204
188
|
configurable: true
|
|
205
189
|
});
|
|
206
190
|
/**
|
|
@@ -472,7 +456,7 @@ function () {
|
|
|
472
456
|
registry.register(this.sessionId, this);
|
|
473
457
|
this.initialized = true;
|
|
474
458
|
this._status = InterpreterStatus.Running;
|
|
475
|
-
var resolvedState = initialState === undefined ? this.initialState :
|
|
459
|
+
var resolvedState = initialState === undefined ? this.initialState : provide(this, function () {
|
|
476
460
|
return isState(initialState) ? _this.machine.resolveState(initialState) : _this.machine.resolveState(State.from(initialState, _this.machine.context));
|
|
477
461
|
});
|
|
478
462
|
|
|
@@ -622,7 +606,7 @@ function () {
|
|
|
622
606
|
|
|
623
607
|
_this.forward(_event);
|
|
624
608
|
|
|
625
|
-
nextState =
|
|
609
|
+
nextState = provide(_this, function () {
|
|
626
610
|
return _this.machine.transition(nextState, _event);
|
|
627
611
|
});
|
|
628
612
|
batchedActions.push.apply(batchedActions, __spread(nextState.actions.map(function (a) {
|
|
@@ -685,7 +669,7 @@ function () {
|
|
|
685
669
|
throw _event.data.data;
|
|
686
670
|
}
|
|
687
671
|
|
|
688
|
-
var nextState =
|
|
672
|
+
var nextState = provide(this, function () {
|
|
689
673
|
return _this.machine.transition(_this.state, _event);
|
|
690
674
|
});
|
|
691
675
|
return nextState;
|
|
@@ -1248,7 +1232,7 @@ function () {
|
|
|
1248
1232
|
logger: global.console.log.bind(console),
|
|
1249
1233
|
devTools: false
|
|
1250
1234
|
};
|
|
1251
|
-
}(typeof
|
|
1235
|
+
}(typeof self !== 'undefined' ? self : global);
|
|
1252
1236
|
|
|
1253
1237
|
Interpreter.interpret = interpret;
|
|
1254
1238
|
return Interpreter;
|
|
@@ -1268,7 +1252,7 @@ var resolveSpawnOptions = function (nameOrOptions) {
|
|
|
1268
1252
|
|
|
1269
1253
|
function spawn(entity, nameOrOptions) {
|
|
1270
1254
|
var resolvedOptions = resolveSpawnOptions(nameOrOptions);
|
|
1271
|
-
return
|
|
1255
|
+
return consume(function (service) {
|
|
1272
1256
|
if (!IS_PRODUCTION) {
|
|
1273
1257
|
var isLazyEntity = isMachine(entity) || isFunction(entity);
|
|
1274
1258
|
warn(!!service || isLazyEntity, "Attempted to spawn an Actor (ID: \"" + (isMachine(entity) ? entity.id : 'undefined') + "\") outside of a service. This will have no effect.");
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Interpreter } from './interpreter';
|
|
2
|
+
export declare const provide: <T, TService extends Interpreter<any, any, any, {
|
|
3
|
+
value: any;
|
|
4
|
+
context: any;
|
|
5
|
+
}>>(service: TService | undefined, fn: (service: TService | undefined) => T) => T;
|
|
6
|
+
export declare const consume: <T, TService extends Interpreter<any, any, any, {
|
|
7
|
+
value: any;
|
|
8
|
+
context: any;
|
|
9
|
+
}>>(fn: (service: TService) => T) => T;
|
|
10
|
+
//# sourceMappingURL=serviceScope.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
|
|
7
|
+
var provide = function (service, fn) {
|
|
8
|
+
serviceStack.push(service);
|
|
9
|
+
var result = fn(service);
|
|
10
|
+
serviceStack.pop();
|
|
11
|
+
return result;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
var consume = function (fn) {
|
|
15
|
+
return fn(serviceStack[serviceStack.length - 1]);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { consume, provide };
|
package/es/stateUtils.d.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { EventObject, StateNode, StateValue } from '.';
|
|
2
2
|
declare type Configuration<TC, TE extends EventObject> = Iterable<StateNode<TC, any, TE>>;
|
|
3
3
|
declare type AdjList<TC, TE extends EventObject> = Map<StateNode<TC, any, TE>, Array<StateNode<TC, any, TE>>>;
|
|
4
|
-
export declare const isLeafNode: (stateNode: StateNode<any, any, any
|
|
5
|
-
value: any;
|
|
6
|
-
context: any;
|
|
7
|
-
}>) => boolean;
|
|
4
|
+
export declare const isLeafNode: (stateNode: StateNode<any, any, any>) => boolean;
|
|
8
5
|
export declare function getChildren<TC, TE extends EventObject>(stateNode: StateNode<TC, any, TE>): Array<StateNode<TC, any, TE>>;
|
|
9
6
|
export declare function getAllStateNodes<TC, TE extends EventObject>(stateNode: StateNode<TC, any, TE>): Array<StateNode<TC, any, TE>>;
|
|
10
7
|
export declare function getConfiguration<TC, TE extends EventObject>(prevStateNodes: Iterable<StateNode<TC, any, TE>>, stateNodes: Iterable<StateNode<TC, any, TE>>): Iterable<StateNode<TC, any, TE>>;
|
package/es/types.d.ts
CHANGED
|
@@ -67,11 +67,14 @@ export interface StateValueMap {
|
|
|
67
67
|
* - For complex state nodes, this is an object, e.g., `{ success: "someChildState" }`.
|
|
68
68
|
*/
|
|
69
69
|
export declare type StateValue = string | StateValueMap;
|
|
70
|
-
|
|
71
|
-
[K in keyof
|
|
72
|
-
states:
|
|
73
|
-
} ?
|
|
74
|
-
};
|
|
70
|
+
declare type KeysWithStates<TStates extends Record<string, StateSchema> | undefined> = TStates extends object ? {
|
|
71
|
+
[K in keyof TStates]-?: TStates[K] extends {
|
|
72
|
+
states: object;
|
|
73
|
+
} ? K : never;
|
|
74
|
+
}[keyof TStates] : never;
|
|
75
|
+
export declare type ExtractStateValue<TSchema extends Required<Pick<StateSchema<any>, 'states'>>> = keyof TSchema['states'] | (KeysWithStates<TSchema['states']> extends never ? never : {
|
|
76
|
+
[K in KeysWithStates<TSchema['states']>]?: ExtractStateValue<TSchema['states'][K]>;
|
|
77
|
+
});
|
|
75
78
|
export interface HistoryValue {
|
|
76
79
|
states: Record<string, HistoryValue | undefined>;
|
|
77
80
|
current: StateValue | undefined;
|
|
@@ -190,13 +193,9 @@ declare type TransitionsConfigMap<TContext, TEvent extends EventObject> = {
|
|
|
190
193
|
} & {
|
|
191
194
|
'*'?: TransitionConfigOrTarget<TContext, TEvent>;
|
|
192
195
|
};
|
|
193
|
-
declare type TransitionsConfigArray<TContext, TEvent extends EventObject> = Array<{
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
} ? TEvent : never> & {
|
|
197
|
-
event: K;
|
|
198
|
-
};
|
|
199
|
-
}[TEvent['type']] | (TransitionConfig<TContext, TEvent> & {
|
|
196
|
+
declare type TransitionsConfigArray<TContext, TEvent extends EventObject> = Array<(TEvent extends EventObject ? TransitionConfig<TContext, TEvent> & {
|
|
197
|
+
event: TEvent['type'];
|
|
198
|
+
} : never) | (TransitionConfig<TContext, TEvent> & {
|
|
200
199
|
event: '';
|
|
201
200
|
}) | (TransitionConfig<TContext, TEvent> & {
|
|
202
201
|
event: '*';
|
package/lib/Actor.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isActor = exports.createDeferredActor = exports.createInvocableActor = exports.createNullActor = void 0;
|
|
3
4
|
var utils_1 = require("./utils");
|
|
5
|
+
var serviceScope = require("./serviceScope");
|
|
4
6
|
function createNullActor(id) {
|
|
5
7
|
return {
|
|
6
8
|
id: id,
|
|
@@ -38,7 +40,8 @@ function createDeferredActor(entity, id, data) {
|
|
|
38
40
|
var tempActor = createNullActor(id);
|
|
39
41
|
tempActor.deferred = true;
|
|
40
42
|
if (utils_1.isMachine(entity)) {
|
|
41
|
-
|
|
43
|
+
// "mute" the existing service scope so potential spawned actors within the `.initialState` stay deferred here
|
|
44
|
+
tempActor.state = serviceScope.provide(undefined, function () { return (data ? entity.withContext(data) : entity).initialState; });
|
|
42
45
|
}
|
|
43
46
|
return tempActor;
|
|
44
47
|
}
|
package/lib/Machine.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createMachine = exports.Machine = void 0;
|
|
3
4
|
var StateNode_1 = require("./StateNode");
|
|
4
5
|
function Machine(config, options, initialContext) {
|
|
5
6
|
if (initialContext === void 0) { initialContext = config.context; }
|
package/lib/SimulatedClock.js
CHANGED
|
@@ -20,6 +20,7 @@ var __spread = (this && this.__spread) || function () {
|
|
|
20
20
|
return ar;
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.SimulatedClock = void 0;
|
|
23
24
|
var SimulatedClock = /** @class */ (function () {
|
|
24
25
|
function SimulatedClock() {
|
|
25
26
|
this.timeouts = new Map();
|
package/lib/State.js
CHANGED
|
@@ -42,6 +42,7 @@ var __spread = (this && this.__spread) || function () {
|
|
|
42
42
|
return ar;
|
|
43
43
|
};
|
|
44
44
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.State = exports.bindActionToState = exports.isState = exports.stateValuesEqual = void 0;
|
|
45
46
|
var constants_1 = require("./constants");
|
|
46
47
|
var utils_1 = require("./utils");
|
|
47
48
|
var stateUtils_1 = require("./stateUtils");
|
package/lib/StateNode.js
CHANGED
|
@@ -53,6 +53,7 @@ var __values = (this && this.__values) || function(o) {
|
|
|
53
53
|
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
54
54
|
};
|
|
55
55
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
56
|
+
exports.StateNode = void 0;
|
|
56
57
|
var utils_1 = require("./utils");
|
|
57
58
|
var types_1 = require("./types");
|
|
58
59
|
var utils_2 = require("./utils");
|
|
@@ -288,7 +289,7 @@ var StateNode = /** @class */ (function () {
|
|
|
288
289
|
invoke: this.invoke
|
|
289
290
|
};
|
|
290
291
|
},
|
|
291
|
-
enumerable:
|
|
292
|
+
enumerable: false,
|
|
292
293
|
configurable: true
|
|
293
294
|
});
|
|
294
295
|
StateNode.prototype.toJSON = function () {
|
|
@@ -309,7 +310,7 @@ var StateNode = /** @class */ (function () {
|
|
|
309
310
|
return map;
|
|
310
311
|
}, {}));
|
|
311
312
|
},
|
|
312
|
-
enumerable:
|
|
313
|
+
enumerable: false,
|
|
313
314
|
configurable: true
|
|
314
315
|
});
|
|
315
316
|
Object.defineProperty(StateNode.prototype, "after", {
|
|
@@ -318,7 +319,7 @@ var StateNode = /** @class */ (function () {
|
|
|
318
319
|
((this.__cache.delayedTransitions = this.getDelayedTransitions()),
|
|
319
320
|
this.__cache.delayedTransitions));
|
|
320
321
|
},
|
|
321
|
-
enumerable:
|
|
322
|
+
enumerable: false,
|
|
322
323
|
configurable: true
|
|
323
324
|
});
|
|
324
325
|
Object.defineProperty(StateNode.prototype, "transitions", {
|
|
@@ -330,7 +331,7 @@ var StateNode = /** @class */ (function () {
|
|
|
330
331
|
((this.__cache.transitions = this.formatTransitions()),
|
|
331
332
|
this.__cache.transitions));
|
|
332
333
|
},
|
|
333
|
-
enumerable:
|
|
334
|
+
enumerable: false,
|
|
334
335
|
configurable: true
|
|
335
336
|
});
|
|
336
337
|
StateNode.prototype.getCandidates = function (eventName) {
|
|
@@ -1017,7 +1018,7 @@ var StateNode = /** @class */ (function () {
|
|
|
1017
1018
|
this.__cache.initialStateValue = initialStateValue;
|
|
1018
1019
|
return this.__cache.initialStateValue;
|
|
1019
1020
|
},
|
|
1020
|
-
enumerable:
|
|
1021
|
+
enumerable: false,
|
|
1021
1022
|
configurable: true
|
|
1022
1023
|
});
|
|
1023
1024
|
StateNode.prototype.getInitialState = function (stateValue, context) {
|
|
@@ -1044,7 +1045,7 @@ var StateNode = /** @class */ (function () {
|
|
|
1044
1045
|
}
|
|
1045
1046
|
return this.getInitialState(initialStateValue);
|
|
1046
1047
|
},
|
|
1047
|
-
enumerable:
|
|
1048
|
+
enumerable: false,
|
|
1048
1049
|
configurable: true
|
|
1049
1050
|
});
|
|
1050
1051
|
Object.defineProperty(StateNode.prototype, "target", {
|
|
@@ -1069,7 +1070,7 @@ var StateNode = /** @class */ (function () {
|
|
|
1069
1070
|
}
|
|
1070
1071
|
return target;
|
|
1071
1072
|
},
|
|
1072
|
-
enumerable:
|
|
1073
|
+
enumerable: false,
|
|
1073
1074
|
configurable: true
|
|
1074
1075
|
});
|
|
1075
1076
|
/**
|
|
@@ -1105,7 +1106,7 @@ var StateNode = /** @class */ (function () {
|
|
|
1105
1106
|
return _this.getFromRelativePath(initialPath);
|
|
1106
1107
|
}));
|
|
1107
1108
|
},
|
|
1108
|
-
enumerable:
|
|
1109
|
+
enumerable: false,
|
|
1109
1110
|
configurable: true
|
|
1110
1111
|
});
|
|
1111
1112
|
/**
|
|
@@ -1189,7 +1190,7 @@ var StateNode = /** @class */ (function () {
|
|
|
1189
1190
|
}));
|
|
1190
1191
|
return [this.id].concat(childStateIds);
|
|
1191
1192
|
},
|
|
1192
|
-
enumerable:
|
|
1193
|
+
enumerable: false,
|
|
1193
1194
|
configurable: true
|
|
1194
1195
|
});
|
|
1195
1196
|
Object.defineProperty(StateNode.prototype, "events", {
|
|
@@ -1235,7 +1236,7 @@ var StateNode = /** @class */ (function () {
|
|
|
1235
1236
|
}
|
|
1236
1237
|
return (this.__cache.events = Array.from(events));
|
|
1237
1238
|
},
|
|
1238
|
-
enumerable:
|
|
1239
|
+
enumerable: false,
|
|
1239
1240
|
configurable: true
|
|
1240
1241
|
});
|
|
1241
1242
|
Object.defineProperty(StateNode.prototype, "ownEvents", {
|
|
@@ -1254,7 +1255,7 @@ var StateNode = /** @class */ (function () {
|
|
|
1254
1255
|
.map(function (transition) { return transition.eventType; }));
|
|
1255
1256
|
return Array.from(events);
|
|
1256
1257
|
},
|
|
1257
|
-
enumerable:
|
|
1258
|
+
enumerable: false,
|
|
1258
1259
|
configurable: true
|
|
1259
1260
|
});
|
|
1260
1261
|
StateNode.prototype.resolveTarget = function (_target) {
|
package/lib/actionTypes.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pure = exports.choose = exports.update = exports.error = exports.errorPlatform = exports.errorExecution = exports.invoke = exports.init = exports.log = exports.doneState = exports.after = exports.assign = exports.nullEvent = exports.cancel = exports.send = exports.raise = exports.stop = exports.start = void 0;
|
|
3
4
|
var types_1 = require("./types");
|
|
4
5
|
// xstate-specific action types
|
|
5
6
|
exports.start = types_1.ActionTypes.Start;
|
package/lib/actions.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export declare const initEvent: SCXML.Event<{
|
|
|
8
8
|
}>;
|
|
9
9
|
export declare function getActionFunction<TContext, TEvent extends EventObject>(actionType: ActionType, actionFunctionMap?: ActionFunctionMap<TContext, TEvent>): ActionObject<TContext, TEvent> | ActionFunction<TContext, TEvent> | undefined;
|
|
10
10
|
export declare function toActionObject<TContext, TEvent extends EventObject>(action: Action<TContext, TEvent>, actionFunctionMap?: ActionFunctionMap<TContext, TEvent>): ActionObject<TContext, TEvent>;
|
|
11
|
-
export declare const toActionObjects: <TContext, TEvent extends EventObject>(action?: string | ActionObject<TContext, TEvent> | ActionFunction<TContext, TEvent> | Action<TContext, TEvent>[] | undefined, actionFunctionMap?: Record<string,
|
|
11
|
+
export declare const toActionObjects: <TContext, TEvent extends EventObject>(action?: string | ActionObject<TContext, TEvent> | ActionFunction<TContext, TEvent> | Action<TContext, TEvent>[] | undefined, actionFunctionMap?: Record<string, ActionObject<TContext, TEvent> | ActionFunction<TContext, TEvent>> | undefined) => ActionObject<TContext, TEvent>[];
|
|
12
12
|
export declare function toActivityDefinition<TContext, TEvent extends EventObject>(action: string | ActivityDefinition<TContext, TEvent>): ActivityDefinition<TContext, TEvent>;
|
|
13
13
|
/**
|
|
14
14
|
* Raises an event. This places the event in the internal event queue, so that
|
package/lib/actions.js
CHANGED
|
@@ -27,6 +27,7 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
27
27
|
return ar;
|
|
28
28
|
};
|
|
29
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
exports.resolveActions = exports.choose = exports.escalate = exports.forwardTo = exports.pure = exports.error = exports.doneInvoke = exports.done = exports.after = exports.isActionObject = exports.assign = exports.stop = exports.start = exports.cancel = exports.resolveLog = exports.log = exports.respond = exports.sendUpdate = exports.sendParent = exports.resolveSend = exports.send = exports.resolveRaise = exports.raise = exports.toActivityDefinition = exports.toActionObjects = exports.toActionObject = exports.getActionFunction = exports.initEvent = exports.actionTypes = void 0;
|
|
30
31
|
var types_1 = require("./types");
|
|
31
32
|
var actionTypes = require("./actionTypes");
|
|
32
33
|
exports.actionTypes = actionTypes;
|
package/lib/constants.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TARGETLESS_KEY = exports.DEFAULT_GUARD_TYPE = exports.EMPTY_ACTIVITY_MAP = exports.STATE_DELIMITER = void 0;
|
|
3
4
|
exports.STATE_DELIMITER = '.';
|
|
4
5
|
exports.EMPTY_ACTIVITY_MAP = {};
|
|
5
6
|
exports.DEFAULT_GUARD_TYPE = 'xstate.guard';
|
package/lib/devTools.js
CHANGED
package/lib/each.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.each = void 0;
|
|
3
4
|
function each(collection, item, indexOrActions, maybeActions) {
|
|
4
5
|
var actions = maybeActions || indexOrActions;
|
|
5
6
|
var index = maybeActions ? indexOrActions : undefined;
|
package/lib/environment.js
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,32 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
}
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
5
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.createMachine = exports.doneInvoke = exports.spawn = exports.matchState = exports.Interpreter = exports.interpret = exports.forwardTo = exports.sendUpdate = exports.sendParent = exports.send = exports.assign = exports.actions = exports.mapState = exports.matchesState = exports.State = exports.StateNode = exports.Machine = void 0;
|
|
6
14
|
var utils_1 = require("./utils");
|
|
7
|
-
exports
|
|
15
|
+
Object.defineProperty(exports, "matchesState", { enumerable: true, get: function () { return utils_1.matchesState; } });
|
|
8
16
|
var mapState_1 = require("./mapState");
|
|
9
|
-
exports
|
|
17
|
+
Object.defineProperty(exports, "mapState", { enumerable: true, get: function () { return mapState_1.mapState; } });
|
|
10
18
|
var StateNode_1 = require("./StateNode");
|
|
11
|
-
exports
|
|
19
|
+
Object.defineProperty(exports, "StateNode", { enumerable: true, get: function () { return StateNode_1.StateNode; } });
|
|
12
20
|
var State_1 = require("./State");
|
|
13
|
-
exports
|
|
21
|
+
Object.defineProperty(exports, "State", { enumerable: true, get: function () { return State_1.State; } });
|
|
14
22
|
var Machine_1 = require("./Machine");
|
|
15
|
-
exports
|
|
16
|
-
exports
|
|
23
|
+
Object.defineProperty(exports, "Machine", { enumerable: true, get: function () { return Machine_1.Machine; } });
|
|
24
|
+
Object.defineProperty(exports, "createMachine", { enumerable: true, get: function () { return Machine_1.createMachine; } });
|
|
17
25
|
var actions_1 = require("./actions");
|
|
18
|
-
exports
|
|
19
|
-
exports
|
|
20
|
-
exports
|
|
21
|
-
exports
|
|
22
|
-
exports
|
|
23
|
-
exports
|
|
26
|
+
Object.defineProperty(exports, "send", { enumerable: true, get: function () { return actions_1.send; } });
|
|
27
|
+
Object.defineProperty(exports, "sendParent", { enumerable: true, get: function () { return actions_1.sendParent; } });
|
|
28
|
+
Object.defineProperty(exports, "sendUpdate", { enumerable: true, get: function () { return actions_1.sendUpdate; } });
|
|
29
|
+
Object.defineProperty(exports, "assign", { enumerable: true, get: function () { return actions_1.assign; } });
|
|
30
|
+
Object.defineProperty(exports, "doneInvoke", { enumerable: true, get: function () { return actions_1.doneInvoke; } });
|
|
31
|
+
Object.defineProperty(exports, "forwardTo", { enumerable: true, get: function () { return actions_1.forwardTo; } });
|
|
24
32
|
var interpreter_1 = require("./interpreter");
|
|
25
|
-
exports
|
|
26
|
-
exports
|
|
27
|
-
exports
|
|
33
|
+
Object.defineProperty(exports, "interpret", { enumerable: true, get: function () { return interpreter_1.interpret; } });
|
|
34
|
+
Object.defineProperty(exports, "Interpreter", { enumerable: true, get: function () { return interpreter_1.Interpreter; } });
|
|
35
|
+
Object.defineProperty(exports, "spawn", { enumerable: true, get: function () { return interpreter_1.spawn; } });
|
|
28
36
|
var match_1 = require("./match");
|
|
29
|
-
exports
|
|
37
|
+
Object.defineProperty(exports, "matchState", { enumerable: true, get: function () { return match_1.matchState; } });
|
|
30
38
|
var actions = {
|
|
31
39
|
raise: actions_1.raise,
|
|
32
40
|
send: actions_1.send,
|
|
@@ -46,4 +54,4 @@ var actions = {
|
|
|
46
54
|
pure: actions_1.pure
|
|
47
55
|
};
|
|
48
56
|
exports.actions = actions;
|
|
49
|
-
|
|
57
|
+
__exportStar(require("./types"), exports);
|
package/lib/interpreter.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StateMachine, Event, EventObject, DefaultContext, StateSchema, StateValue, InterpreterOptions, DoneEvent, Unsubscribable, MachineOptions, SCXML, EventData, Observer, Spawnable, Typestate } from './types';
|
|
1
|
+
import { StateMachine, Event, EventObject, DefaultContext, StateSchema, StateValue, InterpreterOptions, SingleOrArray, DoneEvent, Unsubscribable, MachineOptions, SCXML, EventData, Observer, Spawnable, Typestate } from './types';
|
|
2
2
|
import { State } from './State';
|
|
3
3
|
import { Actor } from './Actor';
|
|
4
4
|
export declare type StateListener<TContext, TEvent extends EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
|
|
@@ -137,7 +137,7 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
137
137
|
*
|
|
138
138
|
* @param event The event(s) to send
|
|
139
139
|
*/
|
|
140
|
-
send: (event:
|
|
140
|
+
send: (event: SingleOrArray<Event<TEvent>> | SCXML.Event<TEvent>, payload?: EventData | undefined) => State<TContext, TEvent, TStateSchema, TTypestate>;
|
|
141
141
|
private batch;
|
|
142
142
|
/**
|
|
143
143
|
* Returns a send function bound to this interpreter instance.
|