xstate 5.0.0-beta.47 → 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 +30 -5
- package/dist/declarations/src/setup.d.ts +21 -5
- 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-156f5f68.development.esm.js → raise-1873c645.development.esm.js} +31 -9
- package/dist/{raise-7dc97582.development.cjs.js → raise-495f4b9f.development.cjs.js} +31 -9
- package/dist/{raise-7af24c22.cjs.js → raise-8f9c4a5a.cjs.js} +31 -9
- package/dist/{raise-91ec8b4f.esm.js → raise-e4cc6d4f.esm.js} +31 -9
- package/dist/{send-7489590c.development.esm.js → send-0a381ca2.development.esm.js} +1 -1
- package/dist/{send-ed326064.esm.js → send-22880315.esm.js} +1 -1
- package/dist/{send-bc0d3e22.development.cjs.js → send-8d30b415.development.cjs.js} +1 -1
- package/dist/{send-401f5c30.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 {};
|
|
@@ -168,13 +168,38 @@ export declare class Actor<TLogic extends AnyActorLogic> implements ActorRef<Eve
|
|
|
168
168
|
getSnapshot(): SnapshotFrom<TLogic>;
|
|
169
169
|
}
|
|
170
170
|
/**
|
|
171
|
-
* Creates a new
|
|
171
|
+
* Creates a new actor instance for the given actor logic with the provided options, if any.
|
|
172
172
|
*
|
|
173
|
-
* @
|
|
174
|
-
*
|
|
173
|
+
* @remarks
|
|
174
|
+
* When you create an actor from actor logic via `createActor(logic)`, you implicitly create an actor system where the created actor is the root actor.
|
|
175
|
+
* Any actors spawned from this root actor and its descendants are part of that actor system.
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```ts
|
|
179
|
+
* import { createActor } from 'xstate';
|
|
180
|
+
* import { someActorLogic } from './someActorLogic.ts';
|
|
181
|
+
*
|
|
182
|
+
* // Creating the actor, which implicitly creates an actor system with itself as the root actor
|
|
183
|
+
* const actor = createActor(someActorLogic);
|
|
184
|
+
*
|
|
185
|
+
* actor.subscribe((snapshot) => {
|
|
186
|
+
* console.log(snapshot);
|
|
187
|
+
* });
|
|
188
|
+
*
|
|
189
|
+
* // Actors must be started by calling `actor.start()`, which will also start the actor system.
|
|
190
|
+
* actor.start();
|
|
191
|
+
*
|
|
192
|
+
* // Actors can receive events
|
|
193
|
+
* actor.send({ type: 'someEvent' });
|
|
194
|
+
*
|
|
195
|
+
* // You can stop root actors by calling `actor.stop()`, which will also stop the actor system and all actors in that system.
|
|
196
|
+
* actor.stop();
|
|
197
|
+
* ```
|
|
198
|
+
*
|
|
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
|
+
* @param options - Actor options
|
|
175
201
|
*/
|
|
176
|
-
export declare function createActor<
|
|
177
|
-
export declare function createActor<TLogic extends AnyActorLogic>(logic: TLogic, options?: ActorOptions<TLogic>): Actor<TLogic>;
|
|
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>;
|
|
178
203
|
/**
|
|
179
204
|
* Creates a new Interpreter instance for the given machine with the provided options, if any.
|
|
180
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;
|
|
@@ -9,13 +9,29 @@ type ToParameterizedObject<TParameterizedMap extends Record<string, Parameterize
|
|
|
9
9
|
};
|
|
10
10
|
}>;
|
|
11
11
|
type DefaultToAnyActors<TActors extends Record<string, AnyActorLogic>> = IsNever<keyof TActors> extends true ? Record<string, AnyActorLogic> : TActors;
|
|
12
|
-
type ToProvidedActor<TChildrenMap extends Record<string, string>, TActors extends Record<Values<TChildrenMap>, AnyActorLogic>> = Values<{
|
|
13
|
-
[K in keyof
|
|
12
|
+
type ToProvidedActor<TChildrenMap extends Record<string, string>, TActors extends Record<Values<TChildrenMap>, AnyActorLogic>, TResolvedActors extends Record<string, AnyActorLogic> = DefaultToAnyActors<TActors>> = Values<{
|
|
13
|
+
[K in keyof TResolvedActors & string]: {
|
|
14
14
|
src: K;
|
|
15
|
-
logic:
|
|
15
|
+
logic: TResolvedActors[K];
|
|
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;
|
|
@@ -849,10 +846,36 @@ class Actor {
|
|
|
849
846
|
}
|
|
850
847
|
|
|
851
848
|
/**
|
|
852
|
-
* Creates a new
|
|
849
|
+
* Creates a new actor instance for the given actor logic with the provided options, if any.
|
|
850
|
+
*
|
|
851
|
+
* @remarks
|
|
852
|
+
* When you create an actor from actor logic via `createActor(logic)`, you implicitly create an actor system where the created actor is the root actor.
|
|
853
|
+
* Any actors spawned from this root actor and its descendants are part of that actor system.
|
|
854
|
+
*
|
|
855
|
+
* @example
|
|
856
|
+
* ```ts
|
|
857
|
+
* import { createActor } from 'xstate';
|
|
858
|
+
* import { someActorLogic } from './someActorLogic.ts';
|
|
859
|
+
*
|
|
860
|
+
* // Creating the actor, which implicitly creates an actor system with itself as the root actor
|
|
861
|
+
* const actor = createActor(someActorLogic);
|
|
862
|
+
*
|
|
863
|
+
* actor.subscribe((snapshot) => {
|
|
864
|
+
* console.log(snapshot);
|
|
865
|
+
* });
|
|
866
|
+
*
|
|
867
|
+
* // Actors must be started by calling `actor.start()`, which will also start the actor system.
|
|
868
|
+
* actor.start();
|
|
869
|
+
*
|
|
870
|
+
* // Actors can receive events
|
|
871
|
+
* actor.send({ type: 'someEvent' });
|
|
872
|
+
*
|
|
873
|
+
* // You can stop root actors by calling `actor.stop()`, which will also stop the actor system and all actors in that system.
|
|
874
|
+
* actor.stop();
|
|
875
|
+
* ```
|
|
853
876
|
*
|
|
854
|
-
* @param
|
|
855
|
-
* @param options
|
|
877
|
+
* @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}.
|
|
878
|
+
* @param options - Actor options
|
|
856
879
|
*/
|
|
857
880
|
|
|
858
881
|
function createActor(logic, options) {
|
|
@@ -2153,10 +2176,9 @@ function createMachineSnapshot(config, machine) {
|
|
|
2153
2176
|
context: config.context,
|
|
2154
2177
|
_nodes: config._nodes,
|
|
2155
2178
|
value: getStateValue(machine.root, config._nodes),
|
|
2156
|
-
tags: new Set(
|
|
2179
|
+
tags: new Set(config._nodes.flatMap(sn => sn.tags)),
|
|
2157
2180
|
children: config.children,
|
|
2158
2181
|
historyValue: config.historyValue || {},
|
|
2159
|
-
// this one is generic in the target and it's hard to create a matching non-generic source signature
|
|
2160
2182
|
matches: machineSnapshotMatches,
|
|
2161
2183
|
hasTag: machineSnapshotHasTag,
|
|
2162
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;
|
|
@@ -851,10 +848,36 @@ class Actor {
|
|
|
851
848
|
}
|
|
852
849
|
|
|
853
850
|
/**
|
|
854
|
-
* Creates a new
|
|
851
|
+
* Creates a new actor instance for the given actor logic with the provided options, if any.
|
|
852
|
+
*
|
|
853
|
+
* @remarks
|
|
854
|
+
* When you create an actor from actor logic via `createActor(logic)`, you implicitly create an actor system where the created actor is the root actor.
|
|
855
|
+
* Any actors spawned from this root actor and its descendants are part of that actor system.
|
|
856
|
+
*
|
|
857
|
+
* @example
|
|
858
|
+
* ```ts
|
|
859
|
+
* import { createActor } from 'xstate';
|
|
860
|
+
* import { someActorLogic } from './someActorLogic.ts';
|
|
861
|
+
*
|
|
862
|
+
* // Creating the actor, which implicitly creates an actor system with itself as the root actor
|
|
863
|
+
* const actor = createActor(someActorLogic);
|
|
864
|
+
*
|
|
865
|
+
* actor.subscribe((snapshot) => {
|
|
866
|
+
* console.log(snapshot);
|
|
867
|
+
* });
|
|
868
|
+
*
|
|
869
|
+
* // Actors must be started by calling `actor.start()`, which will also start the actor system.
|
|
870
|
+
* actor.start();
|
|
871
|
+
*
|
|
872
|
+
* // Actors can receive events
|
|
873
|
+
* actor.send({ type: 'someEvent' });
|
|
874
|
+
*
|
|
875
|
+
* // You can stop root actors by calling `actor.stop()`, which will also stop the actor system and all actors in that system.
|
|
876
|
+
* actor.stop();
|
|
877
|
+
* ```
|
|
855
878
|
*
|
|
856
|
-
* @param
|
|
857
|
-
* @param options
|
|
879
|
+
* @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}.
|
|
880
|
+
* @param options - Actor options
|
|
858
881
|
*/
|
|
859
882
|
|
|
860
883
|
function createActor(logic, options) {
|
|
@@ -2155,10 +2178,9 @@ function createMachineSnapshot(config, machine) {
|
|
|
2155
2178
|
context: config.context,
|
|
2156
2179
|
_nodes: config._nodes,
|
|
2157
2180
|
value: getStateValue(machine.root, config._nodes),
|
|
2158
|
-
tags: new Set(
|
|
2181
|
+
tags: new Set(config._nodes.flatMap(sn => sn.tags)),
|
|
2159
2182
|
children: config.children,
|
|
2160
2183
|
historyValue: config.historyValue || {},
|
|
2161
|
-
// this one is generic in the target and it's hard to create a matching non-generic source signature
|
|
2162
2184
|
matches: machineSnapshotMatches,
|
|
2163
2185
|
hasTag: machineSnapshotHasTag,
|
|
2164
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;
|
|
@@ -840,10 +837,36 @@ class Actor {
|
|
|
840
837
|
}
|
|
841
838
|
|
|
842
839
|
/**
|
|
843
|
-
* Creates a new
|
|
840
|
+
* Creates a new actor instance for the given actor logic with the provided options, if any.
|
|
841
|
+
*
|
|
842
|
+
* @remarks
|
|
843
|
+
* When you create an actor from actor logic via `createActor(logic)`, you implicitly create an actor system where the created actor is the root actor.
|
|
844
|
+
* Any actors spawned from this root actor and its descendants are part of that actor system.
|
|
845
|
+
*
|
|
846
|
+
* @example
|
|
847
|
+
* ```ts
|
|
848
|
+
* import { createActor } from 'xstate';
|
|
849
|
+
* import { someActorLogic } from './someActorLogic.ts';
|
|
850
|
+
*
|
|
851
|
+
* // Creating the actor, which implicitly creates an actor system with itself as the root actor
|
|
852
|
+
* const actor = createActor(someActorLogic);
|
|
853
|
+
*
|
|
854
|
+
* actor.subscribe((snapshot) => {
|
|
855
|
+
* console.log(snapshot);
|
|
856
|
+
* });
|
|
857
|
+
*
|
|
858
|
+
* // Actors must be started by calling `actor.start()`, which will also start the actor system.
|
|
859
|
+
* actor.start();
|
|
860
|
+
*
|
|
861
|
+
* // Actors can receive events
|
|
862
|
+
* actor.send({ type: 'someEvent' });
|
|
863
|
+
*
|
|
864
|
+
* // You can stop root actors by calling `actor.stop()`, which will also stop the actor system and all actors in that system.
|
|
865
|
+
* actor.stop();
|
|
866
|
+
* ```
|
|
844
867
|
*
|
|
845
|
-
* @param
|
|
846
|
-
* @param options
|
|
868
|
+
* @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}.
|
|
869
|
+
* @param options - Actor options
|
|
847
870
|
*/
|
|
848
871
|
|
|
849
872
|
function createActor(logic, options) {
|
|
@@ -2107,10 +2130,9 @@ function createMachineSnapshot(config, machine) {
|
|
|
2107
2130
|
context: config.context,
|
|
2108
2131
|
_nodes: config._nodes,
|
|
2109
2132
|
value: getStateValue(machine.root, config._nodes),
|
|
2110
|
-
tags: new Set(
|
|
2133
|
+
tags: new Set(config._nodes.flatMap(sn => sn.tags)),
|
|
2111
2134
|
children: config.children,
|
|
2112
2135
|
historyValue: config.historyValue || {},
|
|
2113
|
-
// this one is generic in the target and it's hard to create a matching non-generic source signature
|
|
2114
2136
|
matches: machineSnapshotMatches,
|
|
2115
2137
|
hasTag: machineSnapshotHasTag,
|
|
2116
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;
|
|
@@ -838,10 +835,36 @@ class Actor {
|
|
|
838
835
|
}
|
|
839
836
|
|
|
840
837
|
/**
|
|
841
|
-
* Creates a new
|
|
838
|
+
* Creates a new actor instance for the given actor logic with the provided options, if any.
|
|
839
|
+
*
|
|
840
|
+
* @remarks
|
|
841
|
+
* When you create an actor from actor logic via `createActor(logic)`, you implicitly create an actor system where the created actor is the root actor.
|
|
842
|
+
* Any actors spawned from this root actor and its descendants are part of that actor system.
|
|
843
|
+
*
|
|
844
|
+
* @example
|
|
845
|
+
* ```ts
|
|
846
|
+
* import { createActor } from 'xstate';
|
|
847
|
+
* import { someActorLogic } from './someActorLogic.ts';
|
|
848
|
+
*
|
|
849
|
+
* // Creating the actor, which implicitly creates an actor system with itself as the root actor
|
|
850
|
+
* const actor = createActor(someActorLogic);
|
|
851
|
+
*
|
|
852
|
+
* actor.subscribe((snapshot) => {
|
|
853
|
+
* console.log(snapshot);
|
|
854
|
+
* });
|
|
855
|
+
*
|
|
856
|
+
* // Actors must be started by calling `actor.start()`, which will also start the actor system.
|
|
857
|
+
* actor.start();
|
|
858
|
+
*
|
|
859
|
+
* // Actors can receive events
|
|
860
|
+
* actor.send({ type: 'someEvent' });
|
|
861
|
+
*
|
|
862
|
+
* // You can stop root actors by calling `actor.stop()`, which will also stop the actor system and all actors in that system.
|
|
863
|
+
* actor.stop();
|
|
864
|
+
* ```
|
|
842
865
|
*
|
|
843
|
-
* @param
|
|
844
|
-
* @param options
|
|
866
|
+
* @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}.
|
|
867
|
+
* @param options - Actor options
|
|
845
868
|
*/
|
|
846
869
|
|
|
847
870
|
function createActor(logic, options) {
|
|
@@ -2105,10 +2128,9 @@ function createMachineSnapshot(config, machine) {
|
|
|
2105
2128
|
context: config.context,
|
|
2106
2129
|
_nodes: config._nodes,
|
|
2107
2130
|
value: getStateValue(machine.root, config._nodes),
|
|
2108
|
-
tags: new Set(
|
|
2131
|
+
tags: new Set(config._nodes.flatMap(sn => sn.tags)),
|
|
2109
2132
|
children: config.children,
|
|
2110
2133
|
historyValue: config.historyValue || {},
|
|
2111
|
-
// this one is generic in the target and it's hard to create a matching non-generic source signature
|
|
2112
2134
|
matches: machineSnapshotMatches,
|
|
2113
2135
|
hasTag: machineSnapshotHasTag,
|
|
2114
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,
|