xstate 4.20.1 → 4.23.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.
- package/CHANGELOG.md +134 -0
- package/dist/xstate.interpreter.js +1 -1
- package/dist/xstate.js +1 -1
- package/dist/xstate.web.js +2 -2
- package/es/Actor.js +17 -5
- package/es/Machine.d.ts +6 -3
- package/es/Machine.js +3 -6
- package/es/State.js +1 -3
- package/es/StateNode.d.ts +4 -3
- package/es/StateNode.js +34 -20
- package/es/_virtual/_tslib.js +59 -73
- package/es/actionTypes.js +3 -2
- package/es/actions.d.ts +1 -1
- package/es/actions.js +51 -37
- package/es/behaviors.d.ts +37 -0
- package/es/behaviors.js +65 -0
- package/es/constants.js +2 -1
- package/es/devTools.js +1 -1
- package/es/environment.js +2 -1
- package/es/index.js +3 -1
- package/es/interpreter.d.ts +10 -3
- package/es/interpreter.js +44 -22
- package/es/invokeUtils.js +4 -3
- package/es/mapState.js +1 -1
- package/es/match.js +1 -1
- package/es/model.d.ts +2 -36
- package/es/model.types.d.ts +37 -0
- package/es/registry.js +2 -1
- package/es/scheduler.js +2 -1
- package/es/schema.js +1 -1
- package/es/serviceScope.js +1 -3
- package/es/stateUtils.js +1 -9
- package/es/types.d.ts +26 -5
- package/es/types.js +1 -1
- package/es/utils.d.ts +3 -2
- package/es/utils.js +4 -40
- package/lib/Actor.d.ts +25 -25
- package/lib/Actor.js +85 -66
- package/lib/Machine.d.ts +17 -14
- package/lib/Machine.js +14 -14
- package/lib/SimulatedClock.d.ts +16 -16
- package/lib/State.d.ts +108 -108
- package/lib/State.js +246 -236
- package/lib/StateNode.d.ts +279 -278
- package/lib/StateNode.js +1535 -1339
- package/lib/_virtual/_tslib.js +81 -0
- package/lib/actionTypes.d.ts +19 -19
- package/lib/actionTypes.js +43 -23
- package/lib/actions.d.ts +138 -138
- package/lib/actions.js +465 -387
- package/lib/behaviors.d.ts +37 -0
- package/lib/behaviors.js +69 -0
- package/lib/constants.d.ts +5 -5
- package/lib/constants.js +13 -7
- package/lib/devTools.d.ts +15 -15
- package/lib/devTools.js +37 -26
- package/lib/each.d.ts +3 -3
- package/lib/environment.d.ts +1 -1
- package/lib/environment.js +7 -4
- package/lib/index.d.ts +30 -30
- package/lib/index.js +67 -57
- package/lib/interpreter.d.ts +205 -198
- package/lib/interpreter.js +1306 -1054
- package/lib/invoke.d.ts +10 -10
- package/lib/invokeUtils.d.ts +6 -6
- package/lib/invokeUtils.js +40 -37
- package/lib/json.d.ts +30 -30
- package/lib/mapState.d.ts +3 -3
- package/lib/mapState.js +31 -32
- package/lib/match.d.ts +8 -8
- package/lib/match.js +33 -47
- package/lib/model.d.ts +4 -38
- package/lib/model.js +5 -1
- package/lib/model.types.d.ts +37 -0
- package/lib/model.types.js +2 -0
- package/lib/patterns.d.ts +13 -13
- package/lib/registry.d.ts +8 -8
- package/lib/registry.js +21 -18
- package/lib/scheduler.d.ts +16 -16
- package/lib/scheduler.js +79 -70
- package/lib/schema.d.ts +1 -1
- package/lib/schema.js +6 -4
- package/lib/scxml.d.ts +5 -5
- package/lib/serviceScope.d.ts +3 -3
- package/lib/serviceScope.js +16 -12
- package/lib/stateUtils.d.ts +14 -14
- package/lib/stateUtils.js +231 -199
- package/lib/types.d.ts +928 -907
- package/lib/types.js +29 -29
- package/lib/utils.d.ts +68 -67
- package/lib/utils.js +530 -529
- package/package.json +6 -6
package/es/match.js
CHANGED
package/es/model.d.ts
CHANGED
|
@@ -1,39 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
declare type Cast<A1 extends any, A2 extends any> = A1 extends A2 ? A1 : A2;
|
|
4
|
-
declare type Compute<A extends any> = {
|
|
5
|
-
[K in keyof A]: A[K];
|
|
6
|
-
} & unknown;
|
|
7
|
-
declare type Prop<T, K> = K extends keyof T ? T[K] : never;
|
|
8
|
-
export interface Model<TContext, TEvent extends EventObject, TModelCreators = void> {
|
|
9
|
-
initialContext: TContext;
|
|
10
|
-
assign: <TEventType extends TEvent['type'] = TEvent['type']>(assigner: Assigner<TContext, ExtractEvent<TEvent, TEventType>> | PropertyAssigner<TContext, ExtractEvent<TEvent, TEventType>>, eventType?: TEventType) => AssignAction<TContext, ExtractEvent<TEvent, TEventType>>;
|
|
11
|
-
events: Prop<TModelCreators, 'events'>;
|
|
12
|
-
reset: () => AssignAction<TContext, any>;
|
|
13
|
-
}
|
|
14
|
-
export declare type ModelContextFrom<TModel extends Model<any, any, any>> = TModel extends Model<infer TContext, any, any> ? TContext : never;
|
|
15
|
-
export declare type ModelEventsFrom<TModel extends Model<any, any, any>> = TModel extends Model<any, infer TEvent, any> ? TEvent : never;
|
|
16
|
-
declare type EventCreator<Self extends AnyFunction, Return = ReturnType<Self>> = Return extends object ? Return extends {
|
|
17
|
-
type: any;
|
|
18
|
-
} ? "An event creator can't return an object with a type property" : Self : 'An event creator must return an object';
|
|
19
|
-
declare type EventCreators<Self> = {
|
|
20
|
-
[K in keyof Self]: Self[K] extends AnyFunction ? EventCreator<Self[K]> : 'An event creator must be a function';
|
|
21
|
-
};
|
|
22
|
-
declare type ModelCreators<Self> = {
|
|
23
|
-
events: EventCreators<Prop<Self, 'events'>>;
|
|
24
|
-
};
|
|
25
|
-
declare type FinalEventCreators<Self> = {
|
|
26
|
-
[K in keyof Self]: Self[K] extends AnyFunction ? (...args: Parameters<Self[K]>) => Compute<ReturnType<Self[K]> & {
|
|
27
|
-
type: K;
|
|
28
|
-
}> : never;
|
|
29
|
-
};
|
|
30
|
-
declare type FinalModelCreators<Self> = {
|
|
31
|
-
events: FinalEventCreators<Prop<Self, 'events'>>;
|
|
32
|
-
};
|
|
33
|
-
declare type EventFromEventCreators<EventCreators> = {
|
|
34
|
-
[K in keyof EventCreators]: EventCreators[K] extends AnyFunction ? ReturnType<EventCreators[K]> : never;
|
|
35
|
-
}[keyof EventCreators];
|
|
1
|
+
import type { EventObject } from './types';
|
|
2
|
+
import { Cast, EventFromEventCreators, FinalModelCreators, Model, ModelCreators, Prop } from './model.types';
|
|
36
3
|
export declare function createModel<TContext, TEvent extends EventObject>(initialContext: TContext): Model<TContext, TEvent, void>;
|
|
37
4
|
export declare function createModel<TContext, TModelCreators extends ModelCreators<TModelCreators>, TFinalModelCreators = FinalModelCreators<TModelCreators>>(initialContext: TContext, creators: TModelCreators): Model<TContext, Cast<EventFromEventCreators<Prop<TFinalModelCreators, 'events'>>, EventObject>, TFinalModelCreators>;
|
|
38
|
-
export {};
|
|
39
5
|
//# sourceMappingURL=model.d.ts.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { EventObject, Assigner, ExtractEvent, PropertyAssigner, AssignAction, MachineConfig, MachineOptions, StateMachine } from './types';
|
|
2
|
+
export declare type AnyFunction = (...args: any[]) => any;
|
|
3
|
+
export declare type Cast<A1 extends any, A2 extends any> = A1 extends A2 ? A1 : A2;
|
|
4
|
+
export declare type Compute<A extends any> = {
|
|
5
|
+
[K in keyof A]: A[K];
|
|
6
|
+
} & unknown;
|
|
7
|
+
export declare type Prop<T, K> = K extends keyof T ? T[K] : never;
|
|
8
|
+
export interface Model<TContext, TEvent extends EventObject, TModelCreators = void> {
|
|
9
|
+
initialContext: TContext;
|
|
10
|
+
assign: <TEventType extends TEvent['type'] = TEvent['type']>(assigner: Assigner<TContext, ExtractEvent<TEvent, TEventType>> | PropertyAssigner<TContext, ExtractEvent<TEvent, TEventType>>, eventType?: TEventType) => AssignAction<TContext, ExtractEvent<TEvent, TEventType>>;
|
|
11
|
+
events: Prop<TModelCreators, 'events'>;
|
|
12
|
+
reset: () => AssignAction<TContext, any>;
|
|
13
|
+
createMachine: (config: MachineConfig<TContext, any, TEvent>, implementations?: Partial<MachineOptions<TContext, TEvent>>) => StateMachine<TContext, any, TEvent>;
|
|
14
|
+
}
|
|
15
|
+
export declare type ModelContextFrom<TModel extends Model<any, any, any>> = TModel extends Model<infer TContext, any, any> ? TContext : never;
|
|
16
|
+
export declare type ModelEventsFrom<TModel extends Model<any, any, any>> = TModel extends Model<any, infer TEvent, any> ? TEvent : never;
|
|
17
|
+
export declare type EventCreator<Self extends AnyFunction, Return = ReturnType<Self>> = Return extends object ? Return extends {
|
|
18
|
+
type: any;
|
|
19
|
+
} ? "An event creator can't return an object with a type property" : Self : 'An event creator must return an object';
|
|
20
|
+
export declare type EventCreators<Self> = {
|
|
21
|
+
[K in keyof Self]: Self[K] extends AnyFunction ? EventCreator<Self[K]> : 'An event creator must be a function';
|
|
22
|
+
};
|
|
23
|
+
export declare type ModelCreators<Self> = {
|
|
24
|
+
events: EventCreators<Prop<Self, 'events'>>;
|
|
25
|
+
};
|
|
26
|
+
export declare type FinalEventCreators<Self> = {
|
|
27
|
+
[K in keyof Self]: Self[K] extends AnyFunction ? (...args: Parameters<Self[K]>) => Compute<ReturnType<Self[K]> & {
|
|
28
|
+
type: K;
|
|
29
|
+
}> : never;
|
|
30
|
+
};
|
|
31
|
+
export declare type FinalModelCreators<Self> = {
|
|
32
|
+
events: FinalEventCreators<Prop<Self, 'events'>>;
|
|
33
|
+
};
|
|
34
|
+
export declare type EventFromEventCreators<EventCreators> = {
|
|
35
|
+
[K in keyof EventCreators]: EventCreators[K] extends AnyFunction ? ReturnType<EventCreators[K]> : never;
|
|
36
|
+
}[keyof EventCreators];
|
|
37
|
+
//# sourceMappingURL=model.types.d.ts.map
|
package/es/registry.js
CHANGED
package/es/scheduler.js
CHANGED
package/es/schema.js
CHANGED
package/es/serviceScope.js
CHANGED
|
@@ -3,16 +3,14 @@
|
|
|
3
3
|
* This is used to provide the correct service to spawn().
|
|
4
4
|
*/
|
|
5
5
|
var serviceStack = [];
|
|
6
|
-
|
|
7
6
|
var provide = function (service, fn) {
|
|
8
7
|
serviceStack.push(service);
|
|
9
8
|
var result = fn(service);
|
|
10
9
|
serviceStack.pop();
|
|
11
10
|
return result;
|
|
12
11
|
};
|
|
13
|
-
|
|
14
12
|
var consume = function (fn) {
|
|
15
13
|
return fn(serviceStack[serviceStack.length - 1]);
|
|
16
14
|
};
|
|
17
15
|
|
|
18
|
-
export { consume, provide };
|
|
16
|
+
export { consume, provide };
|
package/es/stateUtils.js
CHANGED
|
@@ -4,13 +4,11 @@ import { keys, flatten } from './utils.js';
|
|
|
4
4
|
var isLeafNode = function (stateNode) {
|
|
5
5
|
return stateNode.type === 'atomic' || stateNode.type === 'final';
|
|
6
6
|
};
|
|
7
|
-
|
|
8
7
|
function getChildren(stateNode) {
|
|
9
8
|
return keys(stateNode.states).map(function (key) {
|
|
10
9
|
return stateNode.states[key];
|
|
11
10
|
});
|
|
12
11
|
}
|
|
13
|
-
|
|
14
12
|
function getAllStateNodes(stateNode) {
|
|
15
13
|
var stateNodes = [stateNode];
|
|
16
14
|
|
|
@@ -20,7 +18,6 @@ function getAllStateNodes(stateNode) {
|
|
|
20
18
|
|
|
21
19
|
return stateNodes.concat(flatten(getChildren(stateNode).map(getAllStateNodes)));
|
|
22
20
|
}
|
|
23
|
-
|
|
24
21
|
function getConfiguration(prevStateNodes, stateNodes) {
|
|
25
22
|
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
26
23
|
|
|
@@ -205,12 +202,10 @@ function getAdjList(configuration) {
|
|
|
205
202
|
|
|
206
203
|
return adjList;
|
|
207
204
|
}
|
|
208
|
-
|
|
209
205
|
function getValue(rootNode, configuration) {
|
|
210
206
|
var config = getConfiguration([rootNode], configuration);
|
|
211
207
|
return getValueFromAdj(rootNode, getAdjList(config));
|
|
212
208
|
}
|
|
213
|
-
|
|
214
209
|
function has(iterable, item) {
|
|
215
210
|
if (Array.isArray(iterable)) {
|
|
216
211
|
return iterable.some(function (member) {
|
|
@@ -224,13 +219,11 @@ function has(iterable, item) {
|
|
|
224
219
|
|
|
225
220
|
return false; // TODO: fix
|
|
226
221
|
}
|
|
227
|
-
|
|
228
222
|
function nextEvents(configuration) {
|
|
229
223
|
return __spreadArray([], __read(new Set(flatten(__spreadArray([], __read(configuration.map(function (sn) {
|
|
230
224
|
return sn.ownEvents;
|
|
231
225
|
})))))));
|
|
232
226
|
}
|
|
233
|
-
|
|
234
227
|
function isInFinalState(configuration, stateNode) {
|
|
235
228
|
if (stateNode.type === 'compound') {
|
|
236
229
|
return getChildren(stateNode).some(function (s) {
|
|
@@ -246,7 +239,6 @@ function isInFinalState(configuration, stateNode) {
|
|
|
246
239
|
|
|
247
240
|
return false;
|
|
248
241
|
}
|
|
249
|
-
|
|
250
242
|
function getMeta(configuration) {
|
|
251
243
|
if (configuration === void 0) {
|
|
252
244
|
configuration = [];
|
|
@@ -261,4 +253,4 @@ function getMeta(configuration) {
|
|
|
261
253
|
}, {});
|
|
262
254
|
}
|
|
263
255
|
|
|
264
|
-
export { getAdjList, getAllStateNodes, getChildren, getConfiguration, getMeta, getValue, has, isInFinalState, isLeafNode, nextEvents };
|
|
256
|
+
export { getAdjList, getAllStateNodes, getChildren, getConfiguration, getMeta, getValue, has, isInFinalState, isLeafNode, nextEvents };
|
package/es/types.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { StateNode } from './StateNode';
|
|
2
2
|
import { State } from './State';
|
|
3
3
|
import { Interpreter, Clock } from './interpreter';
|
|
4
|
+
import { Model } from './model.types';
|
|
4
5
|
export declare type EventType = string;
|
|
5
6
|
export declare type ActionType = string;
|
|
6
7
|
export declare type MetaObject = Record<string, any>;
|
|
@@ -152,7 +153,7 @@ export interface InvokeMeta {
|
|
|
152
153
|
* @param context The current machine `context`
|
|
153
154
|
* @param event The event that invoked the service
|
|
154
155
|
*/
|
|
155
|
-
export declare type InvokeCreator<TContext, TEvent extends EventObject, TFinalContext = any> = (context: TContext, event: TEvent, meta: InvokeMeta) => PromiseLike<TFinalContext> | StateMachine<TFinalContext, any, any> | Subscribable<EventObject> | InvokeCallback<any, TEvent>;
|
|
156
|
+
export declare type InvokeCreator<TContext, TEvent extends EventObject, TFinalContext = any> = (context: TContext, event: TEvent, meta: InvokeMeta) => PromiseLike<TFinalContext> | StateMachine<TFinalContext, any, any> | Subscribable<EventObject> | InvokeCallback<any, TEvent> | Behavior<any>;
|
|
156
157
|
export interface InvokeDefinition<TContext, TEvent extends EventObject> extends ActivityDefinition<TContext, TEvent> {
|
|
157
158
|
/**
|
|
158
159
|
* The source of the machine to be invoked, or the machine itself.
|
|
@@ -384,6 +385,13 @@ export interface StateNodeConfig<TContext, TStateSchema extends StateSchema, TEv
|
|
|
384
385
|
* The tags for this state node, which are accumulated into the `state.tags` property.
|
|
385
386
|
*/
|
|
386
387
|
tags?: SingleOrArray<string>;
|
|
388
|
+
/**
|
|
389
|
+
* Whether actions should be called in order.
|
|
390
|
+
* When `false` (default), `assign(...)` actions are prioritized before other actions.
|
|
391
|
+
*
|
|
392
|
+
* @default false
|
|
393
|
+
*/
|
|
394
|
+
preserveActionOrder?: boolean;
|
|
387
395
|
}
|
|
388
396
|
export interface StateNodeDefinition<TContext, TStateSchema extends StateSchema, TEvent extends EventObject> {
|
|
389
397
|
id: string;
|
|
@@ -875,10 +883,10 @@ export interface Subscription {
|
|
|
875
883
|
unsubscribe(): void;
|
|
876
884
|
}
|
|
877
885
|
export interface Subscribable<T> {
|
|
878
|
-
subscribe(observer: Observer<T>): Subscription;
|
|
879
886
|
subscribe(next: (value: T) => void, error?: (error: any) => void, complete?: () => void): Subscription;
|
|
887
|
+
subscribe(observer: Observer<T>): Subscription;
|
|
880
888
|
}
|
|
881
|
-
export declare type Spawnable = StateMachine<any, any, any> |
|
|
889
|
+
export declare type Spawnable = StateMachine<any, any, any> | PromiseLike<any> | InvokeCallback | Subscribable<any> | Behavior<any>;
|
|
882
890
|
export declare type ExtractEvent<TEvent extends EventObject, TEventType extends TEvent['type']> = TEvent extends {
|
|
883
891
|
type: TEventType;
|
|
884
892
|
} ? TEvent : never;
|
|
@@ -896,13 +904,26 @@ export interface ActorRef<TEvent extends EventObject, TEmitted = any> extends Su
|
|
|
896
904
|
* @deprecated Use `ActorRef` instead.
|
|
897
905
|
*/
|
|
898
906
|
export declare type SpawnedActorRef<TEvent extends EventObject, TEmitted = any> = ActorRef<TEvent, TEmitted>;
|
|
899
|
-
export declare type ActorRefFrom<T extends StateMachine<any, any, any> | Promise<any>> = T extends StateMachine<infer TContext, any, infer TEvent, infer TTypestate> ? ActorRef<TEvent, State<TContext, TEvent, any, TTypestate>> & {
|
|
907
|
+
export declare type ActorRefFrom<T extends StateMachine<any, any, any> | Promise<any> | Behavior<any>> = T extends StateMachine<infer TContext, any, infer TEvent, infer TTypestate> ? ActorRef<TEvent, State<TContext, TEvent, any, TTypestate>> & {
|
|
900
908
|
/**
|
|
901
909
|
* @deprecated Use `.getSnapshot()` instead.
|
|
902
910
|
*/
|
|
903
911
|
state: State<TContext, TEvent, any, TTypestate>;
|
|
904
|
-
} : T extends Promise<infer U> ? ActorRef<never, U> : never;
|
|
912
|
+
} : T extends Promise<infer U> ? ActorRef<never, U> : T extends Behavior<infer TEvent1, infer TEmitted> ? ActorRef<TEvent1, TEmitted> : never;
|
|
905
913
|
export declare type AnyInterpreter = Interpreter<any, any, any, any>;
|
|
906
914
|
export declare type InterpreterFrom<T extends StateMachine<any, any, any, any>> = T extends StateMachine<infer TContext, infer TStateSchema, infer TEvent, infer TTypestate> ? Interpreter<TContext, TStateSchema, TEvent, TTypestate> : never;
|
|
915
|
+
export interface ActorContext<TEvent extends EventObject, TEmitted> {
|
|
916
|
+
parent?: ActorRef<any, any>;
|
|
917
|
+
self: ActorRef<TEvent, TEmitted>;
|
|
918
|
+
id: string;
|
|
919
|
+
observers: Set<Observer<TEmitted>>;
|
|
920
|
+
}
|
|
921
|
+
export interface Behavior<TEvent extends EventObject, TEmitted = any> {
|
|
922
|
+
transition: (state: TEmitted, event: TEvent, actorCtx: ActorContext<TEvent, TEmitted>) => TEmitted;
|
|
923
|
+
initialState: TEmitted;
|
|
924
|
+
start?: (actorCtx: ActorContext<TEvent, TEmitted>) => TEmitted;
|
|
925
|
+
}
|
|
926
|
+
export declare type EventFrom<T> = T extends StateMachine<any, any, infer TEvent, any> ? TEvent : T extends Model<any, infer TEvent, any> ? TEvent : T extends State<any, infer TEvent, any, any> ? TEvent : T extends Interpreter<any, any, infer TEvent, any> ? TEvent : never;
|
|
927
|
+
export declare type ContextFrom<T> = T extends StateMachine<infer TContext, any, any, any> ? TContext : T extends Model<infer TContext, any, any> ? TContext : T extends State<infer TContext, any, any, any> ? TContext : T extends Interpreter<infer TContext, any, any, any> ? TContext : never;
|
|
907
928
|
export {};
|
|
908
929
|
//# sourceMappingURL=types.d.ts.map
|
package/es/types.js
CHANGED
package/es/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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';
|
|
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, Observer, Behavior } from './types';
|
|
2
2
|
import { StateNode } from './StateNode';
|
|
3
|
-
import {
|
|
3
|
+
import { State } from './State';
|
|
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;
|
|
@@ -40,6 +40,7 @@ export declare function toArray<T>(value: T[] | T | undefined): T[];
|
|
|
40
40
|
export declare function mapContext<TContext, TEvent extends EventObject>(mapper: Mapper<TContext, TEvent, any> | PropertyMapper<TContext, TEvent, any>, context: TContext, _event: SCXML.Event<TEvent>): any;
|
|
41
41
|
export declare function isBuiltInEvent(eventType: EventType): boolean;
|
|
42
42
|
export declare function isPromiseLike(value: any): value is PromiseLike<any>;
|
|
43
|
+
export declare function isBehavior(value: any): value is Behavior<any, any>;
|
|
43
44
|
export declare function partition<T, A extends T, B extends T>(items: T[], predicate: (item: T) => item is A): [A[], B[]];
|
|
44
45
|
export declare function updateHistoryStates(hist: HistoryValue, stateValue: StateValue): Record<string, HistoryValue | undefined>;
|
|
45
46
|
export declare function updateHistoryValue(hist: HistoryValue, stateValue: StateValue): HistoryValue;
|
package/es/utils.js
CHANGED
|
@@ -5,7 +5,6 @@ import { IS_PRODUCTION } from './environment.js';
|
|
|
5
5
|
function keys(value) {
|
|
6
6
|
return Object.keys(value);
|
|
7
7
|
}
|
|
8
|
-
|
|
9
8
|
function matchesState(parentStateId, childStateId, delimiter) {
|
|
10
9
|
if (delimiter === void 0) {
|
|
11
10
|
delimiter = STATE_DELIMITER;
|
|
@@ -35,7 +34,6 @@ function matchesState(parentStateId, childStateId, delimiter) {
|
|
|
35
34
|
return matchesState(parentStateValue[key], childStateValue[key]);
|
|
36
35
|
});
|
|
37
36
|
}
|
|
38
|
-
|
|
39
37
|
function getEventType(event) {
|
|
40
38
|
try {
|
|
41
39
|
return isString(event) || typeof event === 'number' ? "" + event : event.type;
|
|
@@ -43,7 +41,6 @@ function getEventType(event) {
|
|
|
43
41
|
throw new Error('Events must be strings or objects with a string event.type property.');
|
|
44
42
|
}
|
|
45
43
|
}
|
|
46
|
-
|
|
47
44
|
function toStatePath(stateId, delimiter) {
|
|
48
45
|
try {
|
|
49
46
|
if (isArray(stateId)) {
|
|
@@ -55,11 +52,9 @@ function toStatePath(stateId, delimiter) {
|
|
|
55
52
|
throw new Error("'" + stateId + "' is not a valid state path.");
|
|
56
53
|
}
|
|
57
54
|
}
|
|
58
|
-
|
|
59
55
|
function isStateLike(state) {
|
|
60
56
|
return typeof state === 'object' && 'value' in state && 'context' in state && 'event' in state && '_event' in state;
|
|
61
57
|
}
|
|
62
|
-
|
|
63
58
|
function toStateValue(stateValue, delimiter) {
|
|
64
59
|
if (isStateLike(stateValue)) {
|
|
65
60
|
return stateValue.value;
|
|
@@ -76,7 +71,6 @@ function toStateValue(stateValue, delimiter) {
|
|
|
76
71
|
var statePath = toStatePath(stateValue, delimiter);
|
|
77
72
|
return pathToStateValue(statePath);
|
|
78
73
|
}
|
|
79
|
-
|
|
80
74
|
function pathToStateValue(statePath) {
|
|
81
75
|
if (statePath.length === 1) {
|
|
82
76
|
return statePath[0];
|
|
@@ -96,7 +90,6 @@ function pathToStateValue(statePath) {
|
|
|
96
90
|
|
|
97
91
|
return value;
|
|
98
92
|
}
|
|
99
|
-
|
|
100
93
|
function mapValues(collection, iteratee) {
|
|
101
94
|
var result = {};
|
|
102
95
|
var collectionKeys = keys(collection);
|
|
@@ -108,7 +101,6 @@ function mapValues(collection, iteratee) {
|
|
|
108
101
|
|
|
109
102
|
return result;
|
|
110
103
|
}
|
|
111
|
-
|
|
112
104
|
function mapFilterValues(collection, iteratee, predicate) {
|
|
113
105
|
var e_1, _a;
|
|
114
106
|
|
|
@@ -144,7 +136,6 @@ function mapFilterValues(collection, iteratee, predicate) {
|
|
|
144
136
|
* @param props The deep path to the prop of the desired value
|
|
145
137
|
*/
|
|
146
138
|
|
|
147
|
-
|
|
148
139
|
var path = function (props) {
|
|
149
140
|
return function (object) {
|
|
150
141
|
var e_2, _a;
|
|
@@ -176,7 +167,6 @@ var path = function (props) {
|
|
|
176
167
|
* @param props The deep path to the prop of the desired value
|
|
177
168
|
*/
|
|
178
169
|
|
|
179
|
-
|
|
180
170
|
function nestedPath(props, accessorProp) {
|
|
181
171
|
return function (object) {
|
|
182
172
|
var e_3, _a;
|
|
@@ -203,7 +193,6 @@ function nestedPath(props, accessorProp) {
|
|
|
203
193
|
return result;
|
|
204
194
|
};
|
|
205
195
|
}
|
|
206
|
-
|
|
207
196
|
function toStatePaths(stateValue) {
|
|
208
197
|
if (!stateValue) {
|
|
209
198
|
return [[]];
|
|
@@ -226,13 +215,11 @@ function toStatePaths(stateValue) {
|
|
|
226
215
|
}));
|
|
227
216
|
return result;
|
|
228
217
|
}
|
|
229
|
-
|
|
230
218
|
function flatten(array) {
|
|
231
219
|
var _a;
|
|
232
220
|
|
|
233
221
|
return (_a = []).concat.apply(_a, __spreadArray([], __read(array)));
|
|
234
222
|
}
|
|
235
|
-
|
|
236
223
|
function toArrayStrict(value) {
|
|
237
224
|
if (isArray(value)) {
|
|
238
225
|
return value;
|
|
@@ -240,7 +227,6 @@ function toArrayStrict(value) {
|
|
|
240
227
|
|
|
241
228
|
return [value];
|
|
242
229
|
}
|
|
243
|
-
|
|
244
230
|
function toArray(value) {
|
|
245
231
|
if (value === undefined) {
|
|
246
232
|
return [];
|
|
@@ -248,7 +234,6 @@ function toArray(value) {
|
|
|
248
234
|
|
|
249
235
|
return toArrayStrict(value);
|
|
250
236
|
}
|
|
251
|
-
|
|
252
237
|
function mapContext(mapper, context, _event) {
|
|
253
238
|
var e_5, _a;
|
|
254
239
|
|
|
@@ -283,11 +268,9 @@ function mapContext(mapper, context, _event) {
|
|
|
283
268
|
|
|
284
269
|
return result;
|
|
285
270
|
}
|
|
286
|
-
|
|
287
271
|
function isBuiltInEvent(eventType) {
|
|
288
272
|
return /^(done|error)\./.test(eventType);
|
|
289
273
|
}
|
|
290
|
-
|
|
291
274
|
function isPromiseLike(value) {
|
|
292
275
|
if (value instanceof Promise) {
|
|
293
276
|
return true;
|
|
@@ -300,7 +283,9 @@ function isPromiseLike(value) {
|
|
|
300
283
|
|
|
301
284
|
return false;
|
|
302
285
|
}
|
|
303
|
-
|
|
286
|
+
function isBehavior(value) {
|
|
287
|
+
return value !== null && typeof value === 'object' && 'transition' in value && typeof value.transition === 'function';
|
|
288
|
+
}
|
|
304
289
|
function partition(items, predicate) {
|
|
305
290
|
var e_6, _a;
|
|
306
291
|
|
|
@@ -332,7 +317,6 @@ function partition(items, predicate) {
|
|
|
332
317
|
|
|
333
318
|
return [truthy, falsy];
|
|
334
319
|
}
|
|
335
|
-
|
|
336
320
|
function updateHistoryStates(hist, stateValue) {
|
|
337
321
|
return mapValues(hist.states, function (subHist, key) {
|
|
338
322
|
if (!subHist) {
|
|
@@ -351,14 +335,12 @@ function updateHistoryStates(hist, stateValue) {
|
|
|
351
335
|
};
|
|
352
336
|
});
|
|
353
337
|
}
|
|
354
|
-
|
|
355
338
|
function updateHistoryValue(hist, stateValue) {
|
|
356
339
|
return {
|
|
357
340
|
current: stateValue,
|
|
358
341
|
states: updateHistoryStates(hist, stateValue)
|
|
359
342
|
};
|
|
360
343
|
}
|
|
361
|
-
|
|
362
344
|
function updateContext(context, _event, assignActions, state) {
|
|
363
345
|
if (!IS_PRODUCTION) {
|
|
364
346
|
warn(!!context, 'Attempting to update undefined context');
|
|
@@ -402,7 +384,6 @@ function updateContext(context, _event, assignActions, state) {
|
|
|
402
384
|
return updatedContext;
|
|
403
385
|
} // tslint:disable-next-line:no-empty
|
|
404
386
|
|
|
405
|
-
|
|
406
387
|
var warn = function () {};
|
|
407
388
|
|
|
408
389
|
if (!IS_PRODUCTION) {
|
|
@@ -425,16 +406,13 @@ if (!IS_PRODUCTION) {
|
|
|
425
406
|
}
|
|
426
407
|
};
|
|
427
408
|
}
|
|
428
|
-
|
|
429
409
|
function isArray(value) {
|
|
430
410
|
return Array.isArray(value);
|
|
431
411
|
} // tslint:disable-next-line:ban-types
|
|
432
412
|
|
|
433
|
-
|
|
434
413
|
function isFunction(value) {
|
|
435
414
|
return typeof value === 'function';
|
|
436
415
|
}
|
|
437
|
-
|
|
438
416
|
function isString(value) {
|
|
439
417
|
return typeof value === 'string';
|
|
440
418
|
} // export function memoizedGetter<T, TP extends { prototype: object }>(
|
|
@@ -449,7 +427,6 @@ function isString(value) {
|
|
|
449
427
|
// });
|
|
450
428
|
// }
|
|
451
429
|
|
|
452
|
-
|
|
453
430
|
function toGuard(condition, guardMap) {
|
|
454
431
|
if (!condition) {
|
|
455
432
|
return undefined;
|
|
@@ -473,7 +450,6 @@ function toGuard(condition, guardMap) {
|
|
|
473
450
|
|
|
474
451
|
return condition;
|
|
475
452
|
}
|
|
476
|
-
|
|
477
453
|
function isObservable(value) {
|
|
478
454
|
try {
|
|
479
455
|
return 'subscribe' in value && isFunction(value.subscribe);
|
|
@@ -481,11 +457,9 @@ function isObservable(value) {
|
|
|
481
457
|
return false;
|
|
482
458
|
}
|
|
483
459
|
}
|
|
484
|
-
|
|
485
460
|
var symbolObservable = /*#__PURE__*/function () {
|
|
486
461
|
return typeof Symbol === 'function' && Symbol.observable || '@@observable';
|
|
487
462
|
}();
|
|
488
|
-
|
|
489
463
|
function isMachine(value) {
|
|
490
464
|
try {
|
|
491
465
|
return '__xstatenode' in value;
|
|
@@ -493,11 +467,9 @@ function isMachine(value) {
|
|
|
493
467
|
return false;
|
|
494
468
|
}
|
|
495
469
|
}
|
|
496
|
-
|
|
497
470
|
function isActor(value) {
|
|
498
471
|
return !!value && typeof value.send === 'function';
|
|
499
472
|
}
|
|
500
|
-
|
|
501
473
|
var uniqueId = /*#__PURE__*/function () {
|
|
502
474
|
var currentId = 0;
|
|
503
475
|
return function () {
|
|
@@ -505,7 +477,6 @@ var uniqueId = /*#__PURE__*/function () {
|
|
|
505
477
|
return currentId.toString(16);
|
|
506
478
|
};
|
|
507
479
|
}();
|
|
508
|
-
|
|
509
480
|
function toEventObject(event, payload // id?: TEvent['type']
|
|
510
481
|
) {
|
|
511
482
|
if (isString(event) || typeof event === 'number') {
|
|
@@ -516,7 +487,6 @@ function toEventObject(event, payload // id?: TEvent['type']
|
|
|
516
487
|
|
|
517
488
|
return event;
|
|
518
489
|
}
|
|
519
|
-
|
|
520
490
|
function toSCXMLEvent(event, scxmlEvent) {
|
|
521
491
|
if (!isString(event) && '$$type' in event && event.$$type === 'scxml') {
|
|
522
492
|
return event;
|
|
@@ -530,7 +500,6 @@ function toSCXMLEvent(event, scxmlEvent) {
|
|
|
530
500
|
type: 'external'
|
|
531
501
|
}, scxmlEvent);
|
|
532
502
|
}
|
|
533
|
-
|
|
534
503
|
function toTransitionConfigArray(event, configLike) {
|
|
535
504
|
var transitions = toArrayStrict(configLike).map(function (transitionLike) {
|
|
536
505
|
if (typeof transitionLike === 'undefined' || typeof transitionLike === 'string' || isMachine(transitionLike)) {
|
|
@@ -546,7 +515,6 @@ function toTransitionConfigArray(event, configLike) {
|
|
|
546
515
|
});
|
|
547
516
|
return transitions;
|
|
548
517
|
}
|
|
549
|
-
|
|
550
518
|
function normalizeTarget(target) {
|
|
551
519
|
if (target === undefined || target === TARGETLESS_KEY) {
|
|
552
520
|
return undefined;
|
|
@@ -554,7 +522,6 @@ function normalizeTarget(target) {
|
|
|
554
522
|
|
|
555
523
|
return toArray(target);
|
|
556
524
|
}
|
|
557
|
-
|
|
558
525
|
function reportUnhandledExceptionOnInvocation(originalError, currentError, id) {
|
|
559
526
|
if (!IS_PRODUCTION) {
|
|
560
527
|
var originalStackTrace = originalError.stack ? " Stacktrace was '" + originalError.stack + "'" : '';
|
|
@@ -569,7 +536,6 @@ function reportUnhandledExceptionOnInvocation(originalError, currentError, id) {
|
|
|
569
536
|
}
|
|
570
537
|
}
|
|
571
538
|
}
|
|
572
|
-
|
|
573
539
|
function evaluateGuard(machine, guard, context, _event, state) {
|
|
574
540
|
var guards = machine.options.guards;
|
|
575
541
|
var guardMeta = {
|
|
@@ -590,7 +556,6 @@ function evaluateGuard(machine, guard, context, _event, state) {
|
|
|
590
556
|
|
|
591
557
|
return condFn(context, _event.data, guardMeta);
|
|
592
558
|
}
|
|
593
|
-
|
|
594
559
|
function toInvokeSource(src) {
|
|
595
560
|
if (typeof src === 'string') {
|
|
596
561
|
return {
|
|
@@ -600,7 +565,6 @@ function toInvokeSource(src) {
|
|
|
600
565
|
|
|
601
566
|
return src;
|
|
602
567
|
}
|
|
603
|
-
|
|
604
568
|
function toObserver(nextHandler, errorHandler, completionHandler) {
|
|
605
569
|
if (typeof nextHandler === 'object') {
|
|
606
570
|
return nextHandler;
|
|
@@ -617,4 +581,4 @@ function toObserver(nextHandler, errorHandler, completionHandler) {
|
|
|
617
581
|
};
|
|
618
582
|
}
|
|
619
583
|
|
|
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 };
|
|
584
|
+
export { evaluateGuard, flatten, getEventType, isActor, isArray, isBehavior, 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,26 +1,26 @@
|
|
|
1
|
-
import { EventObject, Subscribable, InvokeDefinition, AnyEventObject, StateMachine, Spawnable, SCXML } from './types';
|
|
2
|
-
import { ActorRef, BaseActorRef } from '.';
|
|
3
|
-
export interface Actor<TContext = any, TEvent extends EventObject = AnyEventObject> extends Subscribable<TContext> {
|
|
4
|
-
id: string;
|
|
5
|
-
send: (event: TEvent) => any;
|
|
6
|
-
stop?: () => any | undefined;
|
|
7
|
-
toJSON: () => {
|
|
8
|
-
id: string;
|
|
9
|
-
};
|
|
10
|
-
meta?: InvokeDefinition<TContext, TEvent>;
|
|
11
|
-
state?: any;
|
|
12
|
-
deferred?: boolean;
|
|
13
|
-
}
|
|
14
|
-
export declare function createNullActor(id: string): ActorRef<any>;
|
|
15
|
-
/**
|
|
16
|
-
* Creates a deferred actor that is able to be invoked given the provided
|
|
17
|
-
* invocation information in its `.meta` value.
|
|
18
|
-
*
|
|
19
|
-
* @param invokeDefinition The meta information needed to invoke the actor.
|
|
20
|
-
*/
|
|
21
|
-
export declare function createInvocableActor<TC, TE extends EventObject>(invokeDefinition: InvokeDefinition<TC, TE>, machine: StateMachine<TC, any, TE, any>, context: TC, _event: SCXML.Event<TE>): ActorRef<any>;
|
|
22
|
-
export declare function createDeferredActor(entity: Spawnable, id: string, data?: any): ActorRef<any, undefined>;
|
|
23
|
-
export declare function isActor(item: any): item is ActorRef<any>;
|
|
24
|
-
export declare function isSpawnedActor(item: any): item is ActorRef<any>;
|
|
25
|
-
export declare function toActorRef<TEvent extends EventObject, TEmitted = any, TActorRefLike extends BaseActorRef<TEvent> = BaseActorRef<TEvent>>(actorRefLike: TActorRefLike): ActorRef<TEvent, TEmitted>;
|
|
1
|
+
import { EventObject, Subscribable, InvokeDefinition, AnyEventObject, StateMachine, Spawnable, SCXML } from './types';
|
|
2
|
+
import { ActorRef, BaseActorRef } from '.';
|
|
3
|
+
export interface Actor<TContext = any, TEvent extends EventObject = AnyEventObject> extends Subscribable<TContext> {
|
|
4
|
+
id: string;
|
|
5
|
+
send: (event: TEvent) => any;
|
|
6
|
+
stop?: () => any | undefined;
|
|
7
|
+
toJSON: () => {
|
|
8
|
+
id: string;
|
|
9
|
+
};
|
|
10
|
+
meta?: InvokeDefinition<TContext, TEvent>;
|
|
11
|
+
state?: any;
|
|
12
|
+
deferred?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare function createNullActor(id: string): ActorRef<any>;
|
|
15
|
+
/**
|
|
16
|
+
* Creates a deferred actor that is able to be invoked given the provided
|
|
17
|
+
* invocation information in its `.meta` value.
|
|
18
|
+
*
|
|
19
|
+
* @param invokeDefinition The meta information needed to invoke the actor.
|
|
20
|
+
*/
|
|
21
|
+
export declare function createInvocableActor<TC, TE extends EventObject>(invokeDefinition: InvokeDefinition<TC, TE>, machine: StateMachine<TC, any, TE, any>, context: TC, _event: SCXML.Event<TE>): ActorRef<any>;
|
|
22
|
+
export declare function createDeferredActor(entity: Spawnable, id: string, data?: any): ActorRef<any, undefined>;
|
|
23
|
+
export declare function isActor(item: any): item is ActorRef<any>;
|
|
24
|
+
export declare function isSpawnedActor(item: any): item is ActorRef<any>;
|
|
25
|
+
export declare function toActorRef<TEvent extends EventObject, TEmitted = any, TActorRefLike extends BaseActorRef<TEvent> = BaseActorRef<TEvent>>(actorRefLike: TActorRefLike): ActorRef<TEvent, TEmitted>;
|
|
26
26
|
//# sourceMappingURL=Actor.d.ts.map
|