xstate 4.14.0 → 4.15.2
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 +61 -0
- package/dist/xstate.interpreter.js +1 -1
- package/dist/xstate.js +1 -1
- package/dist/xstate.web.js +2 -2
- package/es/Actor.d.ts +3 -1
- package/es/Actor.js +5 -1
- package/es/State.d.ts +2 -3
- package/es/StateNode.js +0 -1
- package/es/devTools.d.ts +9 -0
- package/es/devTools.js +2 -4
- package/es/interpreter.d.ts +9 -8
- package/es/interpreter.js +59 -55
- package/es/types.d.ts +25 -13
- package/es/utils.d.ts +2 -1
- package/es/utils.js +21 -1
- package/lib/Actor.d.ts +3 -1
- package/lib/Actor.js +5 -1
- package/lib/State.d.ts +2 -3
- package/lib/StateNode.js +0 -1
- package/lib/actions.js +8 -4
- package/lib/devTools.d.ts +9 -0
- package/lib/devTools.js +2 -3
- package/lib/interpreter.d.ts +9 -8
- package/lib/interpreter.js +41 -38
- package/lib/serviceScope.js +4 -2
- package/lib/stateUtils.js +2 -1
- package/lib/types.d.ts +25 -13
- package/lib/utils.d.ts +2 -1
- package/lib/utils.js +15 -2
- package/package.json +2 -2
package/es/types.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { StateNode } from './StateNode';
|
|
2
2
|
import { State } from './State';
|
|
3
3
|
import { Interpreter, Clock } from './interpreter';
|
|
4
|
-
import { Actor } from './Actor';
|
|
5
4
|
export declare type EventType = string;
|
|
6
5
|
export declare type ActionType = string;
|
|
7
6
|
export declare type MetaObject = Record<string, any>;
|
|
@@ -223,7 +222,7 @@ export interface InvokeSourceDefinition {
|
|
|
223
222
|
[key: string]: any;
|
|
224
223
|
type: string;
|
|
225
224
|
}
|
|
226
|
-
export
|
|
225
|
+
export interface InvokeConfig<TContext, TEvent extends EventObject> {
|
|
227
226
|
/**
|
|
228
227
|
* The unique identifier for the invoked machine. If not specified, this
|
|
229
228
|
* will be the machine's own `id`, or the URL (from `src`).
|
|
@@ -260,7 +259,7 @@ export declare type InvokeConfig<TContext, TEvent extends EventObject> = {
|
|
|
260
259
|
* The transition to take upon the invoked child machine sending an error event.
|
|
261
260
|
*/
|
|
262
261
|
onError?: string | SingleOrArray<TransitionConfig<TContext, DoneInvokeEvent<any>>>;
|
|
263
|
-
}
|
|
262
|
+
}
|
|
264
263
|
export interface StateNodeConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject> {
|
|
265
264
|
/**
|
|
266
265
|
* The relative key of the state node, which represents its location in the overall state value.
|
|
@@ -575,13 +574,13 @@ export interface LogActionObject<TContext, TEvent extends EventObject> extends L
|
|
|
575
574
|
value: any;
|
|
576
575
|
}
|
|
577
576
|
export interface SendAction<TContext, TEvent extends EventObject, TSentEvent extends EventObject> extends ActionObject<TContext, TEvent> {
|
|
578
|
-
to: string | number |
|
|
577
|
+
to: string | number | ActorRef<any> | ExprWithMeta<TContext, TEvent, string | number | ActorRef<any>> | undefined;
|
|
579
578
|
event: TSentEvent | SendExpr<TContext, TEvent, TSentEvent>;
|
|
580
579
|
delay?: number | string | DelayExpr<TContext, TEvent>;
|
|
581
580
|
id: string | number;
|
|
582
581
|
}
|
|
583
582
|
export interface SendActionObject<TContext, TEvent extends EventObject, TSentEvent extends EventObject = AnyEventObject> extends SendAction<TContext, TEvent, TSentEvent> {
|
|
584
|
-
to: string | number |
|
|
583
|
+
to: string | number | ActorRef<any> | undefined;
|
|
585
584
|
_event: SCXML.Event<TSentEvent>;
|
|
586
585
|
event: TSentEvent;
|
|
587
586
|
delay?: number;
|
|
@@ -611,7 +610,7 @@ export declare enum SpecialTargets {
|
|
|
611
610
|
export interface SendActionOptions<TContext, TEvent extends EventObject> {
|
|
612
611
|
id?: string | number;
|
|
613
612
|
delay?: number | string | DelayExpr<TContext, TEvent>;
|
|
614
|
-
to?: string | ExprWithMeta<TContext, TEvent, string | number |
|
|
613
|
+
to?: string | ExprWithMeta<TContext, TEvent, string | number | ActorRef<any>>;
|
|
615
614
|
}
|
|
616
615
|
export interface CancelAction extends ActionObject<any, any> {
|
|
617
616
|
sendId: string | number;
|
|
@@ -652,6 +651,7 @@ export interface TransitionDefinition<TContext, TEvent extends EventObject> exte
|
|
|
652
651
|
actions: Array<ActionObject<TContext, TEvent>>;
|
|
653
652
|
cond?: Guard<TContext, TEvent>;
|
|
654
653
|
eventType: TEvent['type'] | NullEvent['type'] | '*';
|
|
654
|
+
meta?: Record<string, any>;
|
|
655
655
|
};
|
|
656
656
|
}
|
|
657
657
|
export declare type TransitionDefinitionMap<TContext, TEvent extends EventObject> = {
|
|
@@ -741,7 +741,7 @@ export interface StateConfig<TContext, TEvent extends EventObject> {
|
|
|
741
741
|
events?: TEvent[];
|
|
742
742
|
configuration: Array<StateNode<TContext, any, TEvent>>;
|
|
743
743
|
transitions: Array<TransitionDefinition<TContext, TEvent>>;
|
|
744
|
-
children: Record<string,
|
|
744
|
+
children: Record<string, ActorRef<any>>;
|
|
745
745
|
done?: boolean;
|
|
746
746
|
}
|
|
747
747
|
export interface StateSchema<TC = any> {
|
|
@@ -841,17 +841,29 @@ export declare namespace SCXML {
|
|
|
841
841
|
$$type: 'scxml';
|
|
842
842
|
}
|
|
843
843
|
}
|
|
844
|
-
export interface Unsubscribable {
|
|
845
|
-
unsubscribe(): void;
|
|
846
|
-
}
|
|
847
|
-
export interface Subscribable<T> {
|
|
848
|
-
subscribe(next?: (value: T) => void, error?: (error: any) => void, complete?: () => void): Unsubscribable;
|
|
849
|
-
}
|
|
850
844
|
export interface Observer<T> {
|
|
851
845
|
next: (value: T) => void;
|
|
852
846
|
error: (err: any) => void;
|
|
853
847
|
complete: () => void;
|
|
854
848
|
}
|
|
849
|
+
export interface Subscription {
|
|
850
|
+
unsubscribe(): void;
|
|
851
|
+
}
|
|
852
|
+
export interface Subscribable<T> {
|
|
853
|
+
subscribe(observer: Observer<T>): Subscription;
|
|
854
|
+
subscribe(next: (value: T) => void, error?: (error: any) => void, complete?: () => void): Subscription;
|
|
855
|
+
}
|
|
855
856
|
export declare type Spawnable = StateMachine<any, any, any> | Promise<any> | InvokeCallback | Subscribable<any>;
|
|
857
|
+
export interface ActorRef<TEvent extends EventObject, TEmitted = any> extends Subscribable<TEmitted> {
|
|
858
|
+
send: Sender<TEvent>;
|
|
859
|
+
}
|
|
860
|
+
export interface SpawnedActorRef<TEvent extends EventObject, TEmitted = any> extends ActorRef<TEvent, TEmitted> {
|
|
861
|
+
id: string;
|
|
862
|
+
stop?: () => void;
|
|
863
|
+
toJSON?: () => any;
|
|
864
|
+
}
|
|
865
|
+
export declare type ActorRefFrom<T extends StateMachine<any, any, any>> = T extends StateMachine<infer TContext, any, infer TEvent, infer TTypestate> ? SpawnedActorRef<TEvent, State<TContext, TEvent, any, TTypestate>> & {
|
|
866
|
+
state: State<TContext, TEvent, any, TTypestate>;
|
|
867
|
+
} : never;
|
|
856
868
|
export {};
|
|
857
869
|
//# sourceMappingURL=types.d.ts.map
|
package/es/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Event, StateValue, ActionType, Action, EventObject, PropertyMapper, Mapper, EventType, HistoryValue, AssignAction, Condition, Subscribable, StateMachine, ConditionPredicate, SCXML, StateLike, EventData, TransitionConfig, TransitionConfigTarget, NullEvent, SingleOrArray, Guard, InvokeSourceDefinition } from './types';
|
|
2
2
|
import { StateNode } from './StateNode';
|
|
3
|
-
import { State } from '.';
|
|
3
|
+
import { Observer, State } from '.';
|
|
4
4
|
import { Actor } from './Actor';
|
|
5
5
|
export declare function keys<T extends object>(value: T): Array<keyof T & string>;
|
|
6
6
|
export declare function matchesState(parentStateId: StateValue, childStateId: StateValue, delimiter?: string): boolean;
|
|
@@ -66,4 +66,5 @@ export declare function normalizeTarget<TContext, TEvent extends EventObject>(ta
|
|
|
66
66
|
export declare function reportUnhandledExceptionOnInvocation(originalError: any, currentError: any, id: string): void;
|
|
67
67
|
export declare function evaluateGuard<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent>, guard: Guard<TContext, TEvent>, context: TContext, _event: SCXML.Event<TEvent>, state: State<TContext, TEvent>): boolean;
|
|
68
68
|
export declare function toInvokeSource(src: string | InvokeSourceDefinition): InvokeSourceDefinition;
|
|
69
|
+
export declare function toObserver<T>(nextHandler: Observer<T> | ((value: T) => void), errorHandler?: (error: any) => void, completionHandler?: () => void): Observer<T>;
|
|
69
70
|
//# sourceMappingURL=utils.d.ts.map
|
package/es/utils.js
CHANGED
|
@@ -494,6 +494,10 @@ function isMachine(value) {
|
|
|
494
494
|
}
|
|
495
495
|
}
|
|
496
496
|
|
|
497
|
+
function isActor(value) {
|
|
498
|
+
return !!value && typeof value.send === 'function';
|
|
499
|
+
}
|
|
500
|
+
|
|
497
501
|
var uniqueId = /*#__PURE__*/function () {
|
|
498
502
|
var currentId = 0;
|
|
499
503
|
return function () {
|
|
@@ -597,4 +601,20 @@ function toInvokeSource(src) {
|
|
|
597
601
|
return src;
|
|
598
602
|
}
|
|
599
603
|
|
|
600
|
-
|
|
604
|
+
function toObserver(nextHandler, errorHandler, completionHandler) {
|
|
605
|
+
if (typeof nextHandler === 'object') {
|
|
606
|
+
return nextHandler;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
var noop = function () {
|
|
610
|
+
return void 0;
|
|
611
|
+
};
|
|
612
|
+
|
|
613
|
+
return {
|
|
614
|
+
next: nextHandler,
|
|
615
|
+
error: errorHandler || noop,
|
|
616
|
+
complete: completionHandler || noop
|
|
617
|
+
};
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
export { evaluateGuard, flatten, getEventType, isActor, isArray, isBuiltInEvent, isFunction, isMachine, isObservable, isPromiseLike, isStateLike, isString, keys, mapContext, mapFilterValues, mapValues, matchesState, nestedPath, normalizeTarget, partition, path, pathToStateValue, reportUnhandledExceptionOnInvocation, symbolObservable, toArray, toArrayStrict, toEventObject, toGuard, toInvokeSource, toObserver, toSCXMLEvent, toStatePath, toStatePaths, toStateValue, toTransitionConfigArray, uniqueId, updateContext, updateHistoryStates, updateHistoryValue, warn };
|
package/lib/Actor.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EventObject, Subscribable, InvokeDefinition, AnyEventObject, StateMachine, Spawnable, SCXML } from './types';
|
|
2
|
+
import { ActorRef, SpawnedActorRef } from '.';
|
|
2
3
|
export interface Actor<TContext = any, TEvent extends EventObject = AnyEventObject> extends Subscribable<TContext> {
|
|
3
4
|
id: string;
|
|
4
5
|
send: (event: TEvent) => any;
|
|
@@ -19,5 +20,6 @@ export declare function createNullActor(id: string): Actor;
|
|
|
19
20
|
*/
|
|
20
21
|
export declare function createInvocableActor<TC, TE extends EventObject>(invokeDefinition: InvokeDefinition<TC, TE>, machine: StateMachine<TC, any, TE>, context: TC, _event: SCXML.Event<TE>): Actor;
|
|
21
22
|
export declare function createDeferredActor(entity: Spawnable, id: string, data?: any): Actor;
|
|
22
|
-
export declare function isActor(item: any): item is
|
|
23
|
+
export declare function isActor(item: any): item is ActorRef<any>;
|
|
24
|
+
export declare function isSpawnedActor(item: any): item is SpawnedActorRef<any>;
|
|
23
25
|
//# sourceMappingURL=Actor.d.ts.map
|
package/lib/Actor.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isActor = exports.createDeferredActor = exports.createInvocableActor = exports.createNullActor = void 0;
|
|
3
|
+
exports.isSpawnedActor = exports.isActor = exports.createDeferredActor = exports.createInvocableActor = exports.createNullActor = void 0;
|
|
4
4
|
var utils_1 = require("./utils");
|
|
5
5
|
var serviceScope = require("./serviceScope");
|
|
6
6
|
function createNullActor(id) {
|
|
@@ -55,3 +55,7 @@ function isActor(item) {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
exports.isActor = isActor;
|
|
58
|
+
function isSpawnedActor(item) {
|
|
59
|
+
return isActor(item) && 'id' in item;
|
|
60
|
+
}
|
|
61
|
+
exports.isSpawnedActor = isSpawnedActor;
|
package/lib/State.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { StateValue, ActivityMap, EventObject, HistoryValue, ActionObject, EventType, StateConfig, SCXML, StateSchema, TransitionDefinition, Typestate } from './types';
|
|
1
|
+
import { StateValue, ActivityMap, EventObject, HistoryValue, ActionObject, EventType, StateConfig, SCXML, StateSchema, TransitionDefinition, Typestate, ActorRef } from './types';
|
|
2
2
|
import { StateNode } from './StateNode';
|
|
3
|
-
import { Actor } from './Actor';
|
|
4
3
|
export declare function stateValuesEqual(a: StateValue | undefined, b: StateValue | undefined): boolean;
|
|
5
4
|
export declare function isState<TContext, TEvent extends EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
|
|
6
5
|
value: any;
|
|
@@ -50,7 +49,7 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
|
|
|
50
49
|
/**
|
|
51
50
|
* An object mapping actor IDs to spawned actors/invoked services.
|
|
52
51
|
*/
|
|
53
|
-
children: Record<string,
|
|
52
|
+
children: Record<string, ActorRef<any>>;
|
|
54
53
|
/**
|
|
55
54
|
* Creates a new State instance for the given `stateValue` and `context`.
|
|
56
55
|
* @param stateValue
|
package/lib/StateNode.js
CHANGED
|
@@ -883,7 +883,6 @@ var StateNode = /** @class */ (function () {
|
|
|
883
883
|
: undefined);
|
|
884
884
|
maybeNextState.changed = changed;
|
|
885
885
|
// Preserve original history after raised events
|
|
886
|
-
maybeNextState.historyValue = nextState.historyValue;
|
|
887
886
|
maybeNextState.history = history;
|
|
888
887
|
return maybeNextState;
|
|
889
888
|
};
|
package/lib/actions.js
CHANGED
|
@@ -85,7 +85,7 @@ function toActionObject(action, actionFunctionMap) {
|
|
|
85
85
|
return actionObject;
|
|
86
86
|
}
|
|
87
87
|
exports.toActionObject = toActionObject;
|
|
88
|
-
|
|
88
|
+
var toActionObjects = function (action, actionFunctionMap) {
|
|
89
89
|
if (!action) {
|
|
90
90
|
return [];
|
|
91
91
|
}
|
|
@@ -94,6 +94,7 @@ exports.toActionObjects = function (action, actionFunctionMap) {
|
|
|
94
94
|
return toActionObject(subAction, actionFunctionMap);
|
|
95
95
|
});
|
|
96
96
|
};
|
|
97
|
+
exports.toActionObjects = toActionObjects;
|
|
97
98
|
function toActivityDefinition(action) {
|
|
98
99
|
var actionObject = toActionObject(action);
|
|
99
100
|
return __assign(__assign({ id: utils_1.isString(action) ? action : actionObject.id }, actionObject), { type: actionObject.type });
|
|
@@ -223,11 +224,12 @@ function log(expr, label) {
|
|
|
223
224
|
};
|
|
224
225
|
}
|
|
225
226
|
exports.log = log;
|
|
226
|
-
|
|
227
|
+
var resolveLog = function (action, ctx, _event) { return (__assign(__assign({}, action), { value: utils_1.isString(action.expr)
|
|
227
228
|
? action.expr
|
|
228
229
|
: action.expr(ctx, _event.data, {
|
|
229
230
|
_event: _event
|
|
230
231
|
}) })); };
|
|
232
|
+
exports.resolveLog = resolveLog;
|
|
231
233
|
/**
|
|
232
234
|
* Cancels an in-flight `send(...)` action. A canceled sent action will not
|
|
233
235
|
* be executed, nor will its event be sent, unless it has already been sent
|
|
@@ -235,12 +237,13 @@ exports.resolveLog = function (action, ctx, _event) { return (__assign(__assign(
|
|
|
235
237
|
*
|
|
236
238
|
* @param sendId The `id` of the `send(...)` action to cancel.
|
|
237
239
|
*/
|
|
238
|
-
|
|
240
|
+
var cancel = function (sendId) {
|
|
239
241
|
return {
|
|
240
242
|
type: actionTypes.cancel,
|
|
241
243
|
sendId: sendId
|
|
242
244
|
};
|
|
243
245
|
};
|
|
246
|
+
exports.cancel = cancel;
|
|
244
247
|
/**
|
|
245
248
|
* Starts an activity.
|
|
246
249
|
*
|
|
@@ -290,12 +293,13 @@ exports.resolveStop = resolveStop;
|
|
|
290
293
|
*
|
|
291
294
|
* @param assignment An object that represents the partial context to update.
|
|
292
295
|
*/
|
|
293
|
-
|
|
296
|
+
var assign = function (assignment) {
|
|
294
297
|
return {
|
|
295
298
|
type: actionTypes.assign,
|
|
296
299
|
assignment: assignment
|
|
297
300
|
};
|
|
298
301
|
};
|
|
302
|
+
exports.assign = assign;
|
|
299
303
|
function isActionObject(action) {
|
|
300
304
|
return typeof action === 'object' && 'type' in action;
|
|
301
305
|
}
|
package/lib/devTools.d.ts
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { Interpreter } from '.';
|
|
2
2
|
declare type AnyInterpreter = Interpreter<any, any, any>;
|
|
3
|
+
declare type ServiceListener = (service: AnyInterpreter) => void;
|
|
4
|
+
export interface XStateDevInterface {
|
|
5
|
+
register: (service: Interpreter<any>) => void;
|
|
6
|
+
unregister: (service: Interpreter<any>) => void;
|
|
7
|
+
onRegister: (listener: ServiceListener) => {
|
|
8
|
+
unsubscribe: () => void;
|
|
9
|
+
};
|
|
10
|
+
services: Set<Interpreter<any>>;
|
|
11
|
+
}
|
|
3
12
|
export declare function registerService(service: AnyInterpreter): void;
|
|
4
13
|
export {};
|
|
5
14
|
//# sourceMappingURL=devTools.d.ts.map
|
package/lib/devTools.js
CHANGED
|
@@ -3,9 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.registerService = void 0;
|
|
4
4
|
var environment_1 = require("./environment");
|
|
5
5
|
function getDevTools() {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return w.__xstate__;
|
|
6
|
+
if (!!window.__xstate__) {
|
|
7
|
+
return window.__xstate__;
|
|
9
8
|
}
|
|
10
9
|
return undefined;
|
|
11
10
|
}
|
package/lib/interpreter.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { StateMachine, Event, EventObject, DefaultContext, StateSchema, StateValue, InterpreterOptions, SingleOrArray, DoneEvent,
|
|
1
|
+
import { StateMachine, Event, EventObject, DefaultContext, StateSchema, StateValue, InterpreterOptions, SingleOrArray, DoneEvent, MachineOptions, SCXML, EventData, Observer, Spawnable, Typestate } from './types';
|
|
2
2
|
import { State } from './State';
|
|
3
3
|
import { Actor } from './Actor';
|
|
4
|
+
import { ActorRefFrom, SpawnedActorRef, Subscription } from '.';
|
|
4
5
|
export declare type StateListener<TContext, TEvent extends EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
|
|
5
6
|
value: any;
|
|
6
7
|
context: TContext;
|
|
@@ -64,7 +65,7 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
64
65
|
* The globally unique process ID for this invocation.
|
|
65
66
|
*/
|
|
66
67
|
sessionId: string;
|
|
67
|
-
children: Map<string | number,
|
|
68
|
+
children: Map<string | number, SpawnedActorRef<any>>;
|
|
68
69
|
private forwardTo;
|
|
69
70
|
private devTools?;
|
|
70
71
|
/**
|
|
@@ -86,8 +87,8 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
86
87
|
execute(state: State<TContext, TEvent, TStateSchema, TTypestate>, actionsConfig?: MachineOptions<TContext, TEvent>['actions']): void;
|
|
87
88
|
private update;
|
|
88
89
|
onTransition(listener: StateListener<TContext, TEvent, TStateSchema, TTypestate>): this;
|
|
89
|
-
subscribe(observer: Observer<State<TContext, TEvent, any, TTypestate>>):
|
|
90
|
-
subscribe(nextListener?: (state: State<TContext, TEvent, any, TTypestate>) => void, errorListener?: (error: any) => void, completeListener?: () => void):
|
|
90
|
+
subscribe(observer: Observer<State<TContext, TEvent, any, TTypestate>>): Subscription;
|
|
91
|
+
subscribe(nextListener?: (state: State<TContext, TEvent, any, TTypestate>) => void, errorListener?: (error: any) => void, completeListener?: () => void): Subscription;
|
|
91
92
|
/**
|
|
92
93
|
* Adds an event listener that is notified whenever an event is sent to the running interpreter.
|
|
93
94
|
* @param listener The event listener
|
|
@@ -165,12 +166,12 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
165
166
|
private exec;
|
|
166
167
|
private removeChild;
|
|
167
168
|
private stopChild;
|
|
168
|
-
spawn(entity: Spawnable, name: string, options?: SpawnOptions):
|
|
169
|
+
spawn(entity: Spawnable, name: string, options?: SpawnOptions): SpawnedActorRef<any>;
|
|
169
170
|
spawnMachine<TChildContext, TChildStateSchema, TChildEvent extends EventObject>(machine: StateMachine<TChildContext, TChildStateSchema, TChildEvent>, options?: {
|
|
170
171
|
id?: string;
|
|
171
172
|
autoForward?: boolean;
|
|
172
173
|
sync?: boolean;
|
|
173
|
-
}):
|
|
174
|
+
}): SpawnedActorRef<TChildEvent, State<TChildContext, TChildEvent>>;
|
|
174
175
|
private spawnPromise;
|
|
175
176
|
private spawnCallback;
|
|
176
177
|
private spawnObservable;
|
|
@@ -182,8 +183,8 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
182
183
|
id: string;
|
|
183
184
|
};
|
|
184
185
|
}
|
|
185
|
-
export declare function spawn<TC, TE extends EventObject>(entity: StateMachine<TC, any, TE>, nameOrOptions?: string | SpawnOptions):
|
|
186
|
-
export declare function spawn(entity: Spawnable, nameOrOptions?: string | SpawnOptions):
|
|
186
|
+
export declare function spawn<TC, TE extends EventObject>(entity: StateMachine<TC, any, TE>, nameOrOptions?: string | SpawnOptions): ActorRefFrom<StateMachine<TC, any, TE>>;
|
|
187
|
+
export declare function spawn(entity: Spawnable, nameOrOptions?: string | SpawnOptions): SpawnedActorRef<any>;
|
|
187
188
|
/**
|
|
188
189
|
* Creates a new Interpreter instance for the given machine with the provided options, if any.
|
|
189
190
|
*
|
package/lib/interpreter.js
CHANGED
|
@@ -131,9 +131,11 @@ var Interpreter = /** @class */ (function () {
|
|
|
131
131
|
var isParent = _this.parent && (to === types_1.SpecialTargets.Parent || _this.parent.id === to);
|
|
132
132
|
var target = isParent
|
|
133
133
|
? _this.parent
|
|
134
|
-
:
|
|
135
|
-
? to
|
|
136
|
-
:
|
|
134
|
+
: utils_1.isString(to)
|
|
135
|
+
? _this.children.get(to) || registry_1.registry.get(to)
|
|
136
|
+
: utils_1.isActor(to)
|
|
137
|
+
? to
|
|
138
|
+
: undefined;
|
|
137
139
|
if (!target) {
|
|
138
140
|
if (!isParent) {
|
|
139
141
|
throw new Error("Unable to send event to child '" + to + "' from service '" + _this.id + "'.");
|
|
@@ -275,23 +277,6 @@ var Interpreter = /** @class */ (function () {
|
|
|
275
277
|
}
|
|
276
278
|
var isDone = stateUtils_1.isInFinalState(state.configuration || [], this.machine);
|
|
277
279
|
if (this.state.configuration && isDone) {
|
|
278
|
-
// exit interpreter procedure: https://www.w3.org/TR/scxml/#exitInterpreter
|
|
279
|
-
this.state.configuration.forEach(function (stateNode) {
|
|
280
|
-
var e_6, _a;
|
|
281
|
-
try {
|
|
282
|
-
for (var _b = __values(stateNode.definition.exit), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
283
|
-
var action = _c.value;
|
|
284
|
-
_this.exec(action, state);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
288
|
-
finally {
|
|
289
|
-
try {
|
|
290
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
291
|
-
}
|
|
292
|
-
finally { if (e_6) throw e_6.error; }
|
|
293
|
-
}
|
|
294
|
-
});
|
|
295
280
|
// get final child state node
|
|
296
281
|
var finalChildStateNode = state.configuration.find(function (sn) { return sn.type === 'final' && sn.parent === _this.machine; });
|
|
297
282
|
var doneData = finalChildStateNode && finalChildStateNode.doneData
|
|
@@ -445,19 +430,20 @@ var Interpreter = /** @class */ (function () {
|
|
|
445
430
|
* This will also notify the `onStop` listeners.
|
|
446
431
|
*/
|
|
447
432
|
Interpreter.prototype.stop = function () {
|
|
448
|
-
var
|
|
433
|
+
var e_6, _a, e_7, _b, e_8, _c, e_9, _d, e_10, _e;
|
|
434
|
+
var _this = this;
|
|
449
435
|
try {
|
|
450
436
|
for (var _f = __values(this.listeners), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
451
437
|
var listener = _g.value;
|
|
452
438
|
this.listeners.delete(listener);
|
|
453
439
|
}
|
|
454
440
|
}
|
|
455
|
-
catch (
|
|
441
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
456
442
|
finally {
|
|
457
443
|
try {
|
|
458
444
|
if (_g && !_g.done && (_a = _f.return)) _a.call(_f);
|
|
459
445
|
}
|
|
460
|
-
finally { if (
|
|
446
|
+
finally { if (e_6) throw e_6.error; }
|
|
461
447
|
}
|
|
462
448
|
try {
|
|
463
449
|
for (var _h = __values(this.stopListeners), _j = _h.next(); !_j.done; _j = _h.next()) {
|
|
@@ -467,12 +453,12 @@ var Interpreter = /** @class */ (function () {
|
|
|
467
453
|
this.stopListeners.delete(listener);
|
|
468
454
|
}
|
|
469
455
|
}
|
|
470
|
-
catch (
|
|
456
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
471
457
|
finally {
|
|
472
458
|
try {
|
|
473
459
|
if (_j && !_j.done && (_b = _h.return)) _b.call(_h);
|
|
474
460
|
}
|
|
475
|
-
finally { if (
|
|
461
|
+
finally { if (e_7) throw e_7.error; }
|
|
476
462
|
}
|
|
477
463
|
try {
|
|
478
464
|
for (var _k = __values(this.contextListeners), _l = _k.next(); !_l.done; _l = _k.next()) {
|
|
@@ -480,12 +466,12 @@ var Interpreter = /** @class */ (function () {
|
|
|
480
466
|
this.contextListeners.delete(listener);
|
|
481
467
|
}
|
|
482
468
|
}
|
|
483
|
-
catch (
|
|
469
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
484
470
|
finally {
|
|
485
471
|
try {
|
|
486
472
|
if (_l && !_l.done && (_c = _k.return)) _c.call(_k);
|
|
487
473
|
}
|
|
488
|
-
finally { if (
|
|
474
|
+
finally { if (e_8) throw e_8.error; }
|
|
489
475
|
}
|
|
490
476
|
try {
|
|
491
477
|
for (var _m = __values(this.doneListeners), _o = _m.next(); !_o.done; _o = _m.next()) {
|
|
@@ -493,13 +479,29 @@ var Interpreter = /** @class */ (function () {
|
|
|
493
479
|
this.doneListeners.delete(listener);
|
|
494
480
|
}
|
|
495
481
|
}
|
|
496
|
-
catch (
|
|
482
|
+
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
497
483
|
finally {
|
|
498
484
|
try {
|
|
499
485
|
if (_o && !_o.done && (_d = _m.return)) _d.call(_m);
|
|
500
486
|
}
|
|
501
|
-
finally { if (
|
|
487
|
+
finally { if (e_9) throw e_9.error; }
|
|
502
488
|
}
|
|
489
|
+
this.state.configuration.forEach(function (stateNode) {
|
|
490
|
+
var e_11, _a;
|
|
491
|
+
try {
|
|
492
|
+
for (var _b = __values(stateNode.definition.exit), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
493
|
+
var action = _c.value;
|
|
494
|
+
_this.exec(action, _this.state);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
catch (e_11_1) { e_11 = { error: e_11_1 }; }
|
|
498
|
+
finally {
|
|
499
|
+
try {
|
|
500
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
501
|
+
}
|
|
502
|
+
finally { if (e_11) throw e_11.error; }
|
|
503
|
+
}
|
|
504
|
+
});
|
|
503
505
|
// Stop all children
|
|
504
506
|
this.children.forEach(function (child) {
|
|
505
507
|
if (utils_1.isFunction(child.stop)) {
|
|
@@ -513,12 +515,12 @@ var Interpreter = /** @class */ (function () {
|
|
|
513
515
|
this.clock.clearTimeout(this.delayedEventsMap[key]);
|
|
514
516
|
}
|
|
515
517
|
}
|
|
516
|
-
catch (
|
|
518
|
+
catch (e_10_1) { e_10 = { error: e_10_1 }; }
|
|
517
519
|
finally {
|
|
518
520
|
try {
|
|
519
521
|
if (_q && !_q.done && (_e = _p.return)) _e.call(_p);
|
|
520
522
|
}
|
|
521
|
-
finally { if (
|
|
523
|
+
finally { if (e_10) throw e_10.error; }
|
|
522
524
|
}
|
|
523
525
|
this.scheduler.clear();
|
|
524
526
|
this.initialized = false;
|
|
@@ -792,7 +794,7 @@ var Interpreter = /** @class */ (function () {
|
|
|
792
794
|
else if (utils_1.isFunction(entity)) {
|
|
793
795
|
return this.spawnCallback(entity, name);
|
|
794
796
|
}
|
|
795
|
-
else if (Actor_1.
|
|
797
|
+
else if (Actor_1.isSpawnedActor(entity)) {
|
|
796
798
|
return this.spawnActor(entity);
|
|
797
799
|
}
|
|
798
800
|
else if (utils_1.isObservable(entity)) {
|
|
@@ -866,21 +868,22 @@ var Interpreter = /** @class */ (function () {
|
|
|
866
868
|
id: id,
|
|
867
869
|
send: function () { return void 0; },
|
|
868
870
|
subscribe: function (next, handleError, complete) {
|
|
871
|
+
var observer = utils_1.toObserver(next, handleError, complete);
|
|
869
872
|
var unsubscribed = false;
|
|
870
873
|
promise.then(function (response) {
|
|
871
874
|
if (unsubscribed) {
|
|
872
875
|
return;
|
|
873
876
|
}
|
|
874
|
-
next
|
|
877
|
+
observer.next(response);
|
|
875
878
|
if (unsubscribed) {
|
|
876
879
|
return;
|
|
877
880
|
}
|
|
878
|
-
complete
|
|
881
|
+
observer.complete();
|
|
879
882
|
}, function (err) {
|
|
880
883
|
if (unsubscribed) {
|
|
881
884
|
return;
|
|
882
885
|
}
|
|
883
|
-
|
|
886
|
+
observer.error(err);
|
|
884
887
|
});
|
|
885
888
|
return {
|
|
886
889
|
unsubscribe: function () { return (unsubscribed = true); }
|
|
@@ -906,7 +909,7 @@ var Interpreter = /** @class */ (function () {
|
|
|
906
909
|
if (canceled) {
|
|
907
910
|
return;
|
|
908
911
|
}
|
|
909
|
-
_this.send(e);
|
|
912
|
+
_this.send(utils_1.toSCXMLEvent(e, { origin: id }));
|
|
910
913
|
};
|
|
911
914
|
var callbackStop;
|
|
912
915
|
try {
|
|
@@ -1043,10 +1046,10 @@ var Interpreter = /** @class */ (function () {
|
|
|
1043
1046
|
deferEvents: true,
|
|
1044
1047
|
clock: {
|
|
1045
1048
|
setTimeout: function (fn, ms) {
|
|
1046
|
-
return
|
|
1049
|
+
return setTimeout(fn, ms);
|
|
1047
1050
|
},
|
|
1048
1051
|
clearTimeout: function (id) {
|
|
1049
|
-
return
|
|
1052
|
+
return clearTimeout(id);
|
|
1050
1053
|
}
|
|
1051
1054
|
},
|
|
1052
1055
|
logger: global.console.log.bind(console),
|
package/lib/serviceScope.js
CHANGED
|
@@ -6,10 +6,12 @@ exports.consume = exports.provide = void 0;
|
|
|
6
6
|
* This is used to provide the correct service to spawn().
|
|
7
7
|
*/
|
|
8
8
|
var serviceStack = [];
|
|
9
|
-
|
|
9
|
+
var provide = function (service, fn) {
|
|
10
10
|
serviceStack.push(service);
|
|
11
11
|
var result = fn(service);
|
|
12
12
|
serviceStack.pop();
|
|
13
13
|
return result;
|
|
14
14
|
};
|
|
15
|
-
exports.
|
|
15
|
+
exports.provide = provide;
|
|
16
|
+
var consume = function (fn) { return fn(serviceStack[serviceStack.length - 1]); };
|
|
17
|
+
exports.consume = consume;
|
package/lib/stateUtils.js
CHANGED
|
@@ -33,9 +33,10 @@ var __spread = (this && this.__spread) || function () {
|
|
|
33
33
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
34
|
exports.isInFinalState = exports.nextEvents = exports.has = exports.getValue = exports.getAdjList = exports.getConfiguration = exports.getAllStateNodes = exports.getChildren = exports.isLeafNode = void 0;
|
|
35
35
|
var utils_1 = require("./utils");
|
|
36
|
-
|
|
36
|
+
var isLeafNode = function (stateNode) {
|
|
37
37
|
return stateNode.type === 'atomic' || stateNode.type === 'final';
|
|
38
38
|
};
|
|
39
|
+
exports.isLeafNode = isLeafNode;
|
|
39
40
|
function getChildren(stateNode) {
|
|
40
41
|
return utils_1.keys(stateNode.states).map(function (key) { return stateNode.states[key]; });
|
|
41
42
|
}
|