xstate 5.0.0-alpha.5 → 5.0.0-beta.10
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/actions/dist/xstate-actions.cjs.d.mts +2 -0
- package/actions/dist/xstate-actions.cjs.d.mts.map +1 -0
- package/actions/dist/xstate-actions.cjs.d.ts +1 -0
- package/actions/dist/xstate-actions.cjs.d.ts.map +1 -0
- package/actions/dist/xstate-actions.cjs.dev.js +2 -2
- package/actions/dist/xstate-actions.cjs.mjs +24 -0
- package/actions/dist/xstate-actions.cjs.prod.js +3 -3
- package/actions/dist/xstate-actions.esm.js +1 -1
- package/actions/dist/xstate-actions.umd.min.js +1 -1
- package/actions/dist/xstate-actions.umd.min.js.map +1 -1
- package/actors/dist/xstate-actors.cjs.d.mts +2 -0
- package/actors/dist/xstate-actors.cjs.d.mts.map +1 -0
- package/actors/dist/xstate-actors.cjs.d.ts +1 -0
- package/actors/dist/xstate-actors.cjs.d.ts.map +1 -0
- package/actors/dist/xstate-actors.cjs.dev.js +2 -1
- package/actors/dist/xstate-actors.cjs.mjs +15 -0
- package/actors/dist/xstate-actors.cjs.prod.js +3 -2
- package/actors/dist/xstate-actors.esm.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dev/dist/xstate-dev.cjs.d.mts +2 -0
- package/dev/dist/xstate-dev.cjs.d.mts.map +1 -0
- package/dev/dist/xstate-dev.cjs.d.ts +1 -0
- package/dev/dist/xstate-dev.cjs.d.ts.map +1 -0
- package/dev/dist/xstate-dev.cjs.mjs +5 -0
- package/dev/dist/xstate-dev.cjs.prod.js +6 -43
- package/dev/dist/xstate-dev.umd.min.js.map +1 -1
- package/dist/{actions-96f799fc.cjs.dev.js → actions-109712d3.cjs.dev.js} +397 -379
- package/dist/{actions-7678b87b.esm.js → actions-67f1d04e.esm.js} +351 -366
- package/dist/{actions-2479953d.cjs.prod.js → actions-d0262a43.cjs.prod.js} +420 -388
- package/dist/declarations/src/State.d.ts +2 -3
- package/dist/declarations/src/StateMachine.d.ts +6 -6
- package/dist/declarations/src/StateNode.d.ts +5 -11
- package/dist/declarations/src/actions/send.d.ts +0 -7
- package/dist/declarations/src/actions.d.ts +13 -12
- package/dist/declarations/src/actors/index.d.ts +2 -1
- package/dist/declarations/src/actors/observable.d.ts +1 -2
- package/dist/declarations/src/actors/promise.d.ts +1 -2
- package/dist/declarations/src/guards.d.ts +2 -2
- package/dist/declarations/src/index.d.ts +13 -29
- package/dist/declarations/src/interpreter.d.ts +5 -4
- package/dist/declarations/src/spawn.d.ts +2 -2
- package/dist/declarations/src/stateUtils.d.ts +15 -14
- package/dist/declarations/src/typegenTypes.d.ts +10 -4
- package/dist/declarations/src/types.d.ts +27 -101
- package/dist/declarations/src/utils.d.ts +3 -5
- package/dist/declarations/src/waitFor.d.ts +33 -0
- package/dist/index-0f3fdf0c.cjs.prod.js +52 -0
- package/dist/xstate.cjs.d.mts +2 -0
- package/dist/xstate.cjs.d.mts.map +1 -0
- package/dist/xstate.cjs.d.ts +1 -0
- package/dist/xstate.cjs.d.ts.map +1 -0
- package/dist/xstate.cjs.dev.js +125 -111
- package/dist/xstate.cjs.mjs +38 -0
- package/dist/xstate.cjs.prod.js +123 -112
- package/dist/xstate.esm.js +108 -99
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.d.mts +2 -0
- package/guards/dist/xstate-guards.cjs.d.mts.map +1 -0
- package/guards/dist/xstate-guards.cjs.d.ts +1 -0
- package/guards/dist/xstate-guards.cjs.d.ts.map +1 -0
- package/guards/dist/xstate-guards.cjs.dev.js +1 -1
- package/guards/dist/xstate-guards.cjs.mjs +8 -0
- package/guards/dist/xstate-guards.cjs.prod.js +2 -2
- package/guards/dist/xstate-guards.esm.js +1 -1
- package/guards/dist/xstate-guards.umd.min.js +1 -1
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +7 -1
- package/dist/declarations/src/schema.d.ts +0 -2
|
@@ -58,7 +58,7 @@ export interface UnifiedArg<TContext extends MachineContext, TEvent extends Even
|
|
|
58
58
|
export interface BaseDynamicActionObject<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TResolvedAction extends BaseActionObject, TDynamicParams extends Record<string, any>> {
|
|
59
59
|
type: `xstate.${string}`;
|
|
60
60
|
params: TDynamicParams;
|
|
61
|
-
resolve: (
|
|
61
|
+
resolve: (event: TExpressionEvent, extra: {
|
|
62
62
|
state: State<TContext, TEvent>;
|
|
63
63
|
/**
|
|
64
64
|
* The original action object
|
|
@@ -75,7 +75,6 @@ export interface BaseDynamicActionObject<TContext extends MachineContext, TExpre
|
|
|
75
75
|
export type MachineContext = Record<string, any>;
|
|
76
76
|
export interface ActionMeta<TEvent extends EventObject, TAction extends ParameterizedObject = ParameterizedObject> extends StateMeta<TEvent> {
|
|
77
77
|
action: TAction;
|
|
78
|
-
_event: SCXML.Event<TEvent>;
|
|
79
78
|
}
|
|
80
79
|
export type Spawner = <T extends ActorBehavior<any, any> | string>(// TODO: read string from machine behavior keys
|
|
81
80
|
behavior: T, options?: Partial<{
|
|
@@ -84,7 +83,7 @@ behavior: T, options?: Partial<{
|
|
|
84
83
|
}>) => T extends ActorBehavior<infer TActorEvent, infer TActorEmitted> ? ActorRef<TActorEvent, TActorEmitted> : ActorRef<any, any>;
|
|
85
84
|
export interface AssignMeta<TExpressionEvent extends EventObject, _TEvent extends EventObject> extends StateMeta<TExpressionEvent> {
|
|
86
85
|
action: BaseActionObject;
|
|
87
|
-
|
|
86
|
+
event: TExpressionEvent;
|
|
88
87
|
spawn: Spawner;
|
|
89
88
|
}
|
|
90
89
|
export type ActionFunction<TContext extends MachineContext, TExpressionEvent extends EventObject, TAction extends ParameterizedObject = ParameterizedObject, TEvent extends EventObject = TExpressionEvent> = (args: {
|
|
@@ -92,7 +91,7 @@ export type ActionFunction<TContext extends MachineContext, TExpressionEvent ext
|
|
|
92
91
|
event: TExpressionEvent;
|
|
93
92
|
} & ActionMeta<TEvent, TAction>) => void;
|
|
94
93
|
export interface ChooseCondition<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent> {
|
|
95
|
-
guard?: GuardConfig<TContext,
|
|
94
|
+
guard?: GuardConfig<TContext, TExpressionEvent>;
|
|
96
95
|
actions: Actions<TContext, TExpressionEvent, TEvent>;
|
|
97
96
|
}
|
|
98
97
|
export type Action<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent> = ActionType | ParameterizedObject | ActionFunction<TContext, TExpressionEvent, ParameterizedObject, TEvent> | BaseDynamicActionObject<TContext, TExpressionEvent, TEvent, any, any>;
|
|
@@ -126,10 +125,9 @@ export interface DefaultGuardObject<TContext extends MachineContext, TEvent exte
|
|
|
126
125
|
children?: Array<GuardObject<TContext, TEvent>>;
|
|
127
126
|
predicate?: GuardPredicate<TContext, TEvent>;
|
|
128
127
|
}
|
|
129
|
-
export type GuardEvaluator<TContext extends MachineContext, TEvent extends EventObject> = (guard: GuardDefinition<TContext, TEvent>, context: TContext,
|
|
128
|
+
export type GuardEvaluator<TContext extends MachineContext, TEvent extends EventObject> = (guard: GuardDefinition<TContext, TEvent>, context: TContext, event: TEvent, state: State<TContext, TEvent>) => boolean;
|
|
130
129
|
export interface GuardMeta<TContext extends MachineContext, TEvent extends EventObject> {
|
|
131
130
|
state: State<TContext, TEvent, any>;
|
|
132
|
-
_event: SCXML.Event<TEvent>;
|
|
133
131
|
guard: GuardDefinition<TContext, TEvent>;
|
|
134
132
|
evaluate: GuardEvaluator<TContext, TEvent>;
|
|
135
133
|
}
|
|
@@ -161,7 +159,7 @@ export type TransitionTarget = SingleOrArray<string>;
|
|
|
161
159
|
export interface TransitionConfig<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent, TAction extends ParameterizedObject = ParameterizedObject> {
|
|
162
160
|
guard?: GuardConfig<TContext, TExpressionEvent>;
|
|
163
161
|
actions?: BaseActions<TContext, TExpressionEvent, TEvent, TAction>;
|
|
164
|
-
|
|
162
|
+
reenter?: boolean;
|
|
165
163
|
target?: TransitionTarget | undefined;
|
|
166
164
|
meta?: Record<string, any>;
|
|
167
165
|
description?: string;
|
|
@@ -190,7 +188,7 @@ export type ActorBehaviorCreator<TContext extends MachineContext, TEvent extends
|
|
|
190
188
|
id: string;
|
|
191
189
|
data?: any;
|
|
192
190
|
src: string;
|
|
193
|
-
|
|
191
|
+
event: TEvent;
|
|
194
192
|
meta: MetaObject | undefined;
|
|
195
193
|
input: any;
|
|
196
194
|
}) => TActorBehavior;
|
|
@@ -269,7 +267,7 @@ export interface InvokeConfig<TContext extends MachineContext, TEvent extends Ev
|
|
|
269
267
|
/**
|
|
270
268
|
* The transition to take upon the invoked child machine sending an error event.
|
|
271
269
|
*/
|
|
272
|
-
onError?: string | SingleOrArray<TransitionConfigOrTarget<TContext,
|
|
270
|
+
onError?: string | SingleOrArray<TransitionConfigOrTarget<TContext, ErrorEvent<any>, TEvent>>;
|
|
273
271
|
onSnapshot?: string | SingleOrArray<TransitionConfigOrTarget<TContext, SnapshotEvent<any>, TEvent>>;
|
|
274
272
|
/**
|
|
275
273
|
* Meta data related to this invocation
|
|
@@ -341,12 +339,12 @@ export interface StateNodeConfig<TContext extends MachineContext, TEvent extends
|
|
|
341
339
|
*/
|
|
342
340
|
meta?: any;
|
|
343
341
|
/**
|
|
344
|
-
* The data sent with the "done.state._id_" event if this is a final state node.
|
|
342
|
+
* The output data sent with the "done.state._id_" event if this is a final state node.
|
|
345
343
|
*
|
|
346
|
-
* The data will be evaluated with the current `context` and placed on the `.data` property
|
|
344
|
+
* The output data will be evaluated with the current `context` and placed on the `.data` property
|
|
347
345
|
* of the event.
|
|
348
346
|
*/
|
|
349
|
-
|
|
347
|
+
output?: Mapper<TContext, TEvent, any> | PropertyMapper<TContext, TEvent, any>;
|
|
350
348
|
/**
|
|
351
349
|
* The unique ID of the state node, which can be referenced as a transition target via the
|
|
352
350
|
* `#id` syntax.
|
|
@@ -357,7 +355,7 @@ export interface StateNodeConfig<TContext extends MachineContext, TEvent extends
|
|
|
357
355
|
*/
|
|
358
356
|
delimiter?: string;
|
|
359
357
|
/**
|
|
360
|
-
* The order this state node appears. Corresponds to the implicit
|
|
358
|
+
* The order this state node appears. Corresponds to the implicit document order.
|
|
361
359
|
*/
|
|
362
360
|
order?: number;
|
|
363
361
|
/**
|
|
@@ -387,7 +385,7 @@ export interface StateNodeDefinition<TContext extends MachineContext, TEvent ext
|
|
|
387
385
|
exit: BaseActionObject[];
|
|
388
386
|
meta: any;
|
|
389
387
|
order: number;
|
|
390
|
-
|
|
388
|
+
output?: FinalStateNodeConfig<TContext, TEvent>['output'];
|
|
391
389
|
invoke: Array<InvokeDefinition<TContext, TEvent>>;
|
|
392
390
|
description?: string;
|
|
393
391
|
tags: string[];
|
|
@@ -416,7 +414,7 @@ export interface FinalStateNodeConfig<TContext extends MachineContext, TEvent ex
|
|
|
416
414
|
* The data to be sent with the "done.state.<id>" event. The data can be
|
|
417
415
|
* static or dynamic (based on assigners).
|
|
418
416
|
*/
|
|
419
|
-
|
|
417
|
+
output?: Mapper<TContext, TEvent, any> | PropertyMapper<TContext, TEvent, any>;
|
|
420
418
|
}
|
|
421
419
|
export type SimpleOrStateNodeConfig<TContext extends MachineContext, TEvent extends EventObject> = AtomicStateNodeConfig<TContext, TEvent> | StateNodeConfig<TContext, TEvent>;
|
|
422
420
|
export type ActionFunctionMap<TContext extends MachineContext, TEvent extends EventObject, TAction extends ParameterizedObject = ParameterizedObject> = {
|
|
@@ -486,17 +484,12 @@ export interface MachineConfig<TContext extends MachineContext, TEvent extends E
|
|
|
486
484
|
* The machine's own version.
|
|
487
485
|
*/
|
|
488
486
|
version?: string;
|
|
489
|
-
|
|
490
|
-
* If `true`, will use SCXML semantics, such as event token matching.
|
|
491
|
-
*/
|
|
492
|
-
scxml?: boolean;
|
|
493
|
-
schema?: MachineSchema<TContext, TEvent, TActorMap>;
|
|
494
|
-
tsTypes?: TTypesMeta;
|
|
487
|
+
types?: MachineTypes<TContext, TEvent, TActorMap, TTypesMeta>;
|
|
495
488
|
}
|
|
496
489
|
export type ActorMap = Record<string, {
|
|
497
|
-
|
|
490
|
+
output: any;
|
|
498
491
|
}>;
|
|
499
|
-
export interface
|
|
492
|
+
export interface MachineTypes<TContext extends MachineContext, TEvent extends EventObject, TActorMap extends ActorMap = ActorMap, TTypesMeta = TypegenDisabled> {
|
|
500
493
|
context?: TContext;
|
|
501
494
|
actions?: {
|
|
502
495
|
type: string;
|
|
@@ -508,6 +501,7 @@ export interface MachineSchema<TContext extends MachineContext, TEvent extends E
|
|
|
508
501
|
type: string;
|
|
509
502
|
[key: string]: any;
|
|
510
503
|
};
|
|
504
|
+
typegen?: TTypesMeta;
|
|
511
505
|
}
|
|
512
506
|
export interface HistoryStateNode<TContext extends MachineContext> extends StateNode<TContext> {
|
|
513
507
|
history: 'shallow' | 'deep';
|
|
@@ -540,14 +534,13 @@ export interface RaiseActionObject<TContext extends MachineContext, TExpressionE
|
|
|
540
534
|
type: ActionTypes.Raise;
|
|
541
535
|
params: {
|
|
542
536
|
event: TEvent;
|
|
543
|
-
_event: SCXML.Event<TEvent>;
|
|
544
537
|
delay: RaiseActionOptions<TContext, TExpressionEvent>['delay'];
|
|
545
538
|
id: string | number;
|
|
546
539
|
};
|
|
547
540
|
}
|
|
548
541
|
export interface DoneInvokeEvent<TData> extends EventObject {
|
|
549
542
|
type: `done.invoke.${string}`;
|
|
550
|
-
|
|
543
|
+
output: TData;
|
|
551
544
|
}
|
|
552
545
|
export interface ErrorEvent<TErrorData> {
|
|
553
546
|
type: `error.${string}`;
|
|
@@ -565,12 +558,8 @@ export interface ErrorExecutionEvent extends EventObject {
|
|
|
565
558
|
export interface ErrorPlatformEvent extends EventObject {
|
|
566
559
|
data: any;
|
|
567
560
|
}
|
|
568
|
-
export interface SCXMLErrorEvent extends SCXML.Event<any> {
|
|
569
|
-
name: ActionTypes.ErrorExecution | ActionTypes.ErrorPlatform | ActionTypes.ErrorCommunication;
|
|
570
|
-
data: any;
|
|
571
|
-
}
|
|
572
561
|
export interface DoneEventObject extends EventObject {
|
|
573
|
-
|
|
562
|
+
output?: any;
|
|
574
563
|
toString(): string;
|
|
575
564
|
}
|
|
576
565
|
export type DoneEvent = DoneEventObject & string;
|
|
@@ -626,7 +615,6 @@ export interface SendActionObject<TSentEvent extends EventObject = AnyEventObjec
|
|
|
626
615
|
type: 'xstate.send';
|
|
627
616
|
params: {
|
|
628
617
|
to: ActorRef<TSentEvent> | undefined;
|
|
629
|
-
_event: SCXML.Event<TSentEvent>;
|
|
630
618
|
event: TSentEvent;
|
|
631
619
|
delay?: number;
|
|
632
620
|
id: string | number;
|
|
@@ -731,7 +719,7 @@ export interface TransitionDefinition<TContext extends MachineContext, TEvent ex
|
|
|
731
719
|
target: Array<StateNode<TContext, TEvent>> | undefined;
|
|
732
720
|
source: StateNode<TContext, TEvent>;
|
|
733
721
|
actions: BaseActionObject[];
|
|
734
|
-
|
|
722
|
+
reenter: boolean;
|
|
735
723
|
guard?: GuardDefinition<TContext, TEvent>;
|
|
736
724
|
eventType: TEvent['type'] | '*';
|
|
737
725
|
toJSON: () => {
|
|
@@ -782,7 +770,6 @@ export interface Segment<TContext extends MachineContext, TEvent extends EventOb
|
|
|
782
770
|
event: TEvent;
|
|
783
771
|
}
|
|
784
772
|
export interface StateMeta<TEvent extends EventObject> {
|
|
785
|
-
_event: SCXML.Event<TEvent>;
|
|
786
773
|
self: ActorRef<TEvent>;
|
|
787
774
|
system: ActorSystem<any>;
|
|
788
775
|
}
|
|
@@ -790,12 +777,11 @@ export interface StateLike<TContext extends MachineContext> {
|
|
|
790
777
|
value: StateValue;
|
|
791
778
|
context: TContext;
|
|
792
779
|
event: EventObject;
|
|
793
|
-
_event: SCXML.Event<EventObject>;
|
|
794
780
|
}
|
|
795
781
|
export interface StateConfig<TContext extends MachineContext, TEvent extends EventObject> {
|
|
796
782
|
value: StateValue;
|
|
797
783
|
context: TContext;
|
|
798
|
-
|
|
784
|
+
event: TEvent;
|
|
799
785
|
historyValue?: HistoryValue<TContext, TEvent>;
|
|
800
786
|
actions?: BaseActionObject[];
|
|
801
787
|
meta?: any;
|
|
@@ -806,7 +792,7 @@ export interface StateConfig<TContext extends MachineContext, TEvent extends Eve
|
|
|
806
792
|
output?: any;
|
|
807
793
|
tags?: Set<string>;
|
|
808
794
|
machine?: StateMachine<TContext, TEvent, any, any, any>;
|
|
809
|
-
_internalQueue?: Array<
|
|
795
|
+
_internalQueue?: Array<TEvent>;
|
|
810
796
|
}
|
|
811
797
|
export interface InterpreterOptions<_TActorBehavior extends AnyActorBehavior> {
|
|
812
798
|
/**
|
|
@@ -850,68 +836,6 @@ export interface InterpreterOptions<_TActorBehavior extends AnyActorBehavior> {
|
|
|
850
836
|
src?: string;
|
|
851
837
|
}
|
|
852
838
|
export type AnyInterpreter = Interpreter<any>;
|
|
853
|
-
export declare namespace SCXML {
|
|
854
|
-
interface Event<TEvent extends EventObject> {
|
|
855
|
-
/**
|
|
856
|
-
* This is a character string giving the name of the event.
|
|
857
|
-
* The SCXML Processor must set the name field to the name of this event.
|
|
858
|
-
* It is what is matched against the 'event' attribute of <transition>.
|
|
859
|
-
* Note that transitions can do additional tests by using the value of this field
|
|
860
|
-
* inside boolean expressions in the 'cond' attribute.
|
|
861
|
-
*/
|
|
862
|
-
name: string;
|
|
863
|
-
/**
|
|
864
|
-
* This field describes the event type.
|
|
865
|
-
* The SCXML Processor must set it to: "platform" (for events raised by the platform itself, such as error events),
|
|
866
|
-
* "internal" (for events raised by <raise> and <send> with target '_internal')
|
|
867
|
-
* or "external" (for all other events).
|
|
868
|
-
*/
|
|
869
|
-
type: 'platform' | 'internal' | 'external';
|
|
870
|
-
/**
|
|
871
|
-
* If the sending entity has specified a value for this, the Processor must set this field to that value
|
|
872
|
-
* (see C Event I/O Processors for details).
|
|
873
|
-
* Otherwise, in the case of error events triggered by a failed attempt to send an event,
|
|
874
|
-
* the Processor must set this field to the send id of the triggering <send> element.
|
|
875
|
-
* Otherwise it must leave it blank.
|
|
876
|
-
*/
|
|
877
|
-
sendid?: string;
|
|
878
|
-
/**
|
|
879
|
-
* This is a URI, equivalent to the 'target' attribute on the <send> element.
|
|
880
|
-
* For external events, the SCXML Processor should set this field to a value which,
|
|
881
|
-
* when used as the value of 'target', will allow the receiver of the event to <send>
|
|
882
|
-
* a response back to the originating entity via the Event I/O Processor specified in 'origintype'.
|
|
883
|
-
* For internal and platform events, the Processor must leave this field blank.
|
|
884
|
-
*/
|
|
885
|
-
origin?: ActorRef<any>;
|
|
886
|
-
/**
|
|
887
|
-
* This is equivalent to the 'type' field on the <send> element.
|
|
888
|
-
* For external events, the SCXML Processor should set this field to a value which,
|
|
889
|
-
* when used as the value of 'type', will allow the receiver of the event to <send>
|
|
890
|
-
* a response back to the originating entity at the URI specified by 'origin'.
|
|
891
|
-
* For internal and platform events, the Processor must leave this field blank.
|
|
892
|
-
*/
|
|
893
|
-
origintype?: string;
|
|
894
|
-
/**
|
|
895
|
-
* If this event is generated from an invoked child process, the SCXML Processor
|
|
896
|
-
* must set this field to the invoke id of the invocation that triggered the child process.
|
|
897
|
-
* Otherwise it must leave it blank.
|
|
898
|
-
*/
|
|
899
|
-
invokeid?: string;
|
|
900
|
-
/**
|
|
901
|
-
* This field contains whatever data the sending entity chose to include in this event.
|
|
902
|
-
* The receiving SCXML Processor should reformat this data to match its data model,
|
|
903
|
-
* but must not otherwise modify it.
|
|
904
|
-
*
|
|
905
|
-
* If the conversion is not possible, the Processor must leave the field blank
|
|
906
|
-
* and must place an error 'error.execution' in the internal event queue.
|
|
907
|
-
*/
|
|
908
|
-
data: TEvent;
|
|
909
|
-
/**
|
|
910
|
-
* @private
|
|
911
|
-
*/
|
|
912
|
-
$$type: 'scxml';
|
|
913
|
-
}
|
|
914
|
-
}
|
|
915
839
|
export type Observer<T> = {
|
|
916
840
|
next?: (value: T) => void;
|
|
917
841
|
error?: (err: any) => void;
|
|
@@ -979,6 +903,7 @@ export interface ActorBehavior<TEvent extends EventObject, TSnapshot = any, TInt
|
|
|
979
903
|
* Serialized internal state used for persistence & restoration
|
|
980
904
|
*/
|
|
981
905
|
TPersisted = TInternalState, TSystem extends ActorSystem<any> = ActorSystem<any>> {
|
|
906
|
+
config?: unknown;
|
|
982
907
|
transition: (state: TInternalState, message: TEvent | LifecycleSignal, ctx: ActorContext<TEvent, TSnapshot, TSystem>) => TInternalState;
|
|
983
908
|
getInitialState: (actorCtx: ActorContext<TEvent, TSnapshot, any>, input: any) => TInternalState;
|
|
984
909
|
restoreState?: (persistedState: TPersisted, actorCtx: ActorContext<TEvent, TSnapshot>) => TInternalState;
|
|
@@ -994,11 +919,11 @@ TPersisted = TInternalState, TSystem extends ActorSystem<any> = ActorSystem<any>
|
|
|
994
919
|
getPersistedState?: (state: TInternalState) => TPersisted;
|
|
995
920
|
}
|
|
996
921
|
export type AnyActorBehavior = ActorBehavior<any, any, any, any>;
|
|
997
|
-
export type SnapshotFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends ActorRef<infer _, infer TSnapshot> ? TSnapshot : R extends Interpreter<infer TBehavior> ? SnapshotFrom<TBehavior> : R extends ActorBehavior<infer _, infer TSnapshot> ? TSnapshot : R extends ActorContext<infer _, infer TSnapshot, infer __> ? TSnapshot : never : never;
|
|
922
|
+
export type SnapshotFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends ActorRef<infer _, infer TSnapshot> ? TSnapshot : R extends Interpreter<infer TBehavior> ? SnapshotFrom<TBehavior> : R extends StateMachine<infer _, infer __, infer ___, infer ____, infer _____> ? StateFrom<R> : R extends ActorBehavior<infer _, infer TSnapshot, infer __, infer ___, infer ____> ? TSnapshot : R extends ActorContext<infer _, infer TSnapshot, infer __> ? TSnapshot : never : never;
|
|
998
923
|
export type EventFromBehavior<TBehavior extends ActorBehavior<any, any>> = TBehavior extends ActorBehavior<infer TEvent, infer _> ? TEvent : never;
|
|
999
924
|
export type PersistedStateFrom<TBehavior extends ActorBehavior<any, any>> = TBehavior extends ActorBehavior<infer _TEvent, infer _TSnapshot, infer _TInternalState, infer TPersisted> ? TPersisted : never;
|
|
1000
925
|
export type InternalStateFrom<TBehavior extends ActorBehavior<any, any>> = TBehavior extends ActorBehavior<infer _TEvent, infer _TSnapshot, infer TInternalState, infer _TPersisted> ? TInternalState : never;
|
|
1001
|
-
type ResolveEventType<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer _, infer TEvent, infer __, infer ___, infer ____> ? TEvent : R extends State<infer _, infer TEvent, infer __> ? TEvent : R extends
|
|
926
|
+
type ResolveEventType<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer _, infer TEvent, infer __, infer ___, infer ____> ? TEvent : R extends State<infer _, infer TEvent, infer __> ? TEvent : R extends ActorRef<infer TEvent, infer _> ? TEvent : never : never;
|
|
1002
927
|
export type EventFrom<T, K extends Prop<TEvent, 'type'> = never, TEvent extends EventObject = ResolveEventType<T>> = IsNever<K> extends true ? TEvent : ExtractEvent<TEvent, K>;
|
|
1003
928
|
export type ContextFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer _, infer __, infer ___, infer ____> ? TContext : R extends State<infer TContext, infer _, infer __> ? TContext : R extends Interpreter<infer TBehavior> ? TBehavior extends StateMachine<infer TContext, infer _> ? TContext : never : never : never;
|
|
1004
929
|
export type InferEvent<E extends EventObject> = {
|
|
@@ -1010,6 +935,7 @@ export type InferEvent<E extends EventObject> = {
|
|
|
1010
935
|
}[E['type']];
|
|
1011
936
|
export type TODO = any;
|
|
1012
937
|
export type StateValueFrom<TMachine extends AnyStateMachine> = Parameters<StateFrom<TMachine>['matches']>[0];
|
|
938
|
+
export type TagsFrom<TMachine extends AnyStateMachine> = Parameters<StateFrom<TMachine>['hasTag']>[0];
|
|
1013
939
|
export type StateFromMachine<TMachine extends AnyStateMachine> = TMachine['initialState'];
|
|
1014
940
|
export interface ActorSystemInfo {
|
|
1015
941
|
actors: Record<string, AnyActorRef>;
|
|
@@ -1021,7 +947,7 @@ export interface ActorSystem<T extends ActorSystemInfo> {
|
|
|
1021
947
|
_set: <K extends keyof T['actors']>(key: K, actorRef: T['actors'][K]) => void;
|
|
1022
948
|
get: <K extends keyof T['actors']>(key: K) => T['actors'][K] | undefined;
|
|
1023
949
|
}
|
|
1024
|
-
export type PersistedMachineState<TState extends AnyState> = Pick<TState, 'value' | 'output' | 'context' | '
|
|
950
|
+
export type PersistedMachineState<TState extends AnyState> = Pick<TState, 'value' | 'output' | 'context' | 'event' | 'done' | 'historyValue'> & {
|
|
1025
951
|
children: {
|
|
1026
952
|
[K in keyof TState['children']]: {
|
|
1027
953
|
state: any;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AnyActorBehavior, AnyState } from './index.ts';
|
|
2
2
|
import { NULL_EVENT } from './constants.ts';
|
|
3
3
|
import type { StateNode } from './StateNode.ts';
|
|
4
|
-
import type { ActorBehavior, EventObject, EventType, InvokeConfig, MachineContext, Mapper, Observer, PropertyMapper,
|
|
4
|
+
import type { ActorBehavior, AnyEventObject, EventObject, EventType, InvokeConfig, MachineContext, Mapper, Observer, PropertyMapper, ErrorEvent, SingleOrArray, StateLike, StateValue, Subscribable, TransitionConfig, TransitionConfigTarget } from './types.ts';
|
|
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;
|
|
7
7
|
export declare function toStatePath(stateId: string | string[], delimiter: string): string[];
|
|
@@ -27,7 +27,7 @@ export declare function toStatePaths(stateValue: StateValue | undefined): string
|
|
|
27
27
|
export declare function flatten<T>(array: Array<T | T[]>): T[];
|
|
28
28
|
export declare function toArrayStrict<T>(value: T[] | T): T[];
|
|
29
29
|
export declare function toArray<T>(value: T[] | T | undefined): T[];
|
|
30
|
-
export declare function mapContext<TContext extends MachineContext, TEvent extends EventObject>(mapper: Mapper<TContext, TEvent, any> | PropertyMapper<TContext, TEvent, any>, context: TContext,
|
|
30
|
+
export declare function mapContext<TContext extends MachineContext, TEvent extends EventObject>(mapper: Mapper<TContext, TEvent, any> | PropertyMapper<TContext, TEvent, any>, context: TContext, event: TEvent): any;
|
|
31
31
|
export declare function isBuiltInEvent(eventType: EventType): boolean;
|
|
32
32
|
export declare function isPromiseLike(value: any): value is PromiseLike<any>;
|
|
33
33
|
export declare function isBehavior(value: any): value is ActorBehavior<any, any>;
|
|
@@ -38,9 +38,7 @@ export declare function isFunction(value: any): value is Function;
|
|
|
38
38
|
export declare function isString(value: any): value is string;
|
|
39
39
|
export declare function isObservable<T>(value: any): value is Subscribable<T>;
|
|
40
40
|
export declare const uniqueId: () => string;
|
|
41
|
-
export declare function
|
|
42
|
-
export declare function isSCXMLErrorEvent(event: SCXML.Event<any>): event is SCXMLErrorEvent;
|
|
43
|
-
export declare function toSCXMLEvent<TEvent extends EventObject>(event: TEvent | SCXML.Event<TEvent>, scxmlEvent?: Partial<SCXML.Event<TEvent>>): SCXML.Event<TEvent>;
|
|
41
|
+
export declare function isErrorEvent(event: AnyEventObject): event is ErrorEvent<any>;
|
|
44
42
|
export declare function toTransitionConfigArray<TContext extends MachineContext, TEvent extends EventObject>(event: TEvent['type'] | typeof NULL_EVENT | '*', configLike: SingleOrArray<TransitionConfig<TContext, TEvent> | TransitionConfigTarget>): Array<TransitionConfig<TContext, TEvent> & {
|
|
45
43
|
event: TEvent['type'] | typeof NULL_EVENT | '*';
|
|
46
44
|
}>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ActorRef, SnapshotFrom } from '.';
|
|
2
|
+
interface WaitForOptions {
|
|
3
|
+
/**
|
|
4
|
+
* How long to wait before rejecting, if no emitted
|
|
5
|
+
* state satisfies the predicate.
|
|
6
|
+
*
|
|
7
|
+
* @default 10_000 (10 seconds)
|
|
8
|
+
*/
|
|
9
|
+
timeout: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Subscribes to an actor ref and waits for its emitted value to satisfy
|
|
13
|
+
* a predicate, and then resolves with that value.
|
|
14
|
+
* Will throw if the desired state is not reached after a timeout
|
|
15
|
+
* (defaults to 10 seconds).
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```js
|
|
19
|
+
* const state = await waitFor(someService, state => {
|
|
20
|
+
* return state.hasTag('loaded');
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* state.hasTag('loaded'); // true
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @param actorRef The actor ref to subscribe to
|
|
27
|
+
* @param predicate Determines if a value matches the condition to wait for
|
|
28
|
+
* @param options
|
|
29
|
+
* @returns A promise that eventually resolves to the emitted value
|
|
30
|
+
* that matches the condition
|
|
31
|
+
*/
|
|
32
|
+
export declare function waitFor<TActorRef extends ActorRef<any, any>>(actorRef: TActorRef, predicate: (emitted: SnapshotFrom<TActorRef>) => boolean, options?: Partial<WaitForOptions>): Promise<SnapshotFrom<TActorRef>>;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var IS_PRODUCTION = "production" === 'production';
|
|
4
|
+
|
|
5
|
+
// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
|
|
6
|
+
function getGlobal() {
|
|
7
|
+
if (typeof globalThis !== 'undefined') {
|
|
8
|
+
return globalThis;
|
|
9
|
+
}
|
|
10
|
+
if (typeof self !== 'undefined') {
|
|
11
|
+
return self;
|
|
12
|
+
}
|
|
13
|
+
if (typeof window !== 'undefined') {
|
|
14
|
+
return window;
|
|
15
|
+
}
|
|
16
|
+
if (typeof global !== 'undefined') {
|
|
17
|
+
return global;
|
|
18
|
+
}
|
|
19
|
+
if (!IS_PRODUCTION) {
|
|
20
|
+
console.warn('XState could not find a global object in this environment. Please let the maintainers know and raise an issue here: https://github.com/statelyai/xstate/issues');
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function getDevTools() {
|
|
24
|
+
var w = getGlobal();
|
|
25
|
+
if (!!w.__xstate__) {
|
|
26
|
+
return w.__xstate__;
|
|
27
|
+
}
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
function registerService(service) {
|
|
31
|
+
if (typeof window === 'undefined') {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
var devTools = getDevTools();
|
|
35
|
+
if (devTools) {
|
|
36
|
+
devTools.register(service);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
var devToolsAdapter = function devToolsAdapter(service) {
|
|
40
|
+
if (typeof window === 'undefined') {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
var devTools = getDevTools();
|
|
44
|
+
if (devTools) {
|
|
45
|
+
devTools.register(service);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
exports.IS_PRODUCTION = IS_PRODUCTION;
|
|
50
|
+
exports.devToolsAdapter = devToolsAdapter;
|
|
51
|
+
exports.getGlobal = getGlobal;
|
|
52
|
+
exports.registerService = registerService;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xstate.cjs.d.mts","sourceRoot":"","sources":["./declarations/src/index.d.ts"],"names":[],"mappings":"AAAA"}
|
package/dist/xstate.cjs.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xstate.cjs.d.ts","sourceRoot":"","sources":["./declarations/src/index.d.ts"],"names":[],"mappings":"AAAA"}
|