xstate 5.0.0-beta.48 → 5.0.0-beta.49
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.js +2 -2
- package/actions/dist/xstate-actions.development.cjs.js +2 -2
- package/actions/dist/xstate-actions.development.esm.js +2 -2
- package/actions/dist/xstate-actions.esm.js +2 -2
- 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.js +52 -71
- package/actors/dist/xstate-actors.development.cjs.js +52 -71
- package/actors/dist/xstate-actors.development.esm.js +52 -71
- package/actors/dist/xstate-actors.esm.js +52 -71
- package/actors/dist/xstate-actors.umd.min.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/declarations/src/State.d.ts +20 -17
- package/dist/declarations/src/StateMachine.d.ts +13 -14
- package/dist/declarations/src/actors/callback.d.ts +2 -5
- package/dist/declarations/src/actors/index.d.ts +3 -3
- package/dist/declarations/src/actors/promise.d.ts +4 -4
- package/dist/declarations/src/createMachine.d.ts +17 -2
- package/dist/declarations/src/interpreter.d.ts +1 -2
- package/dist/declarations/src/setup.d.ts +18 -2
- package/dist/declarations/src/stateUtils.d.ts +1 -1
- package/dist/declarations/src/types.d.ts +14 -10
- package/dist/declarations/src/utils.d.ts +0 -1
- package/dist/{raise-286581d5.development.esm.js → raise-1873c645.development.esm.js} +2 -6
- package/dist/{raise-0eafc1df.development.cjs.js → raise-495f4b9f.development.cjs.js} +2 -6
- package/dist/{raise-cd0dde81.cjs.js → raise-8f9c4a5a.cjs.js} +2 -6
- package/dist/{raise-84fd7a92.esm.js → raise-e4cc6d4f.esm.js} +2 -6
- package/dist/{send-f0a3179c.development.esm.js → send-0a381ca2.development.esm.js} +1 -1
- package/dist/{send-ae491737.esm.js → send-22880315.esm.js} +1 -1
- package/dist/{send-32a63473.development.cjs.js → send-8d30b415.development.cjs.js} +1 -1
- package/dist/{send-355ba004.cjs.js → send-8ed5c8b2.cjs.js} +1 -1
- package/dist/xstate.cjs.js +13 -12
- package/dist/xstate.development.cjs.js +13 -12
- package/dist/xstate.development.esm.js +15 -14
- package/dist/xstate.esm.js +15 -14
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.js +1 -1
- package/guards/dist/xstate-guards.development.cjs.js +1 -1
- package/guards/dist/xstate-guards.development.esm.js +1 -1
- package/guards/dist/xstate-guards.esm.js +1 -1
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ActorRef, AnyEventObject, Snapshot } from "../types.js";
|
|
2
|
-
export { fromCallback, type CallbackActorLogic } from "./callback.js";
|
|
3
|
-
export { fromEventObservable, fromObservable, type ObservableActorLogic } from "./observable.js";
|
|
4
|
-
export { fromPromise, type PromiseActorLogic } from "./promise.js";
|
|
2
|
+
export { fromCallback, type CallbackActorLogic, type CallbackSnapshot } from "./callback.js";
|
|
3
|
+
export { fromEventObservable, fromObservable, type ObservableActorLogic, type ObservableSnapshot } from "./observable.js";
|
|
4
|
+
export { fromPromise, type PromiseActorLogic, type PromiseSnapshot } from "./promise.js";
|
|
5
5
|
export { fromTransition, type TransitionActorLogic, type TransitionSnapshot } from "./transition.js";
|
|
6
6
|
export declare function createEmptyActor(): ActorRef<AnyEventObject, Snapshot<undefined>>;
|
|
@@ -3,13 +3,13 @@ import { XSTATE_STOP } from "../constants.js";
|
|
|
3
3
|
export type PromiseSnapshot<TOutput, TInput> = Snapshot<TOutput> & {
|
|
4
4
|
input: TInput | undefined;
|
|
5
5
|
};
|
|
6
|
-
declare const
|
|
7
|
-
declare const
|
|
6
|
+
declare const XSTATE_PROMISE_RESOLVE = "xstate.promise.resolve";
|
|
7
|
+
declare const XSTATE_PROMISE_REJECT = "xstate.promise.reject";
|
|
8
8
|
export type PromiseActorEvents<T> = {
|
|
9
|
-
type: typeof
|
|
9
|
+
type: typeof XSTATE_PROMISE_RESOLVE;
|
|
10
10
|
data: T;
|
|
11
11
|
} | {
|
|
12
|
-
type: typeof
|
|
12
|
+
type: typeof XSTATE_PROMISE_REJECT;
|
|
13
13
|
data: any;
|
|
14
14
|
} | {
|
|
15
15
|
type: typeof XSTATE_STOP;
|
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
import { StateMachine } from "./StateMachine.js";
|
|
2
2
|
import { ResolveTypegenMeta, TypegenConstraint, TypegenDisabled } from "./typegenTypes.js";
|
|
3
|
-
import { AnyActorRef, AnyEventObject, Cast, InternalMachineImplementations, MachineConfig, MachineContext, NonReducibleUnknown, ParameterizedObject, Prop, ProvidedActor, ToChildren } from "./types.js";
|
|
3
|
+
import { AnyActorRef, AnyEventObject, Cast, InternalMachineImplementations, IsNever, MachineConfig, MachineContext, NonReducibleUnknown, ParameterizedObject, Prop, ProvidedActor, StateValue, ToChildren } from "./types.js";
|
|
4
|
+
type TestValue = string | {
|
|
5
|
+
[k: string]: TestValue | undefined;
|
|
6
|
+
};
|
|
7
|
+
type _GroupTestValues<TTestValue extends string | TestValue> = TTestValue extends string ? TTestValue extends `${string}.${string}` ? [never, never] : [TTestValue, never] : [never, TTestValue];
|
|
8
|
+
type GroupTestValues<TTestValue extends string | TestValue> = {
|
|
9
|
+
leafCandidates: _GroupTestValues<TTestValue>[0];
|
|
10
|
+
nonLeaf: _GroupTestValues<TTestValue>[1];
|
|
11
|
+
};
|
|
12
|
+
type FilterLeafValues<TLeafCandidate extends string, TNonLeaf extends {
|
|
13
|
+
[k: string]: TestValue | undefined;
|
|
14
|
+
}> = IsNever<TNonLeaf> extends true ? TLeafCandidate : TLeafCandidate extends string ? TLeafCandidate extends keyof TNonLeaf ? never : TLeafCandidate : never;
|
|
15
|
+
type ToStateValue<TTestValue extends string | TestValue> = FilterLeafValues<GroupTestValues<TTestValue>['leafCandidates'], GroupTestValues<TTestValue>['nonLeaf']> | (IsNever<GroupTestValues<TTestValue>['nonLeaf']> extends false ? {
|
|
16
|
+
[K in keyof GroupTestValues<TTestValue>['nonLeaf']]: ToStateValue<NonNullable<GroupTestValues<TTestValue>['nonLeaf'][K]>>;
|
|
17
|
+
} : never);
|
|
4
18
|
export declare function createMachine<TContext extends MachineContext, TEvent extends AnyEventObject, // TODO: consider using a stricter `EventObject` here
|
|
5
|
-
TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TTag extends string, TInput, TOutput extends NonReducibleUnknown, TTypesMeta extends TypegenConstraint = TypegenDisabled>(config: MachineConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay, TTag, TInput, TOutput, TTypesMeta>, implementations?: InternalMachineImplementations<TContext, ResolveTypegenMeta<TTypesMeta, TEvent, TActor, TAction, TGuard, TDelay, TTag>>): StateMachine<TContext, TEvent, Cast<ToChildren<TActor>, Record<string, AnyActorRef | undefined>>, TActor, TAction, TGuard, TDelay, Prop<ResolveTypegenMeta<TTypesMeta, TEvent, TActor, TAction, TGuard, TDelay, TTag>['resolved'], 'tags'> & string, TInput, TOutput, ResolveTypegenMeta<TTypesMeta, TEvent, TActor, TAction, TGuard, TDelay, TTag>>;
|
|
19
|
+
TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TTag extends string, TInput, TOutput extends NonReducibleUnknown, TTypesMeta extends TypegenConstraint = TypegenDisabled>(config: MachineConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay, TTag, TInput, TOutput, TTypesMeta>, implementations?: InternalMachineImplementations<TContext, ResolveTypegenMeta<TTypesMeta, TEvent, TActor, TAction, TGuard, TDelay, TTag>>): StateMachine<TContext, TEvent, Cast<ToChildren<TActor>, Record<string, AnyActorRef | undefined>>, TActor, TAction, TGuard, TDelay, 'matchesStates' extends keyof TTypesMeta ? ToStateValue<Cast<TTypesMeta['matchesStates'], TestValue>> : StateValue, Prop<ResolveTypegenMeta<TTypesMeta, TEvent, TActor, TAction, TGuard, TDelay, TTag>['resolved'], 'tags'> & string, TInput, TOutput, ResolveTypegenMeta<TTypesMeta, TEvent, TActor, TAction, TGuard, TDelay, TTag>>;
|
|
20
|
+
export {};
|
|
@@ -199,8 +199,7 @@ export declare class Actor<TLogic extends AnyActorLogic> implements ActorRef<Eve
|
|
|
199
199
|
* @param logic - The actor logic to create an actor from. For a state machine actor logic creator, see {@link createMachine}. Other actor logic creators include {@link fromCallback}, {@link fromEventObservable}, {@link fromObservable}, {@link fromPromise}, and {@link fromTransition}.
|
|
200
200
|
* @param options - Actor options
|
|
201
201
|
*/
|
|
202
|
-
export declare function createActor<TLogic extends AnyActorLogic>(logic: TLogic, options?: ActorOptions<TLogic>): Actor<TLogic>;
|
|
203
|
-
export declare function createActor<TMachine extends AnyStateMachine>(machine: AreAllImplementationsAssumedToBeProvided<TMachine['__TResolvedTypesMeta']> extends true ? TMachine : MissingImplementationsError<TMachine['__TResolvedTypesMeta']>, options?: ActorOptions<TMachine>): Actor<TMachine>;
|
|
202
|
+
export declare function createActor<TLogic extends AnyActorLogic>(logic: TLogic extends AnyStateMachine ? AreAllImplementationsAssumedToBeProvided<TLogic['__TResolvedTypesMeta']> extends true ? TLogic : MissingImplementationsError<TLogic['__TResolvedTypesMeta']> : TLogic, options?: ActorOptions<TLogic>): Actor<TLogic>;
|
|
204
203
|
/**
|
|
205
204
|
* Creates a new Interpreter instance for the given machine with the provided options, if any.
|
|
206
205
|
*
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { StateMachine } from "./StateMachine.js";
|
|
2
2
|
import { GuardPredicate } from "./guards.js";
|
|
3
3
|
import { ResolveTypegenMeta, TypegenDisabled } from "./typegenTypes.js";
|
|
4
|
-
import { ActionFunction, AnyActorLogic, AnyActorRef, AnyEventObject, Cast, DelayConfig, Invert, IsNever, MachineConfig, MachineContext, NonReducibleUnknown, ParameterizedObject, SetupTypes, ToChildren, Values } from "./types.js";
|
|
4
|
+
import { ActionFunction, AnyActorLogic, AnyActorRef, AnyEventObject, Cast, ConditionalRequired, DelayConfig, Invert, IsNever, MachineConfig, MachineContext, NonReducibleUnknown, ParameterizedObject, SetupTypes, StateSchema, ToChildren, Values } from "./types.js";
|
|
5
5
|
type ToParameterizedObject<TParameterizedMap extends Record<string, ParameterizedObject['params'] | undefined>> = Values<{
|
|
6
6
|
[K in keyof TParameterizedMap & string]: {
|
|
7
7
|
type: K;
|
|
@@ -16,6 +16,22 @@ type ToProvidedActor<TChildrenMap extends Record<string, string>, TActors extend
|
|
|
16
16
|
id: IsNever<TChildrenMap> extends true ? string | undefined : K extends keyof Invert<TChildrenMap> ? Invert<TChildrenMap>[K] : string | undefined;
|
|
17
17
|
};
|
|
18
18
|
}>;
|
|
19
|
+
type _GroupStateKeys<T extends StateSchema, S extends keyof T['states']> = S extends any ? T['states'][S] extends {
|
|
20
|
+
type: 'history';
|
|
21
|
+
} ? [never, never] : T extends {
|
|
22
|
+
type: 'parallel';
|
|
23
|
+
} ? [S, never] : 'states' extends keyof T['states'][S] ? [S, never] : [never, S] : never;
|
|
24
|
+
type GroupStateKeys<T extends StateSchema, S extends keyof T['states']> = {
|
|
25
|
+
nonLeaf: _GroupStateKeys<T, S & string>[0];
|
|
26
|
+
leaf: _GroupStateKeys<T, S & string>[1];
|
|
27
|
+
};
|
|
28
|
+
type ToStateValue<T extends StateSchema> = T extends {
|
|
29
|
+
states: Record<infer S, any>;
|
|
30
|
+
} ? IsNever<S> extends true ? {} : GroupStateKeys<T, S>['leaf'] | (IsNever<GroupStateKeys<T, S>['nonLeaf']> extends false ? ConditionalRequired<{
|
|
31
|
+
[K in GroupStateKeys<T, S>['nonLeaf']]?: ToStateValue<T['states'][K]>;
|
|
32
|
+
}, T extends {
|
|
33
|
+
type: 'parallel';
|
|
34
|
+
} ? true : false> : never) : {};
|
|
19
35
|
export declare function setup<TContext extends MachineContext, TEvent extends AnyEventObject, // TODO: consider using a stricter `EventObject` here
|
|
20
36
|
TActors extends Record<Values<TChildrenMap>, AnyActorLogic>, TActions extends Record<string, ParameterizedObject['params'] | undefined>, TGuards extends Record<string, ParameterizedObject['params'] | undefined>, TDelay extends string, TTag extends string, TInput, TOutput extends NonReducibleUnknown, TChildrenMap extends Record<string, string> = never>({ actors, actions, guards, delays }: {
|
|
21
37
|
types?: SetupTypes<TContext, TEvent, TChildrenMap, TTag, TInput, TOutput>;
|
|
@@ -30,6 +46,6 @@ TActors extends Record<Values<TChildrenMap>, AnyActorLogic>, TActions extends Re
|
|
|
30
46
|
[K in TDelay]: DelayConfig<TContext, TEvent, ToParameterizedObject<TActions>['params'], TEvent>;
|
|
31
47
|
};
|
|
32
48
|
}): {
|
|
33
|
-
createMachine: <const TConfig extends MachineConfig<TContext, TEvent, ToProvidedActor<TChildrenMap, TActors>, ToParameterizedObject<TActions>, ToParameterizedObject<TGuards>, TDelay, TTag, TInput, TOutput, ResolveTypegenMeta<TypegenDisabled, TEvent, ToProvidedActor<TChildrenMap, TActors>, ToParameterizedObject<TActions>, ToParameterizedObject<TGuards>, TDelay, TTag>>>(config: TConfig) => StateMachine<TContext, TEvent, Cast<ToChildren<ToProvidedActor<TChildrenMap, TActors>>, Record<string, AnyActorRef | undefined>>, ToProvidedActor<TChildrenMap, TActors>, ToParameterizedObject<TActions>, ToParameterizedObject<TGuards>, TDelay, TTag, TInput, TOutput, ResolveTypegenMeta<TypegenDisabled, TEvent, ToProvidedActor<TChildrenMap, TActors>, ToParameterizedObject<TActions>, ToParameterizedObject<TGuards>, TDelay, TTag>>;
|
|
49
|
+
createMachine: <const TConfig extends MachineConfig<TContext, TEvent, ToProvidedActor<TChildrenMap, TActors>, ToParameterizedObject<TActions>, ToParameterizedObject<TGuards>, TDelay, TTag, TInput, TOutput, ResolveTypegenMeta<TypegenDisabled, TEvent, ToProvidedActor<TChildrenMap, TActors>, ToParameterizedObject<TActions>, ToParameterizedObject<TGuards>, TDelay, TTag>>>(config: TConfig) => StateMachine<TContext, TEvent, Cast<ToChildren<ToProvidedActor<TChildrenMap, TActors>>, Record<string, AnyActorRef | undefined>>, ToProvidedActor<TChildrenMap, TActors>, ToParameterizedObject<TActions>, ToParameterizedObject<TGuards>, TDelay, ToStateValue<TConfig>, TTag, TInput, TOutput, ResolveTypegenMeta<TypegenDisabled, TEvent, ToProvidedActor<TChildrenMap, TActors>, ToParameterizedObject<TActions>, ToParameterizedObject<TGuards>, TDelay, TTag>>;
|
|
34
50
|
};
|
|
35
51
|
export {};
|
|
@@ -40,7 +40,7 @@ export declare function getStateNodes<TContext extends MachineContext, TEvent ex
|
|
|
40
40
|
export declare function transitionAtomicNode<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode, stateValue: string, state: MachineSnapshot<TContext, TEvent, any, any, any, any>, event: TEvent): Array<TransitionDefinition<TContext, TEvent>> | undefined;
|
|
41
41
|
export declare function transitionCompoundNode<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode, stateValue: StateValueMap, state: MachineSnapshot<TContext, TEvent, any, any, any, any>, event: TEvent): Array<TransitionDefinition<TContext, TEvent>> | undefined;
|
|
42
42
|
export declare function transitionParallelNode<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode, stateValue: StateValueMap, state: MachineSnapshot<TContext, TEvent, any, any, any, any>, event: TEvent): Array<TransitionDefinition<TContext, TEvent>> | undefined;
|
|
43
|
-
export declare function transitionNode<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode, stateValue: StateValue, state: MachineSnapshot<TContext, TEvent, any, any, any, any>, event: TEvent): Array<TransitionDefinition<TContext, TEvent>> | undefined;
|
|
43
|
+
export declare function transitionNode<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode, stateValue: StateValue, state: MachineSnapshot<TContext, TEvent, any, any, any, any, any>, event: TEvent): Array<TransitionDefinition<TContext, TEvent>> | undefined;
|
|
44
44
|
export declare function removeConflictingTransitions(enabledTransitions: Array<AnyTransitionDefinition>, stateNodeSet: Set<AnyStateNode>, historyValue: AnyHistoryValue): Array<AnyTransitionDefinition>;
|
|
45
45
|
/**
|
|
46
46
|
* https://www.w3.org/TR/scxml/#microstepProcedure
|
|
@@ -81,13 +81,13 @@ export interface UnifiedArg<TContext extends MachineContext, TExpressionEvent ex
|
|
|
81
81
|
context: TContext;
|
|
82
82
|
event: TExpressionEvent;
|
|
83
83
|
self: ActorRef<TEvent, MachineSnapshot<TContext, TEvent, Record<string, AnyActorRef | undefined>, // TODO: this should be replaced with `TChildren`
|
|
84
|
-
string, unknown>>;
|
|
84
|
+
StateValue, string, unknown>>;
|
|
85
85
|
system: ActorSystem<any>;
|
|
86
86
|
}
|
|
87
87
|
export type MachineContext = Record<string, any>;
|
|
88
88
|
export interface ActionArgs<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject> extends UnifiedArg<TContext, TExpressionEvent, TEvent> {
|
|
89
89
|
}
|
|
90
|
-
export type InputFrom<T extends AnyActorLogic> = T extends StateMachine<infer _TContext, infer _TEvent, infer _TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TTag, infer TInput, infer _TOutput, infer _TResolvedTypesMeta> ? TInput : T extends ActorLogic<infer _TSnapshot, infer _TEvent, infer TInput, infer _TSystem> ? TInput : never;
|
|
90
|
+
export type InputFrom<T extends AnyActorLogic> = T extends StateMachine<infer _TContext, infer _TEvent, infer _TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TStateValue, infer _TTag, infer TInput, infer _TOutput, infer _TResolvedTypesMeta> ? TInput : T extends ActorLogic<infer _TSnapshot, infer _TEvent, infer TInput, infer _TSystem> ? TInput : never;
|
|
91
91
|
export type OutputFrom<T extends AnyActorLogic> = T extends ActorLogic<infer TSnapshot, infer _TEvent, infer _TInput, infer _TSystem> ? (TSnapshot & {
|
|
92
92
|
status: 'done';
|
|
93
93
|
})['output'] : never;
|
|
@@ -349,7 +349,7 @@ export interface StateMachineDefinition<TContext extends MachineContext, TEvent
|
|
|
349
349
|
}
|
|
350
350
|
export type AnyStateNode = StateNode<any, any>;
|
|
351
351
|
export type AnyStateNodeDefinition = StateNodeDefinition<any, any>;
|
|
352
|
-
export type AnyMachineSnapshot = MachineSnapshot<any, any, any, any, any, any>;
|
|
352
|
+
export type AnyMachineSnapshot = MachineSnapshot<any, any, any, any, any, any, any>;
|
|
353
353
|
/** @deprecated use `AnyMachineSnapshot` instead */
|
|
354
354
|
export type AnyState = AnyMachineSnapshot;
|
|
355
355
|
export type AnyStateMachine = StateMachine<any, // context
|
|
@@ -359,6 +359,7 @@ any, // actor
|
|
|
359
359
|
any, // action
|
|
360
360
|
any, // guard
|
|
361
361
|
any, // delay
|
|
362
|
+
any, // state value
|
|
362
363
|
any, // tag
|
|
363
364
|
any, // input
|
|
364
365
|
any, // output
|
|
@@ -521,7 +522,7 @@ export type Mapper<TContext extends MachineContext, TExpressionEvent extends Eve
|
|
|
521
522
|
context: TContext;
|
|
522
523
|
event: TExpressionEvent;
|
|
523
524
|
self: ActorRef<TEvent, MachineSnapshot<TContext, TEvent, Record<string, AnyActorRef>, // TODO: this should be replaced with `TChildren`
|
|
524
|
-
string, unknown>>;
|
|
525
|
+
StateValue, string, unknown>>;
|
|
525
526
|
}) => TResult;
|
|
526
527
|
export interface TransitionDefinition<TContext extends MachineContext, TEvent extends EventObject> extends Omit<TransitionConfig<TContext, TEvent, TEvent, TODO, TODO, TODO, TODO>, 'target' | 'guard'> {
|
|
527
528
|
target: ReadonlyArray<StateNode<TContext, TEvent>> | undefined;
|
|
@@ -746,13 +747,13 @@ export interface ActorRef<TEvent extends EventObject, TSnapshot extends Snapshot
|
|
|
746
747
|
}
|
|
747
748
|
export type AnyActorRef = ActorRef<any, any>;
|
|
748
749
|
export type ActorLogicFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<any, any, any, any, any, any, any, any, any, any, any> ? R : R extends Promise<infer U> ? PromiseActorLogic<U> : never : never;
|
|
749
|
-
export type ActorRefFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer TEvent, infer TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer TTag, infer _TInput, infer TOutput, infer TResolvedTypesMeta> ? ActorRef<TEvent, MachineSnapshot<TContext, TEvent, TChildren, TTag, TOutput, AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta> extends false ? MarkAllImplementationsAsProvided<TResolvedTypesMeta> : TResolvedTypesMeta>> : R extends Promise<infer U> ? ActorRefFrom<PromiseActorLogic<U>> : R extends ActorLogic<infer TSnapshot, infer TEvent, infer _TInput, infer _TSystem> ? ActorRef<TEvent, TSnapshot> : never : never;
|
|
750
|
+
export type ActorRefFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer TEvent, infer TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer TStateValue, infer TTag, infer _TInput, infer TOutput, infer TResolvedTypesMeta> ? ActorRef<TEvent, MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta> extends false ? MarkAllImplementationsAsProvided<TResolvedTypesMeta> : TResolvedTypesMeta>> : R extends Promise<infer U> ? ActorRefFrom<PromiseActorLogic<U>> : R extends ActorLogic<infer TSnapshot, infer TEvent, infer _TInput, infer _TSystem> ? ActorRef<TEvent, TSnapshot> : never : never;
|
|
750
751
|
export type DevToolsAdapter = (service: AnyActor) => void;
|
|
751
752
|
/**
|
|
752
753
|
* @deprecated Use `Actor<T>` instead.
|
|
753
754
|
*/
|
|
754
|
-
export type InterpreterFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine)> = ReturnTypeOrValue<T> extends StateMachine<infer TContext, infer TEvent, infer TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer TTag, infer TInput, infer TOutput, infer TResolvedTypesMeta> ? Actor<ActorLogic<MachineSnapshot<TContext, TEvent, TChildren, TTag, TOutput, TResolvedTypesMeta>, TEvent, TInput, ActorSystem<any>>> : never;
|
|
755
|
-
export type MachineImplementationsFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine), TRequireMissingImplementations extends boolean = false> = ReturnTypeOrValue<T> extends StateMachine<infer TContext, infer _TEvent, infer _TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TTag, infer _TInput, infer _TOutput, infer TResolvedTypesMeta> ? InternalMachineImplementations<TContext, TResolvedTypesMeta, TRequireMissingImplementations> : never;
|
|
755
|
+
export type InterpreterFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine)> = ReturnTypeOrValue<T> extends StateMachine<infer TContext, infer TEvent, infer TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer TStateValue, infer TTag, infer TInput, infer TOutput, infer TResolvedTypesMeta> ? Actor<ActorLogic<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TResolvedTypesMeta>, TEvent, TInput, ActorSystem<any>>> : never;
|
|
756
|
+
export type MachineImplementationsFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine), TRequireMissingImplementations extends boolean = false> = ReturnTypeOrValue<T> extends StateMachine<infer TContext, infer _TEvent, infer _TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TStateValue, infer _TTag, infer _TInput, infer _TOutput, infer TResolvedTypesMeta> ? InternalMachineImplementations<TContext, TResolvedTypesMeta, TRequireMissingImplementations> : never;
|
|
756
757
|
export type __ResolvedTypesMetaFrom<T> = T extends StateMachine<any, // context
|
|
757
758
|
any, // event
|
|
758
759
|
any, // children
|
|
@@ -844,11 +845,11 @@ export type AnyActorLogic = ActorLogic<any, // snapshot
|
|
|
844
845
|
any, // event
|
|
845
846
|
any, // input
|
|
846
847
|
any>;
|
|
847
|
-
export type SnapshotFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends ActorRef<infer _, infer TSnapshot> ? TSnapshot : R extends Actor<infer TLogic> ? SnapshotFrom<TLogic> : R extends
|
|
848
|
+
export type SnapshotFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends ActorRef<infer _, infer TSnapshot> ? TSnapshot : R extends Actor<infer TLogic> ? SnapshotFrom<TLogic> : R extends ActorLogic<infer _, infer __, infer ___, infer ____> ? ReturnType<R['transition']> : R extends ActorScope<infer TSnapshot, infer _, infer __> ? TSnapshot : never : never;
|
|
848
849
|
export type EventFromLogic<TLogic extends ActorLogic<any, any, any, any>> = TLogic extends ActorLogic<infer _, infer TEvent, infer __, infer _____> ? TEvent : never;
|
|
849
|
-
type ResolveEventType<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer _TContext, infer TEvent, infer _TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TTag, infer _TInput, infer _TOutput, infer _TResolvedTypesMeta> ? TEvent : R extends MachineSnapshot<infer _TContext, infer TEvent, infer _TChildren, infer _TTag, infer _TOutput, infer _TResolvedTypesMeta> ? TEvent : R extends ActorRef<infer TEvent, infer _> ? TEvent : never : never;
|
|
850
|
+
type ResolveEventType<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer _TContext, infer TEvent, infer _TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TStateValue, infer _TTag, infer _TInput, infer _TOutput, infer _TResolvedTypesMeta> ? TEvent : R extends MachineSnapshot<infer _TContext, infer TEvent, infer _TChildren, infer _TTag, infer _TOutput, infer _TResolvedTypesMeta> ? TEvent : R extends ActorRef<infer TEvent, infer _> ? TEvent : never : never;
|
|
850
851
|
export type EventFrom<T, K extends Prop<TEvent, 'type'> = never, TEvent extends EventObject = ResolveEventType<T>> = IsNever<K> extends true ? TEvent : ExtractEvent<TEvent, K>;
|
|
851
|
-
export type ContextFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer _TEvent, infer _TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TTag, infer _TInput, infer _TOutput, infer _TTypesMeta> ? TContext : R extends MachineSnapshot<infer TContext, infer _TEvent, infer _TChildren, infer _TTag, infer _TOutput, infer _TResolvedTypesMeta> ? TContext : R extends Actor<infer TActorLogic> ? TActorLogic extends StateMachine<infer TContext, infer _TEvent, infer _TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TTag, infer _TInput, infer _TOutput, infer _TTypesMeta> ? TContext : never : never : never;
|
|
852
|
+
export type ContextFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer _TEvent, infer _TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TStateValue, infer _TTag, infer _TInput, infer _TOutput, infer _TTypesMeta> ? TContext : R extends MachineSnapshot<infer TContext, infer _TEvent, infer _TChildren, infer _TTag, infer _TOutput, infer _TResolvedTypesMeta> ? TContext : R extends Actor<infer TActorLogic> ? TActorLogic extends StateMachine<infer TContext, infer _TEvent, infer _TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TTag, infer _TInput, infer _TOutput, infer _TTypesMeta> ? TContext : never : never : never;
|
|
852
853
|
export type InferEvent<E extends EventObject> = {
|
|
853
854
|
[T in E['type']]: {
|
|
854
855
|
type: T;
|
|
@@ -878,4 +879,7 @@ export type ToChildren<TActor extends ProvidedActor> = string extends TActor['sr
|
|
|
878
879
|
};
|
|
879
880
|
exclude: {};
|
|
880
881
|
}[undefined extends TActor['id'] ? 'include' : string extends TActor['id'] ? 'include' : 'exclude']>;
|
|
882
|
+
export type StateSchema = {
|
|
883
|
+
states?: Record<string, StateSchema>;
|
|
884
|
+
};
|
|
881
885
|
export {};
|
|
@@ -21,7 +21,6 @@ export declare function mapFilterValues<T, P>(collection: {
|
|
|
21
21
|
*/
|
|
22
22
|
export declare function path<T extends Record<string, any>>(props: string[]): any;
|
|
23
23
|
export declare function toStatePaths(stateValue: StateValue | undefined): string[][];
|
|
24
|
-
export declare function flatten<T>(array: Array<T | T[]>): T[];
|
|
25
24
|
export declare function toArrayStrict<T>(value: readonly T[] | T): readonly T[];
|
|
26
25
|
export declare function toArray<T>(value: readonly T[] | T | undefined): readonly T[];
|
|
27
26
|
export declare function resolveOutput<TContext extends MachineContext, TExpressionEvent extends EventObject>(mapper: Mapper<TContext, TExpressionEvent, unknown, EventObject> | NonReducibleUnknown, context: TContext, event: TExpressionEvent, self: AnyActorRef): unknown;
|
|
@@ -248,9 +248,6 @@ function mapValues(collection, iteratee) {
|
|
|
248
248
|
}
|
|
249
249
|
return result;
|
|
250
250
|
}
|
|
251
|
-
function flatten(array) {
|
|
252
|
-
return [].concat(...array);
|
|
253
|
-
}
|
|
254
251
|
function toArrayStrict(value) {
|
|
255
252
|
if (isArray(value)) {
|
|
256
253
|
return value;
|
|
@@ -320,7 +317,7 @@ function resolveReferencedActor(machine, src) {
|
|
|
320
317
|
return machine.implementations.actors[src];
|
|
321
318
|
}
|
|
322
319
|
function getAllOwnEventDescriptors(snapshot) {
|
|
323
|
-
return [...new Set(
|
|
320
|
+
return [...new Set([...snapshot._nodes.flatMap(sn => sn.ownEvents)])];
|
|
324
321
|
}
|
|
325
322
|
|
|
326
323
|
const $$ACTOR_TYPE = 1;
|
|
@@ -2179,10 +2176,9 @@ function createMachineSnapshot(config, machine) {
|
|
|
2179
2176
|
context: config.context,
|
|
2180
2177
|
_nodes: config._nodes,
|
|
2181
2178
|
value: getStateValue(machine.root, config._nodes),
|
|
2182
|
-
tags: new Set(
|
|
2179
|
+
tags: new Set(config._nodes.flatMap(sn => sn.tags)),
|
|
2183
2180
|
children: config.children,
|
|
2184
2181
|
historyValue: config.historyValue || {},
|
|
2185
|
-
// this one is generic in the target and it's hard to create a matching non-generic source signature
|
|
2186
2182
|
matches: machineSnapshotMatches,
|
|
2187
2183
|
hasTag: machineSnapshotHasTag,
|
|
2188
2184
|
can: machineSnapshotCan,
|
|
@@ -250,9 +250,6 @@ function mapValues(collection, iteratee) {
|
|
|
250
250
|
}
|
|
251
251
|
return result;
|
|
252
252
|
}
|
|
253
|
-
function flatten(array) {
|
|
254
|
-
return [].concat(...array);
|
|
255
|
-
}
|
|
256
253
|
function toArrayStrict(value) {
|
|
257
254
|
if (isArray(value)) {
|
|
258
255
|
return value;
|
|
@@ -322,7 +319,7 @@ function resolveReferencedActor(machine, src) {
|
|
|
322
319
|
return machine.implementations.actors[src];
|
|
323
320
|
}
|
|
324
321
|
function getAllOwnEventDescriptors(snapshot) {
|
|
325
|
-
return [...new Set(
|
|
322
|
+
return [...new Set([...snapshot._nodes.flatMap(sn => sn.ownEvents)])];
|
|
326
323
|
}
|
|
327
324
|
|
|
328
325
|
const $$ACTOR_TYPE = 1;
|
|
@@ -2181,10 +2178,9 @@ function createMachineSnapshot(config, machine) {
|
|
|
2181
2178
|
context: config.context,
|
|
2182
2179
|
_nodes: config._nodes,
|
|
2183
2180
|
value: getStateValue(machine.root, config._nodes),
|
|
2184
|
-
tags: new Set(
|
|
2181
|
+
tags: new Set(config._nodes.flatMap(sn => sn.tags)),
|
|
2185
2182
|
children: config.children,
|
|
2186
2183
|
historyValue: config.historyValue || {},
|
|
2187
|
-
// this one is generic in the target and it's hard to create a matching non-generic source signature
|
|
2188
2184
|
matches: machineSnapshotMatches,
|
|
2189
2185
|
hasTag: machineSnapshotHasTag,
|
|
2190
2186
|
can: machineSnapshotCan,
|
|
@@ -250,9 +250,6 @@ function mapValues(collection, iteratee) {
|
|
|
250
250
|
}
|
|
251
251
|
return result;
|
|
252
252
|
}
|
|
253
|
-
function flatten(array) {
|
|
254
|
-
return [].concat(...array);
|
|
255
|
-
}
|
|
256
253
|
function toArrayStrict(value) {
|
|
257
254
|
if (isArray(value)) {
|
|
258
255
|
return value;
|
|
@@ -319,7 +316,7 @@ function resolveReferencedActor(machine, src) {
|
|
|
319
316
|
return machine.implementations.actors[src];
|
|
320
317
|
}
|
|
321
318
|
function getAllOwnEventDescriptors(snapshot) {
|
|
322
|
-
return [...new Set(
|
|
319
|
+
return [...new Set([...snapshot._nodes.flatMap(sn => sn.ownEvents)])];
|
|
323
320
|
}
|
|
324
321
|
|
|
325
322
|
const $$ACTOR_TYPE = 1;
|
|
@@ -2133,10 +2130,9 @@ function createMachineSnapshot(config, machine) {
|
|
|
2133
2130
|
context: config.context,
|
|
2134
2131
|
_nodes: config._nodes,
|
|
2135
2132
|
value: getStateValue(machine.root, config._nodes),
|
|
2136
|
-
tags: new Set(
|
|
2133
|
+
tags: new Set(config._nodes.flatMap(sn => sn.tags)),
|
|
2137
2134
|
children: config.children,
|
|
2138
2135
|
historyValue: config.historyValue || {},
|
|
2139
|
-
// this one is generic in the target and it's hard to create a matching non-generic source signature
|
|
2140
2136
|
matches: machineSnapshotMatches,
|
|
2141
2137
|
hasTag: machineSnapshotHasTag,
|
|
2142
2138
|
can: machineSnapshotCan,
|
|
@@ -248,9 +248,6 @@ function mapValues(collection, iteratee) {
|
|
|
248
248
|
}
|
|
249
249
|
return result;
|
|
250
250
|
}
|
|
251
|
-
function flatten(array) {
|
|
252
|
-
return [].concat(...array);
|
|
253
|
-
}
|
|
254
251
|
function toArrayStrict(value) {
|
|
255
252
|
if (isArray(value)) {
|
|
256
253
|
return value;
|
|
@@ -317,7 +314,7 @@ function resolveReferencedActor(machine, src) {
|
|
|
317
314
|
return machine.implementations.actors[src];
|
|
318
315
|
}
|
|
319
316
|
function getAllOwnEventDescriptors(snapshot) {
|
|
320
|
-
return [...new Set(
|
|
317
|
+
return [...new Set([...snapshot._nodes.flatMap(sn => sn.ownEvents)])];
|
|
321
318
|
}
|
|
322
319
|
|
|
323
320
|
const $$ACTOR_TYPE = 1;
|
|
@@ -2131,10 +2128,9 @@ function createMachineSnapshot(config, machine) {
|
|
|
2131
2128
|
context: config.context,
|
|
2132
2129
|
_nodes: config._nodes,
|
|
2133
2130
|
value: getStateValue(machine.root, config._nodes),
|
|
2134
|
-
tags: new Set(
|
|
2131
|
+
tags: new Set(config._nodes.flatMap(sn => sn.tags)),
|
|
2135
2132
|
children: config.children,
|
|
2136
2133
|
historyValue: config.historyValue || {},
|
|
2137
|
-
// this one is generic in the target and it's hard to create a matching non-generic source signature
|
|
2138
2134
|
matches: machineSnapshotMatches,
|
|
2139
2135
|
hasTag: machineSnapshotHasTag,
|
|
2140
2136
|
can: machineSnapshotCan,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { U as ProcessingStatus, V as createErrorActorEvent, B as resolveReferencedActor, C as createActor, p as cloneMachineSnapshot, e as evaluateGuard, t as toArray, W as XSTATE_ERROR } from './raise-
|
|
1
|
+
import { U as ProcessingStatus, V as createErrorActorEvent, B as resolveReferencedActor, C as createActor, p as cloneMachineSnapshot, e as evaluateGuard, t as toArray, W as XSTATE_ERROR } from './raise-1873c645.development.esm.js';
|
|
2
2
|
|
|
3
3
|
function createSpawner(actorScope, {
|
|
4
4
|
machine,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { U as ProcessingStatus, V as createErrorActorEvent, B as resolveReferencedActor, C as createActor, p as cloneMachineSnapshot, e as evaluateGuard, t as toArray, W as XSTATE_ERROR } from './raise-
|
|
1
|
+
import { U as ProcessingStatus, V as createErrorActorEvent, B as resolveReferencedActor, C as createActor, p as cloneMachineSnapshot, e as evaluateGuard, t as toArray, W as XSTATE_ERROR } from './raise-e4cc6d4f.esm.js';
|
|
2
2
|
|
|
3
3
|
function createSpawner(actorScope, {
|
|
4
4
|
machine,
|
package/dist/xstate.cjs.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var actors_dist_xstateActors = require('../actors/dist/xstate-actors.cjs.js');
|
|
6
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
7
|
-
var send = require('./send-
|
|
6
|
+
var guards_dist_xstateGuards = require('./raise-8f9c4a5a.cjs.js');
|
|
7
|
+
var send = require('./send-8ed5c8b2.cjs.js');
|
|
8
8
|
require('../dev/dist/xstate-dev.cjs.js');
|
|
9
9
|
|
|
10
10
|
class SimulatedClock {
|
|
@@ -372,7 +372,6 @@ class StateMachine {
|
|
|
372
372
|
*/
|
|
373
373
|
this.version = void 0;
|
|
374
374
|
this.implementations = void 0;
|
|
375
|
-
this.types = void 0;
|
|
376
375
|
this.__xstatenode = true;
|
|
377
376
|
this.idMap = new Map();
|
|
378
377
|
this.root = void 0;
|
|
@@ -389,7 +388,6 @@ class StateMachine {
|
|
|
389
388
|
guards: implementations?.guards ?? {}
|
|
390
389
|
};
|
|
391
390
|
this.version = this.config.version;
|
|
392
|
-
this.types = this.config.types ?? {};
|
|
393
391
|
this.transition = this.transition.bind(this);
|
|
394
392
|
this.getInitialState = this.getInitialState.bind(this);
|
|
395
393
|
this.restoreState = this.restoreState.bind(this);
|
|
@@ -453,23 +451,23 @@ class StateMachine {
|
|
|
453
451
|
}
|
|
454
452
|
|
|
455
453
|
/**
|
|
456
|
-
* Determines the next
|
|
454
|
+
* Determines the next snapshot given the current `snapshot` and received `event`.
|
|
457
455
|
* Calculates a full macrostep from all microsteps.
|
|
458
456
|
*
|
|
459
|
-
* @param
|
|
457
|
+
* @param snapshot The current snapshot
|
|
460
458
|
* @param event The received event
|
|
461
459
|
*/
|
|
462
|
-
transition(
|
|
460
|
+
transition(snapshot, event, actorScope) {
|
|
463
461
|
// TODO: handle error events in a better way
|
|
464
|
-
if (guards_dist_xstateGuards.isErrorActorEvent(event) && !guards_dist_xstateGuards.getAllOwnEventDescriptors(
|
|
465
|
-
return guards_dist_xstateGuards.cloneMachineSnapshot(
|
|
462
|
+
if (guards_dist_xstateGuards.isErrorActorEvent(event) && !guards_dist_xstateGuards.getAllOwnEventDescriptors(snapshot).some(nextEvent => nextEvent === event.type)) {
|
|
463
|
+
return guards_dist_xstateGuards.cloneMachineSnapshot(snapshot, {
|
|
466
464
|
status: 'error',
|
|
467
465
|
error: event.data
|
|
468
466
|
});
|
|
469
467
|
}
|
|
470
468
|
const {
|
|
471
469
|
state: nextState
|
|
472
|
-
} = guards_dist_xstateGuards.macrostep(
|
|
470
|
+
} = guards_dist_xstateGuards.macrostep(snapshot, event, actorScope);
|
|
473
471
|
return nextState;
|
|
474
472
|
}
|
|
475
473
|
|
|
@@ -483,8 +481,8 @@ class StateMachine {
|
|
|
483
481
|
microstep(state, event, actorScope) {
|
|
484
482
|
return guards_dist_xstateGuards.macrostep(state, event, actorScope).microstates;
|
|
485
483
|
}
|
|
486
|
-
getTransitionData(
|
|
487
|
-
return guards_dist_xstateGuards.transitionNode(this.root,
|
|
484
|
+
getTransitionData(snapshot, event) {
|
|
485
|
+
return guards_dist_xstateGuards.transitionNode(this.root, snapshot.value, snapshot, event) || [];
|
|
488
486
|
}
|
|
489
487
|
|
|
490
488
|
/**
|
|
@@ -679,6 +677,9 @@ function waitFor(actorRef, predicate, options) {
|
|
|
679
677
|
});
|
|
680
678
|
}
|
|
681
679
|
|
|
680
|
+
// this is not 100% accurate since we can't make parallel regions required in the result
|
|
681
|
+
// `TTestValue` doesn't encode this information anyhow for us to be able to do that
|
|
682
|
+
// this is fine for most practical use cases anyway though
|
|
682
683
|
function createMachine(config, implementations) {
|
|
683
684
|
return new StateMachine(config, implementations);
|
|
684
685
|
}
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var actors_dist_xstateActors = require('../actors/dist/xstate-actors.development.cjs.js');
|
|
6
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
7
|
-
var send = require('./send-
|
|
6
|
+
var guards_dist_xstateGuards = require('./raise-495f4b9f.development.cjs.js');
|
|
7
|
+
var send = require('./send-8d30b415.development.cjs.js');
|
|
8
8
|
require('../dev/dist/xstate-dev.development.cjs.js');
|
|
9
9
|
|
|
10
10
|
class SimulatedClock {
|
|
@@ -372,7 +372,6 @@ class StateMachine {
|
|
|
372
372
|
*/
|
|
373
373
|
this.version = void 0;
|
|
374
374
|
this.implementations = void 0;
|
|
375
|
-
this.types = void 0;
|
|
376
375
|
this.__xstatenode = true;
|
|
377
376
|
this.idMap = new Map();
|
|
378
377
|
this.root = void 0;
|
|
@@ -389,7 +388,6 @@ class StateMachine {
|
|
|
389
388
|
guards: implementations?.guards ?? {}
|
|
390
389
|
};
|
|
391
390
|
this.version = this.config.version;
|
|
392
|
-
this.types = this.config.types ?? {};
|
|
393
391
|
this.transition = this.transition.bind(this);
|
|
394
392
|
this.getInitialState = this.getInitialState.bind(this);
|
|
395
393
|
this.restoreState = this.restoreState.bind(this);
|
|
@@ -456,23 +454,23 @@ class StateMachine {
|
|
|
456
454
|
}
|
|
457
455
|
|
|
458
456
|
/**
|
|
459
|
-
* Determines the next
|
|
457
|
+
* Determines the next snapshot given the current `snapshot` and received `event`.
|
|
460
458
|
* Calculates a full macrostep from all microsteps.
|
|
461
459
|
*
|
|
462
|
-
* @param
|
|
460
|
+
* @param snapshot The current snapshot
|
|
463
461
|
* @param event The received event
|
|
464
462
|
*/
|
|
465
|
-
transition(
|
|
463
|
+
transition(snapshot, event, actorScope) {
|
|
466
464
|
// TODO: handle error events in a better way
|
|
467
|
-
if (guards_dist_xstateGuards.isErrorActorEvent(event) && !guards_dist_xstateGuards.getAllOwnEventDescriptors(
|
|
468
|
-
return guards_dist_xstateGuards.cloneMachineSnapshot(
|
|
465
|
+
if (guards_dist_xstateGuards.isErrorActorEvent(event) && !guards_dist_xstateGuards.getAllOwnEventDescriptors(snapshot).some(nextEvent => nextEvent === event.type)) {
|
|
466
|
+
return guards_dist_xstateGuards.cloneMachineSnapshot(snapshot, {
|
|
469
467
|
status: 'error',
|
|
470
468
|
error: event.data
|
|
471
469
|
});
|
|
472
470
|
}
|
|
473
471
|
const {
|
|
474
472
|
state: nextState
|
|
475
|
-
} = guards_dist_xstateGuards.macrostep(
|
|
473
|
+
} = guards_dist_xstateGuards.macrostep(snapshot, event, actorScope);
|
|
476
474
|
return nextState;
|
|
477
475
|
}
|
|
478
476
|
|
|
@@ -486,8 +484,8 @@ class StateMachine {
|
|
|
486
484
|
microstep(state, event, actorScope) {
|
|
487
485
|
return guards_dist_xstateGuards.macrostep(state, event, actorScope).microstates;
|
|
488
486
|
}
|
|
489
|
-
getTransitionData(
|
|
490
|
-
return guards_dist_xstateGuards.transitionNode(this.root,
|
|
487
|
+
getTransitionData(snapshot, event) {
|
|
488
|
+
return guards_dist_xstateGuards.transitionNode(this.root, snapshot.value, snapshot, event) || [];
|
|
491
489
|
}
|
|
492
490
|
|
|
493
491
|
/**
|
|
@@ -685,6 +683,9 @@ function waitFor(actorRef, predicate, options) {
|
|
|
685
683
|
});
|
|
686
684
|
}
|
|
687
685
|
|
|
686
|
+
// this is not 100% accurate since we can't make parallel regions required in the result
|
|
687
|
+
// `TTestValue` doesn't encode this information anyhow for us to be able to do that
|
|
688
|
+
// this is fine for most practical use cases anyway though
|
|
688
689
|
function createMachine(config, implementations) {
|
|
689
690
|
return new StateMachine(config, implementations);
|
|
690
691
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { createEmptyActor, fromCallback, fromEventObservable, fromObservable, fromPromise, fromTransition } from '../actors/dist/xstate-actors.development.esm.js';
|
|
2
|
-
import { S as STATE_DELIMITER, m as mapValues, t as toArray, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, e as evaluateGuard, c as createInvokeId, g as getDelayedTransitions, d as formatInitialTransition, h as getCandidates, r as resolveStateValue, i as getAllStateNodes, j as getStateNodes, k as createMachineSnapshot, l as isInFinalState, n as isErrorActorEvent, o as getAllOwnEventDescriptors, p as cloneMachineSnapshot, q as macrostep, s as transitionNode, u as resolveActionsAndContext, v as createInitEvent, w as microstep, x as getInitialStateNodes, y as isStateId, z as getStateNodeByPath, A as getPersistedState, B as resolveReferencedActor, C as createActor, $ as $$ACTOR_TYPE } from './raise-
|
|
3
|
-
export { D as Actor, o as __unsafe_getAllOwnEventDescriptors, J as and, O as cancel, C as createActor, j as getStateNodes, E as interpret, F as isMachineSnapshot, G as matchesState, K as not, L as or, H as pathToStateValue, P as raise, T as spawnChild, M as stateIn, Q as stop, R as stopChild, I as toObserver } from './raise-
|
|
4
|
-
import { a as assign } from './send-
|
|
5
|
-
export { S as SpecialTargets, a as assign, c as choose, e as escalate, f as forwardTo, l as log, p as pure, s as sendParent, b as sendTo } from './send-
|
|
2
|
+
import { S as STATE_DELIMITER, m as mapValues, t as toArray, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, e as evaluateGuard, c as createInvokeId, g as getDelayedTransitions, d as formatInitialTransition, h as getCandidates, r as resolveStateValue, i as getAllStateNodes, j as getStateNodes, k as createMachineSnapshot, l as isInFinalState, n as isErrorActorEvent, o as getAllOwnEventDescriptors, p as cloneMachineSnapshot, q as macrostep, s as transitionNode, u as resolveActionsAndContext, v as createInitEvent, w as microstep, x as getInitialStateNodes, y as isStateId, z as getStateNodeByPath, A as getPersistedState, B as resolveReferencedActor, C as createActor, $ as $$ACTOR_TYPE } from './raise-1873c645.development.esm.js';
|
|
3
|
+
export { D as Actor, o as __unsafe_getAllOwnEventDescriptors, J as and, O as cancel, C as createActor, j as getStateNodes, E as interpret, F as isMachineSnapshot, G as matchesState, K as not, L as or, H as pathToStateValue, P as raise, T as spawnChild, M as stateIn, Q as stop, R as stopChild, I as toObserver } from './raise-1873c645.development.esm.js';
|
|
4
|
+
import { a as assign } from './send-0a381ca2.development.esm.js';
|
|
5
|
+
export { S as SpecialTargets, a as assign, c as choose, e as escalate, f as forwardTo, l as log, p as pure, s as sendParent, b as sendTo } from './send-0a381ca2.development.esm.js';
|
|
6
6
|
import '../dev/dist/xstate-dev.development.esm.js';
|
|
7
7
|
|
|
8
8
|
class SimulatedClock {
|
|
@@ -370,7 +370,6 @@ class StateMachine {
|
|
|
370
370
|
*/
|
|
371
371
|
this.version = void 0;
|
|
372
372
|
this.implementations = void 0;
|
|
373
|
-
this.types = void 0;
|
|
374
373
|
this.__xstatenode = true;
|
|
375
374
|
this.idMap = new Map();
|
|
376
375
|
this.root = void 0;
|
|
@@ -387,7 +386,6 @@ class StateMachine {
|
|
|
387
386
|
guards: implementations?.guards ?? {}
|
|
388
387
|
};
|
|
389
388
|
this.version = this.config.version;
|
|
390
|
-
this.types = this.config.types ?? {};
|
|
391
389
|
this.transition = this.transition.bind(this);
|
|
392
390
|
this.getInitialState = this.getInitialState.bind(this);
|
|
393
391
|
this.restoreState = this.restoreState.bind(this);
|
|
@@ -454,23 +452,23 @@ class StateMachine {
|
|
|
454
452
|
}
|
|
455
453
|
|
|
456
454
|
/**
|
|
457
|
-
* Determines the next
|
|
455
|
+
* Determines the next snapshot given the current `snapshot` and received `event`.
|
|
458
456
|
* Calculates a full macrostep from all microsteps.
|
|
459
457
|
*
|
|
460
|
-
* @param
|
|
458
|
+
* @param snapshot The current snapshot
|
|
461
459
|
* @param event The received event
|
|
462
460
|
*/
|
|
463
|
-
transition(
|
|
461
|
+
transition(snapshot, event, actorScope) {
|
|
464
462
|
// TODO: handle error events in a better way
|
|
465
|
-
if (isErrorActorEvent(event) && !getAllOwnEventDescriptors(
|
|
466
|
-
return cloneMachineSnapshot(
|
|
463
|
+
if (isErrorActorEvent(event) && !getAllOwnEventDescriptors(snapshot).some(nextEvent => nextEvent === event.type)) {
|
|
464
|
+
return cloneMachineSnapshot(snapshot, {
|
|
467
465
|
status: 'error',
|
|
468
466
|
error: event.data
|
|
469
467
|
});
|
|
470
468
|
}
|
|
471
469
|
const {
|
|
472
470
|
state: nextState
|
|
473
|
-
} = macrostep(
|
|
471
|
+
} = macrostep(snapshot, event, actorScope);
|
|
474
472
|
return nextState;
|
|
475
473
|
}
|
|
476
474
|
|
|
@@ -484,8 +482,8 @@ class StateMachine {
|
|
|
484
482
|
microstep(state, event, actorScope) {
|
|
485
483
|
return macrostep(state, event, actorScope).microstates;
|
|
486
484
|
}
|
|
487
|
-
getTransitionData(
|
|
488
|
-
return transitionNode(this.root,
|
|
485
|
+
getTransitionData(snapshot, event) {
|
|
486
|
+
return transitionNode(this.root, snapshot.value, snapshot, event) || [];
|
|
489
487
|
}
|
|
490
488
|
|
|
491
489
|
/**
|
|
@@ -683,6 +681,9 @@ function waitFor(actorRef, predicate, options) {
|
|
|
683
681
|
});
|
|
684
682
|
}
|
|
685
683
|
|
|
684
|
+
// this is not 100% accurate since we can't make parallel regions required in the result
|
|
685
|
+
// `TTestValue` doesn't encode this information anyhow for us to be able to do that
|
|
686
|
+
// this is fine for most practical use cases anyway though
|
|
686
687
|
function createMachine(config, implementations) {
|
|
687
688
|
return new StateMachine(config, implementations);
|
|
688
689
|
}
|