xstate 4.26.0-pr2674-202191175724 → 4.27.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 +60 -10
- 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 +2 -1
- package/es/Machine.d.ts +4 -5
- package/es/State.d.ts +14 -13
- package/es/State.js +10 -3
- package/es/StateNode.d.ts +15 -15
- package/es/StateNode.js +50 -56
- package/es/_virtual/_tslib.js +8 -4
- package/es/actions.d.ts +21 -4
- package/es/actions.js +7 -7
- package/es/behaviors.d.ts +1 -1
- package/es/devTools.d.ts +2 -3
- package/es/devTools.js +4 -0
- package/es/each.d.ts +1 -1
- package/es/index.d.ts +0 -1
- package/es/interpreter.d.ts +25 -35
- package/es/interpreter.js +23 -17
- package/es/model.d.ts +2 -2
- package/es/model.types.d.ts +9 -8
- package/es/registry.js +1 -1
- package/es/scxml.d.ts +2 -2
- package/es/stateUtils.d.ts +6 -6
- package/es/stateUtils.js +8 -3
- package/es/types.d.ts +55 -69
- package/es/utils.d.ts +1 -1
- package/es/utils.js +10 -10
- package/lib/Actor.d.ts +2 -1
- package/lib/Machine.d.ts +4 -5
- package/lib/SimulatedClock.js +9 -5
- package/lib/State.d.ts +14 -13
- package/lib/State.js +10 -3
- package/lib/StateNode.d.ts +15 -15
- package/lib/StateNode.js +47 -53
- package/lib/_virtual/_tslib.js +8 -4
- package/lib/actions.d.ts +21 -4
- package/lib/actions.js +7 -7
- package/lib/behaviors.d.ts +1 -1
- package/lib/devTools.d.ts +2 -3
- package/lib/devTools.js +4 -0
- package/lib/each.d.ts +1 -1
- package/lib/index.d.ts +0 -1
- package/lib/interpreter.d.ts +25 -35
- package/lib/interpreter.js +23 -17
- package/lib/json.js +7 -7
- package/lib/model.d.ts +2 -2
- package/lib/model.js +14 -10
- package/lib/model.types.d.ts +9 -8
- package/lib/patterns.js +2 -2
- package/lib/registry.js +1 -1
- package/lib/scxml.d.ts +2 -2
- package/lib/scxml.js +29 -25
- package/lib/stateUtils.d.ts +6 -6
- package/lib/stateUtils.js +7 -1
- package/lib/types.d.ts +55 -69
- package/lib/utils.d.ts +1 -1
- package/lib/utils.js +10 -10
- package/package.json +4 -8
- package/dist/xstate.cjs.d.ts +0 -11
- package/dist/xstate.cjs.js +0 -16
- package/es/typegenTypes.d.ts +0 -78
- package/lib/typegenTypes.d.ts +0 -78
- package/lib/typegenTypes.js +0 -2
package/es/types.d.ts
CHANGED
|
@@ -1,25 +1,10 @@
|
|
|
1
|
-
import { Clock, Interpreter } from './interpreter';
|
|
2
|
-
import { Model } from './model.types';
|
|
3
|
-
import { State } from './State';
|
|
4
1
|
import { StateNode } from './StateNode';
|
|
5
|
-
import {
|
|
6
|
-
|
|
2
|
+
import { State } from './State';
|
|
3
|
+
import { Interpreter, Clock } from './interpreter';
|
|
4
|
+
import { IsNever, Model, Prop } from './model.types';
|
|
5
|
+
declare type AnyFunction = (...args: any[]) => any;
|
|
7
6
|
declare type ReturnTypeOrValue<T> = T extends AnyFunction ? ReturnType<T> : T;
|
|
8
|
-
export declare type
|
|
9
|
-
export declare type Cast<T extends any, TCastType extends any> = T extends TCastType ? T : TCastType;
|
|
10
|
-
export declare type Compute<A extends any> = {
|
|
11
|
-
[K in keyof A]: A[K];
|
|
12
|
-
} & unknown;
|
|
13
|
-
export declare type Prop<T, K> = K extends keyof T ? T[K] : never;
|
|
14
|
-
export declare type Values<T> = T[keyof T];
|
|
15
|
-
export declare type Merge<M, N> = Omit<M, keyof N> & N;
|
|
16
|
-
export declare type IndexByType<T extends {
|
|
17
|
-
type: string;
|
|
18
|
-
}> = {
|
|
19
|
-
[K in T['type']]: Extract<T, {
|
|
20
|
-
type: K;
|
|
21
|
-
}>;
|
|
22
|
-
};
|
|
7
|
+
export declare type Cast<A, B> = A extends B ? A : B;
|
|
23
8
|
export declare type EventType = string;
|
|
24
9
|
export declare type ActionType = string;
|
|
25
10
|
export declare type MetaObject = Record<string, any>;
|
|
@@ -50,7 +35,7 @@ export interface ActionObject<TContext, TEvent extends EventObject> extends Base
|
|
|
50
35
|
/**
|
|
51
36
|
* The implementation for executing the action.
|
|
52
37
|
*/
|
|
53
|
-
exec?: ActionFunction<TContext, TEvent
|
|
38
|
+
exec?: ActionFunction<TContext, TEvent> | undefined;
|
|
54
39
|
}
|
|
55
40
|
export declare type DefaultContext = Record<string, any> | undefined;
|
|
56
41
|
export declare type EventData = Record<string, any> & {
|
|
@@ -60,7 +45,7 @@ export declare type EventData = Record<string, any> & {
|
|
|
60
45
|
* The specified string event types or the specified event objects.
|
|
61
46
|
*/
|
|
62
47
|
export declare type Event<TEvent extends EventObject> = TEvent['type'] | TEvent;
|
|
63
|
-
export interface ActionMeta<TContext, TEvent extends EventObject, TAction extends
|
|
48
|
+
export interface ActionMeta<TContext, TEvent extends EventObject, TAction extends ActionObject<TContext, TEvent> = ActionObject<TContext, TEvent>> extends StateMeta<TContext, TEvent> {
|
|
64
49
|
action: TAction;
|
|
65
50
|
_event: SCXML.Event<TEvent>;
|
|
66
51
|
}
|
|
@@ -69,8 +54,8 @@ export interface AssignMeta<TContext, TEvent extends EventObject> {
|
|
|
69
54
|
action: AssignAction<TContext, TEvent>;
|
|
70
55
|
_event: SCXML.Event<TEvent>;
|
|
71
56
|
}
|
|
72
|
-
export declare type ActionFunction<TContext, TEvent extends EventObject, TAction extends
|
|
73
|
-
export interface
|
|
57
|
+
export declare type ActionFunction<TContext, TEvent extends EventObject, TAction extends ActionObject<TContext, TEvent> = ActionObject<TContext, TEvent>> = (context: TContext, event: TEvent, meta: ActionMeta<TContext, TEvent, TAction>) => void;
|
|
58
|
+
export interface ChooseCondition<TContext, TEvent extends EventObject> {
|
|
74
59
|
cond?: Condition<TContext, TEvent>;
|
|
75
60
|
actions: Actions<TContext, TEvent>;
|
|
76
61
|
}
|
|
@@ -97,14 +82,6 @@ export interface StateValueMap {
|
|
|
97
82
|
* - For complex state nodes, this is an object, e.g., `{ success: "someChildState" }`.
|
|
98
83
|
*/
|
|
99
84
|
export declare type StateValue = string | StateValueMap;
|
|
100
|
-
declare type KeysWithStates<TStates extends Record<string, StateSchema> | undefined> = TStates extends object ? {
|
|
101
|
-
[K in keyof TStates]-?: TStates[K] extends {
|
|
102
|
-
states: object;
|
|
103
|
-
} ? K : never;
|
|
104
|
-
}[keyof TStates] : never;
|
|
105
|
-
export declare type ExtractStateValue<TSchema extends Required<Pick<StateSchema<any>, 'states'>>> = keyof TSchema['states'] | (KeysWithStates<TSchema['states']> extends never ? never : {
|
|
106
|
-
[K in KeysWithStates<TSchema['states']>]?: ExtractStateValue<TSchema['states'][K]>;
|
|
107
|
-
});
|
|
108
85
|
export interface HistoryValue {
|
|
109
86
|
states: Record<string, HistoryValue | undefined>;
|
|
110
87
|
current: StateValue | undefined;
|
|
@@ -130,7 +107,7 @@ export interface TransitionConfig<TContext, TEvent extends EventObject> {
|
|
|
130
107
|
actions?: Actions<TContext, TEvent>;
|
|
131
108
|
in?: StateValue;
|
|
132
109
|
internal?: boolean;
|
|
133
|
-
target?: TransitionTarget<TContext, TEvent
|
|
110
|
+
target?: TransitionTarget<TContext, TEvent> | undefined;
|
|
134
111
|
meta?: Record<string, any>;
|
|
135
112
|
description?: string;
|
|
136
113
|
}
|
|
@@ -174,6 +151,7 @@ export declare type InvokeCallback<TEvent extends EventObject = AnyEventObject,
|
|
|
174
151
|
export interface InvokeMeta {
|
|
175
152
|
data: any;
|
|
176
153
|
src: InvokeSourceDefinition;
|
|
154
|
+
meta?: MetaObject;
|
|
177
155
|
}
|
|
178
156
|
/**
|
|
179
157
|
* Returns either a Promises or a callback handler (for streams of events) given the
|
|
@@ -213,6 +191,7 @@ export interface InvokeDefinition<TContext, TEvent extends EventObject> extends
|
|
|
213
191
|
* Data should be mapped to match the child machine's context shape.
|
|
214
192
|
*/
|
|
215
193
|
data?: Mapper<TContext, TEvent, any> | PropertyMapper<TContext, TEvent, any>;
|
|
194
|
+
meta?: MetaObject;
|
|
216
195
|
}
|
|
217
196
|
export interface Delay {
|
|
218
197
|
id: string;
|
|
@@ -295,6 +274,10 @@ export interface InvokeConfig<TContext, TEvent extends EventObject> {
|
|
|
295
274
|
* The transition to take upon the invoked child machine sending an error event.
|
|
296
275
|
*/
|
|
297
276
|
onError?: string | SingleOrArray<TransitionConfig<TContext, DoneInvokeEvent<any>>>;
|
|
277
|
+
/**
|
|
278
|
+
* Meta data related to this invocation
|
|
279
|
+
*/
|
|
280
|
+
meta?: MetaObject;
|
|
298
281
|
}
|
|
299
282
|
export interface StateNodeConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject> {
|
|
300
283
|
/**
|
|
@@ -363,7 +346,7 @@ export interface StateNodeConfig<TContext, TStateSchema extends StateSchema, TEv
|
|
|
363
346
|
*
|
|
364
347
|
* This is equivalent to defining a `[done(id)]` transition on this state node's `on` property.
|
|
365
348
|
*/
|
|
366
|
-
onDone?: string | SingleOrArray<TransitionConfig<TContext, DoneEventObject
|
|
349
|
+
onDone?: string | SingleOrArray<TransitionConfig<TContext, DoneEventObject>> | undefined;
|
|
367
350
|
/**
|
|
368
351
|
* The mapping (or array) of delays (in milliseconds) to their potential transition(s).
|
|
369
352
|
* The delayed transitions are taken after the specified delay in an interpreter.
|
|
@@ -450,6 +433,7 @@ export interface StateNodeDefinition<TContext, TStateSchema extends StateSchema,
|
|
|
450
433
|
data?: FinalStateNodeConfig<TContext, TEvent>['data'];
|
|
451
434
|
invoke: Array<InvokeDefinition<TContext, TEvent>>;
|
|
452
435
|
description?: string;
|
|
436
|
+
tags: string[];
|
|
453
437
|
}
|
|
454
438
|
export declare type AnyStateNodeDefinition = StateNodeDefinition<any, any, any>;
|
|
455
439
|
export interface AtomicStateNodeConfig<TContext, TEvent extends EventObject> extends StateNodeConfig<TContext, StateSchema, TEvent> {
|
|
@@ -471,7 +455,7 @@ export interface FinalStateNodeConfig<TContext, TEvent extends EventObject> exte
|
|
|
471
455
|
data?: Mapper<TContext, TEvent, any> | PropertyMapper<TContext, TEvent, any>;
|
|
472
456
|
}
|
|
473
457
|
export declare type SimpleOrStateNodeConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject> = AtomicStateNodeConfig<TContext, TEvent> | StateNodeConfig<TContext, TStateSchema, TEvent>;
|
|
474
|
-
export declare type ActionFunctionMap<TContext, TEvent extends EventObject, TAction extends
|
|
458
|
+
export declare type ActionFunctionMap<TContext, TEvent extends EventObject, TAction extends ActionObject<TContext, TEvent> = ActionObject<TContext, TEvent>> = {
|
|
475
459
|
[K in TAction['type']]?: ActionObject<TContext, TEvent> | ActionFunction<TContext, TEvent, TAction extends {
|
|
476
460
|
type: K;
|
|
477
461
|
} ? TAction : never>;
|
|
@@ -479,25 +463,25 @@ export declare type ActionFunctionMap<TContext, TEvent extends EventObject, TAct
|
|
|
479
463
|
export declare type DelayFunctionMap<TContext, TEvent extends EventObject> = Record<string, DelayConfig<TContext, TEvent>>;
|
|
480
464
|
export declare type ServiceConfig<TContext, TEvent extends EventObject = AnyEventObject> = string | StateMachine<any, any, any> | InvokeCreator<TContext, TEvent>;
|
|
481
465
|
export declare type DelayConfig<TContext, TEvent extends EventObject> = number | DelayExpr<TContext, TEvent>;
|
|
482
|
-
export interface MachineOptions<TContext, TEvent extends EventObject, TAction extends
|
|
483
|
-
guards
|
|
484
|
-
actions
|
|
466
|
+
export interface MachineOptions<TContext, TEvent extends EventObject, TAction extends ActionObject<TContext, TEvent> = ActionObject<TContext, TEvent>> {
|
|
467
|
+
guards: Record<string, ConditionPredicate<TContext, TEvent>>;
|
|
468
|
+
actions: ActionFunctionMap<TContext, TEvent, TAction>;
|
|
485
469
|
/**
|
|
486
470
|
* @deprecated Use `services` instead.
|
|
487
471
|
*/
|
|
488
|
-
activities
|
|
489
|
-
services
|
|
490
|
-
delays
|
|
472
|
+
activities: Record<string, ActivityConfig<TContext, TEvent>>;
|
|
473
|
+
services: Record<string, ServiceConfig<TContext, TEvent>>;
|
|
474
|
+
delays: DelayFunctionMap<TContext, TEvent>;
|
|
491
475
|
/**
|
|
492
476
|
* @private
|
|
493
477
|
*/
|
|
494
|
-
_parent?: StateNode<TContext, any, TEvent, any
|
|
478
|
+
_parent?: StateNode<TContext, any, TEvent, any>;
|
|
495
479
|
/**
|
|
496
480
|
* @private
|
|
497
481
|
*/
|
|
498
482
|
_key?: string;
|
|
499
483
|
}
|
|
500
|
-
export interface MachineConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject, TAction extends BaseActionObject =
|
|
484
|
+
export interface MachineConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject, TAction extends BaseActionObject = ActionObject<TContext, TEvent>> extends StateNodeConfig<TContext, TStateSchema, TEvent, TAction> {
|
|
501
485
|
/**
|
|
502
486
|
* The initial context (extended state)
|
|
503
487
|
*/
|
|
@@ -507,7 +491,6 @@ export interface MachineConfig<TContext, TStateSchema extends StateSchema, TEven
|
|
|
507
491
|
*/
|
|
508
492
|
version?: string;
|
|
509
493
|
schema?: MachineSchema<TContext, TEvent>;
|
|
510
|
-
tsTypes?: TTypesMeta | true;
|
|
511
494
|
}
|
|
512
495
|
export interface MachineSchema<TContext, TEvent extends EventObject> {
|
|
513
496
|
context?: TContext;
|
|
@@ -542,13 +525,13 @@ export interface HistoryStateNode<TContext> extends StateNode<TContext> {
|
|
|
542
525
|
export interface StateMachine<TContext, TStateSchema extends StateSchema, TEvent extends EventObject, TTypestate extends Typestate<TContext> = {
|
|
543
526
|
value: any;
|
|
544
527
|
context: TContext;
|
|
545
|
-
},
|
|
528
|
+
}, _TAction extends ActionObject<TContext, TEvent> = ActionObject<TContext, TEvent>> extends StateNode<TContext, TStateSchema, TEvent, TTypestate> {
|
|
546
529
|
id: string;
|
|
547
|
-
states: StateNode<TContext, TStateSchema, TEvent
|
|
548
|
-
withConfig(options:
|
|
549
|
-
withContext(context: TContext | (() => TContext)): StateMachine<TContext, TStateSchema, TEvent, TTypestate
|
|
530
|
+
states: StateNode<TContext, TStateSchema, TEvent>['states'];
|
|
531
|
+
withConfig(options: Partial<MachineOptions<TContext, TEvent>>, context?: TContext | (() => TContext)): StateMachine<TContext, TStateSchema, TEvent, TTypestate>;
|
|
532
|
+
withContext(context: TContext | (() => TContext)): StateMachine<TContext, TStateSchema, TEvent, TTypestate>;
|
|
550
533
|
}
|
|
551
|
-
export declare type StateFrom<T extends StateMachine<any, any, any, any
|
|
534
|
+
export declare type StateFrom<T extends StateMachine<any, any, any, any> | ((...args: any[]) => StateMachine<any, any, any, any>)> = T extends StateMachine<any, any, any> ? ReturnType<T['transition']> : T extends (...args: any[]) => StateMachine<any, any, any> ? ReturnType<ReturnType<T>['transition']> : never;
|
|
552
535
|
export interface ActionMap<TContext, TEvent extends EventObject> {
|
|
553
536
|
onEntry: Array<Action<TContext, TEvent>>;
|
|
554
537
|
actions: Array<Action<TContext, TEvent>>;
|
|
@@ -567,13 +550,13 @@ export interface ActivityMap {
|
|
|
567
550
|
}
|
|
568
551
|
export interface StateTransition<TContext, TEvent extends EventObject> {
|
|
569
552
|
transitions: Array<TransitionDefinition<TContext, TEvent>>;
|
|
570
|
-
configuration: Array<StateNode<TContext, any, TEvent, any
|
|
571
|
-
entrySet: Array<StateNode<TContext, any, TEvent, any
|
|
572
|
-
exitSet: Array<StateNode<TContext, any, TEvent, any
|
|
553
|
+
configuration: Array<StateNode<TContext, any, TEvent, any>>;
|
|
554
|
+
entrySet: Array<StateNode<TContext, any, TEvent, any>>;
|
|
555
|
+
exitSet: Array<StateNode<TContext, any, TEvent, any>>;
|
|
573
556
|
/**
|
|
574
557
|
* The source state that preceded the transition.
|
|
575
558
|
*/
|
|
576
|
-
source: State<TContext, any, any, any
|
|
559
|
+
source: State<TContext, any, any, any> | undefined;
|
|
577
560
|
actions: Array<ActionObject<TContext, TEvent>>;
|
|
578
561
|
}
|
|
579
562
|
export interface TransitionData<TContext, TEvent extends EventObject> {
|
|
@@ -716,7 +699,7 @@ export interface PureAction<TContext, TEvent extends EventObject> extends Action
|
|
|
716
699
|
}
|
|
717
700
|
export interface ChooseAction<TContext, TEvent extends EventObject> extends ActionObject<TContext, TEvent> {
|
|
718
701
|
type: ActionTypes.Choose;
|
|
719
|
-
conds: Array<
|
|
702
|
+
conds: Array<ChooseCondition<TContext, TEvent>>;
|
|
720
703
|
}
|
|
721
704
|
export interface TransitionDefinition<TContext, TEvent extends EventObject> extends TransitionConfig<TContext, TEvent> {
|
|
722
705
|
target: Array<StateNode<TContext, any, TEvent>> | undefined;
|
|
@@ -794,7 +777,7 @@ export interface SCXMLEventMeta<TEvent extends EventObject> {
|
|
|
794
777
|
_event: SCXML.Event<TEvent>;
|
|
795
778
|
}
|
|
796
779
|
export interface StateMeta<TContext, TEvent extends EventObject> {
|
|
797
|
-
state: State<TContext, TEvent, any, any
|
|
780
|
+
state: State<TContext, TEvent, any, any>;
|
|
798
781
|
_event: SCXML.Event<TEvent>;
|
|
799
782
|
}
|
|
800
783
|
export interface Typestate<TContext> {
|
|
@@ -813,7 +796,7 @@ export interface StateConfig<TContext, TEvent extends EventObject> {
|
|
|
813
796
|
_event: SCXML.Event<TEvent>;
|
|
814
797
|
_sessionid: string | null;
|
|
815
798
|
historyValue?: HistoryValue | undefined;
|
|
816
|
-
history?: State<TContext, TEvent
|
|
799
|
+
history?: State<TContext, TEvent>;
|
|
817
800
|
actions?: Array<ActionObject<TContext, TEvent>>;
|
|
818
801
|
/**
|
|
819
802
|
* @deprecated
|
|
@@ -826,7 +809,7 @@ export interface StateConfig<TContext, TEvent extends EventObject> {
|
|
|
826
809
|
children: Record<string, ActorRef<any>>;
|
|
827
810
|
done?: boolean;
|
|
828
811
|
tags?: Set<string>;
|
|
829
|
-
machine?: StateMachine<TContext, any, TEvent, any
|
|
812
|
+
machine?: StateMachine<TContext, any, TEvent, any>;
|
|
830
813
|
}
|
|
831
814
|
export interface StateSchema<TC = any> {
|
|
832
815
|
meta?: any;
|
|
@@ -839,9 +822,9 @@ export interface InterpreterOptions {
|
|
|
839
822
|
/**
|
|
840
823
|
* Whether state actions should be executed immediately upon transition. Defaults to `true`.
|
|
841
824
|
*/
|
|
842
|
-
execute
|
|
843
|
-
clock
|
|
844
|
-
logger
|
|
825
|
+
execute: boolean;
|
|
826
|
+
clock: Clock;
|
|
827
|
+
logger: (...args: any[]) => void;
|
|
845
828
|
parent?: AnyInterpreter;
|
|
846
829
|
/**
|
|
847
830
|
* If `true`, defers processing of sent events until the service
|
|
@@ -850,7 +833,7 @@ export interface InterpreterOptions {
|
|
|
850
833
|
*
|
|
851
834
|
* Default: `true`
|
|
852
835
|
*/
|
|
853
|
-
deferEvents
|
|
836
|
+
deferEvents: boolean;
|
|
854
837
|
/**
|
|
855
838
|
* The custom `id` for referencing this service.
|
|
856
839
|
*/
|
|
@@ -860,7 +843,8 @@ export interface InterpreterOptions {
|
|
|
860
843
|
*
|
|
861
844
|
* Default: `false`
|
|
862
845
|
*/
|
|
863
|
-
devTools
|
|
846
|
+
devTools: boolean | object;
|
|
847
|
+
[option: string]: any;
|
|
864
848
|
}
|
|
865
849
|
export declare namespace SCXML {
|
|
866
850
|
interface Event<TEvent extends EventObject> {
|
|
@@ -954,16 +938,15 @@ export interface ActorRef<TEvent extends EventObject, TEmitted = any> extends Su
|
|
|
954
938
|
* @deprecated Use `ActorRef` instead.
|
|
955
939
|
*/
|
|
956
940
|
export declare type SpawnedActorRef<TEvent extends EventObject, TEmitted = any> = ActorRef<TEvent, TEmitted>;
|
|
957
|
-
export declare type ActorRefWithDeprecatedState<TContext, TEvent extends EventObject, TTypestate extends Typestate<TContext
|
|
941
|
+
export declare type ActorRefWithDeprecatedState<TContext, TEvent extends EventObject, TTypestate extends Typestate<TContext>> = ActorRef<TEvent, State<TContext, TEvent, any, TTypestate>> & {
|
|
958
942
|
/**
|
|
959
943
|
* @deprecated Use `.getSnapshot()` instead.
|
|
960
944
|
*/
|
|
961
|
-
state: State<TContext, TEvent, any, TTypestate
|
|
945
|
+
state: State<TContext, TEvent, any, TTypestate>;
|
|
962
946
|
};
|
|
963
|
-
export declare type ActorRefFrom<T> = T extends StateMachine<infer TContext, any, infer TEvent, infer TTypestate> ? ActorRefWithDeprecatedState<TContext, TEvent, TTypestate> : T extends (...args: any[]) => StateMachine<infer TContext, any, infer TEvent, infer TTypestate
|
|
964
|
-
export declare type AnyInterpreter = Interpreter<any, any, any, any
|
|
965
|
-
export declare type InterpreterFrom<T extends StateMachine<any, any, any, any> | ((...args: any[]) => StateMachine<any, any, any, any>)> = T extends StateMachine<infer TContext, infer TStateSchema, infer TEvent, infer TTypestate
|
|
966
|
-
export declare type MachineOptionsFrom<T extends StateMachine<any, any, any, any> | ((...args: any[]) => StateMachine<any, any, any, any>), TRequireMissingImplementations extends boolean = false> = T extends StateMachine<infer TContext, any, infer TEvent, any, any, infer TResolvedTypesMeta> ? MaybeTypegenMachineOptions<TContext, TEvent, any, TResolvedTypesMeta, TRequireMissingImplementations> : T extends (...args: any[]) => StateMachine<infer TContext, any, infer TEvent, any, any, infer TResolvedTypesMeta> ? MaybeTypegenMachineOptions<TContext, TEvent, any, TResolvedTypesMeta, TRequireMissingImplementations> : never;
|
|
947
|
+
export declare type ActorRefFrom<T> = T extends StateMachine<infer TContext, any, infer TEvent, infer TTypestate> ? ActorRefWithDeprecatedState<TContext, TEvent, TTypestate> : T extends (...args: any[]) => StateMachine<infer TContext, any, infer TEvent, infer TTypestate> ? ActorRefWithDeprecatedState<TContext, TEvent, TTypestate> : T extends Promise<infer U> ? ActorRef<never, U> : T extends Behavior<infer TEvent1, infer TEmitted> ? ActorRef<TEvent1, TEmitted> : T extends (...args: any[]) => Behavior<infer TEvent1, infer TEmitted> ? ActorRef<TEvent1, TEmitted> : never;
|
|
948
|
+
export declare type AnyInterpreter = Interpreter<any, any, any, any>;
|
|
949
|
+
export declare type InterpreterFrom<T extends StateMachine<any, any, any, any> | ((...args: any[]) => StateMachine<any, any, any, any>)> = T extends StateMachine<infer TContext, infer TStateSchema, infer TEvent, infer TTypestate> ? Interpreter<TContext, TStateSchema, TEvent, TTypestate> : T extends (...args: any[]) => StateMachine<infer TContext, infer TStateSchema, infer TEvent, infer TTypestate> ? Interpreter<TContext, TStateSchema, TEvent, TTypestate> : never;
|
|
967
950
|
export interface ActorContext<TEvent extends EventObject, TEmitted> {
|
|
968
951
|
parent?: ActorRef<any, any>;
|
|
969
952
|
self: ActorRef<TEvent, TEmitted>;
|
|
@@ -976,7 +959,10 @@ export interface Behavior<TEvent extends EventObject, TEmitted = any> {
|
|
|
976
959
|
start?: (actorCtx: ActorContext<TEvent, TEmitted>) => TEmitted;
|
|
977
960
|
}
|
|
978
961
|
export declare type EmittedFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends ActorRef<infer _, infer TEmitted> ? TEmitted : R extends Behavior<infer _, infer TEmitted> ? TEmitted : R extends ActorContext<infer _, infer TEmitted> ? TEmitted : never : never;
|
|
979
|
-
|
|
962
|
+
declare type ResolveEventType<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer _, infer __, infer TEvent, infer ____> ? TEvent : R extends Model<infer _, infer TEvent, infer ___, infer ____> ? TEvent : R extends State<infer _, infer TEvent, infer ___, infer ____> ? TEvent : R extends Interpreter<infer _, infer __, infer TEvent, infer ____> ? TEvent : R extends ActorRef<infer TEvent, infer _> ? TEvent : never : never;
|
|
963
|
+
export declare type EventFrom<T, K extends Prop<TEvent, 'type'> = never, TEvent = ResolveEventType<T>> = IsNever<K> extends true ? TEvent : Extract<TEvent, {
|
|
964
|
+
type: K;
|
|
965
|
+
}>;
|
|
980
966
|
export declare type ContextFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer _, infer __, infer ___> ? TContext : R extends Model<infer TContext, infer _, infer __, infer ___> ? TContext : R extends State<infer TContext, infer _, infer __, infer ___> ? TContext : R extends Interpreter<infer TContext, infer _, infer __, infer ___> ? TContext : never : never;
|
|
981
967
|
export {};
|
|
982
968
|
//# sourceMappingURL=types.d.ts.map
|
package/es/utils.d.ts
CHANGED
|
@@ -63,7 +63,7 @@ export declare function toTransitionConfigArray<TContext, TEvent extends EventOb
|
|
|
63
63
|
}>;
|
|
64
64
|
export declare function normalizeTarget<TContext, TEvent extends EventObject>(target: SingleOrArray<string | StateNode<TContext, any, TEvent>> | undefined): Array<string | StateNode<TContext, any, TEvent>> | undefined;
|
|
65
65
|
export declare function reportUnhandledExceptionOnInvocation(originalError: any, currentError: any, id: string): void;
|
|
66
|
-
export declare function evaluateGuard<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any
|
|
66
|
+
export declare function evaluateGuard<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any>, guard: Guard<TContext, TEvent>, context: TContext, _event: SCXML.Event<TEvent>, state: State<TContext, TEvent>): boolean;
|
|
67
67
|
export declare function toInvokeSource(src: string | InvokeSourceDefinition): InvokeSourceDefinition;
|
|
68
68
|
export declare function toObserver<T>(nextHandler: Observer<T> | ((value: T) => void), errorHandler?: (error: any) => void, completionHandler?: () => void): Observer<T>;
|
|
69
69
|
//# sourceMappingURL=utils.d.ts.map
|
package/es/utils.js
CHANGED
|
@@ -36,7 +36,7 @@ function matchesState(parentStateId, childStateId, delimiter) {
|
|
|
36
36
|
}
|
|
37
37
|
function getEventType(event) {
|
|
38
38
|
try {
|
|
39
|
-
return isString(event) || typeof event === 'number' ? ""
|
|
39
|
+
return isString(event) || typeof event === 'number' ? "".concat(event) : event.type;
|
|
40
40
|
} catch (e) {
|
|
41
41
|
throw new Error('Events must be strings or objects with a string event.type property.');
|
|
42
42
|
}
|
|
@@ -49,7 +49,7 @@ function toStatePath(stateId, delimiter) {
|
|
|
49
49
|
|
|
50
50
|
return stateId.toString().split(delimiter);
|
|
51
51
|
} catch (e) {
|
|
52
|
-
throw new Error("'"
|
|
52
|
+
throw new Error("'".concat(stateId, "' is not a valid state path."));
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
function isStateLike(state) {
|
|
@@ -218,7 +218,7 @@ function toStatePaths(stateValue) {
|
|
|
218
218
|
function flatten(array) {
|
|
219
219
|
var _a;
|
|
220
220
|
|
|
221
|
-
return (_a = []).concat.apply(_a, __spreadArray([], __read(array)));
|
|
221
|
+
return (_a = []).concat.apply(_a, __spreadArray([], __read(array), false));
|
|
222
222
|
}
|
|
223
223
|
function toArrayStrict(value) {
|
|
224
224
|
if (isArray(value)) {
|
|
@@ -395,7 +395,7 @@ if (!IS_PRODUCTION) {
|
|
|
395
395
|
}
|
|
396
396
|
|
|
397
397
|
if (console !== undefined) {
|
|
398
|
-
var args = ["Warning: "
|
|
398
|
+
var args = ["Warning: ".concat(message)];
|
|
399
399
|
|
|
400
400
|
if (error) {
|
|
401
401
|
args.push(error);
|
|
@@ -524,15 +524,15 @@ function normalizeTarget(target) {
|
|
|
524
524
|
}
|
|
525
525
|
function reportUnhandledExceptionOnInvocation(originalError, currentError, id) {
|
|
526
526
|
if (!IS_PRODUCTION) {
|
|
527
|
-
var originalStackTrace = originalError.stack ? " Stacktrace was '"
|
|
527
|
+
var originalStackTrace = originalError.stack ? " Stacktrace was '".concat(originalError.stack, "'") : '';
|
|
528
528
|
|
|
529
529
|
if (originalError === currentError) {
|
|
530
530
|
// tslint:disable-next-line:no-console
|
|
531
|
-
console.error("Missing onError handler for invocation '"
|
|
531
|
+
console.error("Missing onError handler for invocation '".concat(id, "', error was '").concat(originalError, "'.").concat(originalStackTrace));
|
|
532
532
|
} else {
|
|
533
|
-
var stackTrace = currentError.stack ? " Stacktrace was '"
|
|
533
|
+
var stackTrace = currentError.stack ? " Stacktrace was '".concat(currentError.stack, "'") : ''; // tslint:disable-next-line:no-console
|
|
534
534
|
|
|
535
|
-
console.error("Missing onError handler and/or unhandled exception/promise rejection for invocation '"
|
|
535
|
+
console.error("Missing onError handler and/or unhandled exception/promise rejection for invocation '".concat(id, "'. ") + "Original error: '".concat(originalError, "'. ").concat(originalStackTrace, " Current error is '").concat(currentError, "'.").concat(stackTrace));
|
|
536
536
|
}
|
|
537
537
|
}
|
|
538
538
|
}
|
|
@@ -548,10 +548,10 @@ function evaluateGuard(machine, guard, context, _event, state) {
|
|
|
548
548
|
return ((guards === null || guards === void 0 ? void 0 : guards[guard.name]) || guard.predicate)(context, _event.data, guardMeta);
|
|
549
549
|
}
|
|
550
550
|
|
|
551
|
-
var condFn = guards
|
|
551
|
+
var condFn = guards[guard.type];
|
|
552
552
|
|
|
553
553
|
if (!condFn) {
|
|
554
|
-
throw new Error("Guard '"
|
|
554
|
+
throw new Error("Guard '".concat(guard.type, "' is not implemented on machine '").concat(machine.id, "'."));
|
|
555
555
|
}
|
|
556
556
|
|
|
557
557
|
return condFn(context, _event.data, guardMeta);
|
package/lib/Actor.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { EventObject, Subscribable, InvokeDefinition, AnyEventObject, StateMachine, Spawnable, SCXML
|
|
1
|
+
import { EventObject, Subscribable, InvokeDefinition, AnyEventObject, StateMachine, Spawnable, SCXML } from './types';
|
|
2
|
+
import { ActorRef, BaseActorRef } 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;
|
package/lib/Machine.d.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { Model } from './model.types';
|
|
2
|
-
import { AnyEventObject,
|
|
3
|
-
import { MaybeTypegenMachineOptions, TypegenConstraint, TypegenDisabled, ResolveTypegenMeta } from './typegenTypes';
|
|
2
|
+
import { AnyEventObject, DefaultContext, EventObject, MachineConfig, MachineOptions, StateMachine, StateSchema, Typestate } from './types';
|
|
4
3
|
/**
|
|
5
4
|
* @deprecated Use `createMachine(...)` instead.
|
|
6
5
|
*/
|
|
7
|
-
export declare function Machine<TContext = any, TEvent extends EventObject = AnyEventObject>(config: MachineConfig<TContext, any, TEvent>, options?: MachineOptions<TContext, TEvent
|
|
8
|
-
export declare function Machine<TContext = DefaultContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = AnyEventObject>(config: MachineConfig<TContext, TStateSchema, TEvent>, options?: MachineOptions<TContext, TEvent
|
|
6
|
+
export declare function Machine<TContext = any, TEvent extends EventObject = AnyEventObject>(config: MachineConfig<TContext, any, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>, initialContext?: TContext): StateMachine<TContext, any, TEvent>;
|
|
7
|
+
export declare function Machine<TContext = DefaultContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = AnyEventObject>(config: MachineConfig<TContext, TStateSchema, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>, initialContext?: TContext): StateMachine<TContext, TStateSchema, TEvent>;
|
|
9
8
|
export declare function createMachine<TContext, TEvent extends EventObject = AnyEventObject, TTypestate extends Typestate<TContext> = {
|
|
10
9
|
value: any;
|
|
11
10
|
context: TContext;
|
|
12
|
-
}
|
|
11
|
+
}>(config: TContext extends Model<any, any, any, any> ? 'Model type no longer supported as generic type. Please use `model.createMachine(...)` instead.' : MachineConfig<TContext, any, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>): StateMachine<TContext, any, TEvent, TTypestate>;
|
|
13
12
|
//# sourceMappingURL=Machine.d.ts.map
|
package/lib/SimulatedClock.js
CHANGED
|
@@ -15,10 +15,14 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
15
15
|
}
|
|
16
16
|
return ar;
|
|
17
17
|
};
|
|
18
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
19
|
-
for (var i = 0,
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
+
if (ar || !(i in from)) {
|
|
21
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
+
ar[i] = from[i];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
22
26
|
};
|
|
23
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
28
|
exports.SimulatedClock = void 0;
|
|
@@ -55,7 +59,7 @@ var SimulatedClock = /** @class */ (function () {
|
|
|
55
59
|
};
|
|
56
60
|
SimulatedClock.prototype.flushTimeouts = function () {
|
|
57
61
|
var _this = this;
|
|
58
|
-
__spreadArray([], __read(this.timeouts)).sort(function (_a, _b) {
|
|
62
|
+
__spreadArray([], __read(this.timeouts), false).sort(function (_a, _b) {
|
|
59
63
|
var _c = __read(_a, 2), _idA = _c[0], timeoutA = _c[1];
|
|
60
64
|
var _d = __read(_b, 2), _idB = _d[0], timeoutB = _d[1];
|
|
61
65
|
var endA = timeoutA.start + timeoutA.timeout;
|
package/lib/State.d.ts
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
import { StateValue, ActivityMap, EventObject, HistoryValue, ActionObject, EventType, StateConfig, SCXML, StateSchema, TransitionDefinition, Typestate, ActorRef, StateMachine, SimpleEventsOf } from './types';
|
|
2
2
|
import { StateNode } from './StateNode';
|
|
3
|
-
import { TypegenDisabled, TypegenEnabled } from './typegenTypes';
|
|
4
|
-
import { BaseActionObject, Prop } from './types';
|
|
5
3
|
export declare function stateValuesEqual(a: StateValue | undefined, b: StateValue | undefined): boolean;
|
|
6
4
|
export declare function isState<TContext, TEvent extends EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
|
|
7
5
|
value: any;
|
|
8
6
|
context: TContext;
|
|
9
|
-
}
|
|
10
|
-
export declare function bindActionToState<TC, TE extends EventObject>(action: ActionObject<TC, TE>, state: State<TC, TE, any, any
|
|
7
|
+
}>(state: object | string): state is State<TContext, TEvent, TStateSchema, TTypestate>;
|
|
8
|
+
export declare function bindActionToState<TC, TE extends EventObject>(action: ActionObject<TC, TE>, state: State<TC, TE, any, any>): ActionObject<TC, TE>;
|
|
11
9
|
export declare class State<TContext, TEvent extends EventObject = EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
|
|
12
10
|
value: any;
|
|
13
11
|
context: TContext;
|
|
14
|
-
}
|
|
12
|
+
}> {
|
|
15
13
|
value: StateValue;
|
|
16
14
|
context: TContext;
|
|
17
15
|
historyValue?: HistoryValue | undefined;
|
|
18
|
-
history?: State<TContext, TEvent, TStateSchema, TTypestate
|
|
16
|
+
history?: State<TContext, TEvent, TStateSchema, TTypestate>;
|
|
19
17
|
actions: Array<ActionObject<TContext, TEvent>>;
|
|
20
18
|
activities: ActivityMap;
|
|
21
19
|
meta: any;
|
|
@@ -53,13 +51,13 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
|
|
|
53
51
|
*/
|
|
54
52
|
children: Record<string, ActorRef<any>>;
|
|
55
53
|
tags: Set<string>;
|
|
56
|
-
machine: StateMachine<TContext, any, TEvent, TTypestate
|
|
54
|
+
machine: StateMachine<TContext, any, TEvent, TTypestate> | undefined;
|
|
57
55
|
/**
|
|
58
56
|
* Creates a new State instance for the given `stateValue` and `context`.
|
|
59
57
|
* @param stateValue
|
|
60
58
|
* @param context
|
|
61
59
|
*/
|
|
62
|
-
static from<TC, TE extends EventObject = EventObject>(stateValue: State<TC, TE, any, any
|
|
60
|
+
static from<TC, TE extends EventObject = EventObject>(stateValue: State<TC, TE, any, any> | StateValue, context?: TC | undefined): State<TC, TE, any, any>;
|
|
63
61
|
/**
|
|
64
62
|
* Creates a new State instance for the given `config`.
|
|
65
63
|
* @param config The state config
|
|
@@ -90,26 +88,29 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
|
|
|
90
88
|
* @param delimiter The character(s) that separate each subpath in the string state node path.
|
|
91
89
|
*/
|
|
92
90
|
toStrings(stateValue?: StateValue, delimiter?: string): string[];
|
|
93
|
-
toJSON(): Omit<this, "
|
|
91
|
+
toJSON(): Omit<this, "machine" | "tags" | "transitions" | "configuration"> & {
|
|
94
92
|
tags: string[];
|
|
95
93
|
};
|
|
96
94
|
/**
|
|
97
95
|
* Whether the current state value is a subset of the given parent state value.
|
|
98
96
|
* @param parentStateValue
|
|
99
97
|
*/
|
|
100
|
-
matches<TSV extends TTypestate['value']>(parentStateValue:
|
|
98
|
+
matches<TSV extends TTypestate['value']>(parentStateValue: TSV): this is State<(TTypestate extends any ? {
|
|
101
99
|
value: TSV;
|
|
102
100
|
context: any;
|
|
103
|
-
} extends TTypestate ? TTypestate : never : never)['context'], TEvent, TStateSchema, TTypestate
|
|
101
|
+
} extends TTypestate ? TTypestate : never : never)['context'], TEvent, TStateSchema, TTypestate> & {
|
|
104
102
|
value: TSV;
|
|
105
103
|
};
|
|
106
104
|
/**
|
|
107
105
|
* Whether the current state configuration has a state node with the specified `tag`.
|
|
108
106
|
* @param tag
|
|
109
107
|
*/
|
|
110
|
-
hasTag(tag:
|
|
108
|
+
hasTag(tag: string): boolean;
|
|
111
109
|
/**
|
|
112
|
-
* Determines whether sending the `event` will cause a transition
|
|
110
|
+
* Determines whether sending the `event` will cause a non-forbidden transition
|
|
111
|
+
* to be selected, even if the transitions have no actions nor
|
|
112
|
+
* change the state value.
|
|
113
|
+
*
|
|
113
114
|
* @param event The event to test
|
|
114
115
|
* @returns Whether the event will cause a transition
|
|
115
116
|
*/
|
package/lib/State.js
CHANGED
|
@@ -215,7 +215,7 @@ function () {
|
|
|
215
215
|
return _this.toStrings(stateValue[key], delimiter).map(function (s) {
|
|
216
216
|
return key + delimiter + s;
|
|
217
217
|
});
|
|
218
|
-
}))));
|
|
218
|
+
})), false));
|
|
219
219
|
};
|
|
220
220
|
|
|
221
221
|
State.prototype.toJSON = function () {
|
|
@@ -249,7 +249,10 @@ function () {
|
|
|
249
249
|
return this.tags.has(tag);
|
|
250
250
|
};
|
|
251
251
|
/**
|
|
252
|
-
* Determines whether sending the `event` will cause a transition
|
|
252
|
+
* Determines whether sending the `event` will cause a non-forbidden transition
|
|
253
|
+
* to be selected, even if the transitions have no actions nor
|
|
254
|
+
* change the state value.
|
|
255
|
+
*
|
|
253
256
|
* @param event The event to test
|
|
254
257
|
* @returns Whether the event will cause a transition
|
|
255
258
|
*/
|
|
@@ -262,7 +265,11 @@ function () {
|
|
|
262
265
|
utils.warn(!!this.machine, "state.can(...) used outside of a machine-created State object; this will always return false.");
|
|
263
266
|
}
|
|
264
267
|
|
|
265
|
-
|
|
268
|
+
var transitionData = (_a = this.machine) === null || _a === void 0 ? void 0 : _a.getTransitionData(this, event);
|
|
269
|
+
return !!(transitionData === null || transitionData === void 0 ? void 0 : transitionData.transitions.length) && // Check that at least one transition is not forbidden
|
|
270
|
+
transitionData.transitions.some(function (t) {
|
|
271
|
+
return t.target !== undefined || t.actions.length;
|
|
272
|
+
});
|
|
266
273
|
};
|
|
267
274
|
|
|
268
275
|
return State;
|