xstate 5.0.0-beta.42 → 5.0.0-beta.43
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 +3 -3
- package/actions/dist/xstate-actions.development.cjs.js +3 -3
- package/actions/dist/xstate-actions.development.esm.js +3 -3
- package/actions/dist/xstate-actions.esm.js +3 -3
- 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 +45 -1
- package/actors/dist/xstate-actors.development.cjs.js +45 -1
- package/actors/dist/xstate-actors.development.esm.js +45 -1
- package/actors/dist/xstate-actors.esm.js +45 -1
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/declarations/src/State.d.ts +5 -5
- package/dist/declarations/src/actions/spawn.d.ts +3 -3
- package/dist/declarations/src/actors/promise.d.ts +53 -0
- package/dist/declarations/src/types.d.ts +41 -6
- package/dist/declarations/src/utils.d.ts +2 -8
- package/dist/{interpreter-b6bdd134.cjs.js → interpreter-36d5556e.cjs.js} +2 -9
- package/dist/{interpreter-23e4041c.development.cjs.js → interpreter-4e8e2a0d.development.cjs.js} +2 -9
- package/dist/{interpreter-3d0c0ff2.esm.js → interpreter-63c80754.esm.js} +2 -9
- package/dist/{interpreter-f2620ea7.development.esm.js → interpreter-80eb3bec.development.esm.js} +2 -9
- package/dist/{raise-8f482ce9.development.cjs.js → raise-23dea0d7.development.cjs.js} +69 -56
- package/dist/{raise-d2084327.esm.js → raise-8dc8e1aa.esm.js} +66 -53
- package/dist/{raise-6b64c553.cjs.js → raise-e0fe5c2d.cjs.js} +66 -53
- package/dist/{raise-51ae36e5.development.esm.js → raise-f4ad5a87.development.esm.js} +69 -56
- package/dist/{send-cc8f864e.development.cjs.js → send-0174c155.development.cjs.js} +7 -9
- package/dist/{send-7a350091.development.esm.js → send-5d129d95.development.esm.js} +7 -9
- package/dist/{send-4e732fa5.esm.js → send-84e2e742.esm.js} +7 -9
- package/dist/{send-85b562d8.cjs.js → send-87bbaaab.cjs.js} +7 -9
- package/dist/xstate.cjs.js +4 -4
- package/dist/xstate.development.cjs.js +4 -4
- package/dist/xstate.development.esm.js +7 -7
- package/dist/xstate.esm.js +7 -7
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.js +2 -2
- package/guards/dist/xstate-guards.development.cjs.js +2 -2
- package/guards/dist/xstate-guards.development.esm.js +2 -2
- package/guards/dist/xstate-guards.esm.js +2 -2
- package/package.json +1 -1
|
@@ -36,14 +36,14 @@ interface MachineSnapshotBase<TContext extends MachineContext, TEvent extends Ev
|
|
|
36
36
|
meta: Record<string, any>;
|
|
37
37
|
/**
|
|
38
38
|
* Whether the current state value is a subset of the given parent state value.
|
|
39
|
-
* @param
|
|
39
|
+
* @param testValue
|
|
40
40
|
*/
|
|
41
|
-
matches: <TSV extends TResolvedTypesMeta extends TypegenEnabled ? Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'matchesStates'> : StateValue>(
|
|
41
|
+
matches: <TSV extends TResolvedTypesMeta extends TypegenEnabled ? Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'matchesStates'> : StateValue>(this: MachineSnapshotBase<TContext, TEvent, TActor, TTag, TOutput, TResolvedTypesMeta>, testValue: TSV) => boolean;
|
|
42
42
|
/**
|
|
43
43
|
* Whether the current state configuration has a state node with the specified `tag`.
|
|
44
44
|
* @param tag
|
|
45
45
|
*/
|
|
46
|
-
hasTag: (tag: TTag) => boolean;
|
|
46
|
+
hasTag: (this: MachineSnapshotBase<TContext, TEvent, TActor, TTag, TOutput, TResolvedTypesMeta>, tag: TTag) => boolean;
|
|
47
47
|
/**
|
|
48
48
|
* Determines whether sending the `event` will cause a non-forbidden transition
|
|
49
49
|
* to be selected, even if the transitions have no actions nor
|
|
@@ -52,8 +52,8 @@ interface MachineSnapshotBase<TContext extends MachineContext, TEvent extends Ev
|
|
|
52
52
|
* @param event The event to test
|
|
53
53
|
* @returns Whether the event will cause a transition
|
|
54
54
|
*/
|
|
55
|
-
can: (event: TEvent) => boolean;
|
|
56
|
-
toJSON: () => unknown;
|
|
55
|
+
can: (this: MachineSnapshotBase<TContext, TEvent, TActor, TTag, TOutput, TResolvedTypesMeta>, event: TEvent) => boolean;
|
|
56
|
+
toJSON: (this: MachineSnapshotBase<TContext, TEvent, TActor, TTag, TOutput, TResolvedTypesMeta>) => unknown;
|
|
57
57
|
}
|
|
58
58
|
interface ActiveMachineSnapshot<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TTag extends string, TOutput, TResolvedTypesMeta = TypegenDisabled> extends MachineSnapshotBase<TContext, TEvent, TActor, TTag, TOutput, TResolvedTypesMeta> {
|
|
59
59
|
status: 'active';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ActionArgs, EventObject, MachineContext, ParameterizedObject, AnyActorLogic, ProvidedActor, IsLiteralString, InputFrom, UnifiedArg } from "../types.js";
|
|
1
|
+
import { ActionArgs, EventObject, MachineContext, ParameterizedObject, AnyActorLogic, ProvidedActor, IsLiteralString, InputFrom, UnifiedArg, Mapper } from "../types.js";
|
|
2
2
|
type ResolvableActorId<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TId extends string | undefined> = TId | ((args: UnifiedArg<TContext, TExpressionEvent, TEvent>) => TId);
|
|
3
3
|
export interface SpawnAction<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject, TActor extends ProvidedActor> {
|
|
4
4
|
(args: ActionArgs<TContext, TExpressionEvent, TEvent>, params: TParams): void;
|
|
@@ -9,7 +9,7 @@ type DistributeActors<TContext extends MachineContext, TExpressionEvent extends
|
|
|
9
9
|
options: {
|
|
10
10
|
id: ResolvableActorId<TContext, TExpressionEvent, TEvent, TActor['id']>;
|
|
11
11
|
systemId?: string;
|
|
12
|
-
input?: InputFrom<TActor['logic']>;
|
|
12
|
+
input?: Mapper<TContext, TEvent, InputFrom<TActor['logic']>, TEvent> | InputFrom<TActor['logic']>;
|
|
13
13
|
syncSnapshot?: boolean;
|
|
14
14
|
}
|
|
15
15
|
] : [
|
|
@@ -17,7 +17,7 @@ type DistributeActors<TContext extends MachineContext, TExpressionEvent extends
|
|
|
17
17
|
options?: {
|
|
18
18
|
id?: ResolvableActorId<TContext, TExpressionEvent, TEvent, string>;
|
|
19
19
|
systemId?: string;
|
|
20
|
-
input?: InputFrom<TActor['logic']>;
|
|
20
|
+
input?: Mapper<TContext, TEvent, InputFrom<TActor['logic']>, TEvent> | InputFrom<TActor['logic']>;
|
|
21
21
|
syncSnapshot?: boolean;
|
|
22
22
|
}
|
|
23
23
|
] : never;
|
|
@@ -20,9 +20,62 @@ export type PromiseActorLogic<TOutput, TInput = unknown> = ActorLogic<PromiseSna
|
|
|
20
20
|
}, TInput, // input
|
|
21
21
|
ActorSystem<any>>;
|
|
22
22
|
export type PromiseActorRef<TOutput> = ActorRefFrom<PromiseActorLogic<TOutput, unknown>>;
|
|
23
|
+
/**
|
|
24
|
+
* An actor logic creator which returns promise logic as defined by an async process that resolves or rejects after some time.
|
|
25
|
+
*
|
|
26
|
+
* Actors created from promise actor logic (“promise actors”) can:
|
|
27
|
+
* - Emit the resolved value of the promise
|
|
28
|
+
* - Output the resolved value of the promise
|
|
29
|
+
*
|
|
30
|
+
* Sending events to promise actors will have no effect.
|
|
31
|
+
*
|
|
32
|
+
* @param promiseCreator
|
|
33
|
+
* A function which returns a Promise, and accepts an object with the following properties:
|
|
34
|
+
* - `input` - Data that was provided to the promise actor
|
|
35
|
+
* - `self` - The parent actor of the promise actor
|
|
36
|
+
* - `system` - The actor system to which the promise actor belongs
|
|
37
|
+
* @see {@link https://stately.ai/docs/input | Input docs} for more information about how input is passed
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* const promiseLogic = fromPromise(async () => {
|
|
42
|
+
* const result = await fetch('https://example.com/...')
|
|
43
|
+
* .then((data) => data.json());
|
|
44
|
+
*
|
|
45
|
+
* return result;
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* const promiseActor = createActor(promiseLogic);
|
|
49
|
+
* promiseActor.subscribe((snapshot) => {
|
|
50
|
+
* console.log(snapshot);
|
|
51
|
+
* });
|
|
52
|
+
* promiseActor.start();
|
|
53
|
+
* // => {
|
|
54
|
+
* // output: undefined,
|
|
55
|
+
* // status: 'active'
|
|
56
|
+
* // ...
|
|
57
|
+
* // }
|
|
58
|
+
*
|
|
59
|
+
* // After promise resolves
|
|
60
|
+
* // => {
|
|
61
|
+
* // output: { ... },
|
|
62
|
+
* // status: 'done',
|
|
63
|
+
* // ...
|
|
64
|
+
* // }
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
23
67
|
export declare function fromPromise<TOutput, TInput = unknown>(promiseCreator: ({ input, system }: {
|
|
68
|
+
/**
|
|
69
|
+
* Data that was provided to the promise actor
|
|
70
|
+
*/
|
|
24
71
|
input: TInput;
|
|
72
|
+
/**
|
|
73
|
+
* The actor system to which the promise actor belongs
|
|
74
|
+
*/
|
|
25
75
|
system: AnyActorSystem;
|
|
76
|
+
/**
|
|
77
|
+
* The parent actor of the promise actor
|
|
78
|
+
*/
|
|
26
79
|
self: PromiseActorRef<TOutput>;
|
|
27
80
|
}) => PromiseLike<TOutput>): PromiseActorLogic<TOutput, TInput>;
|
|
28
81
|
export {};
|
|
@@ -387,11 +387,8 @@ type MaybeNarrowedEvent<TIndexedEvents, TCausingLookup, K> = Cast<Prop<TIndexedE
|
|
|
387
387
|
type MachineImplementationsActions<TContext extends MachineContext, TResolvedTypesMeta, TEventsCausingActions = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'eventsCausingActions'>, TIndexedEvents = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedEvents'>, TIndexedActors = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedActors'>, TIndexedActions = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedActions'>, TIndexedGuards = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedGuards'>, TIndexedDelays = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedDelays'>> = {
|
|
388
388
|
[K in keyof TIndexedActions]?: ActionFunction<TContext, MaybeNarrowedEvent<TIndexedEvents, TEventsCausingActions, K>, Cast<Prop<TIndexedEvents, keyof TIndexedEvents>, EventObject>, GetParameterizedParams<Cast<TIndexedActions[K], ParameterizedObject>>, Cast<Prop<TIndexedActors, keyof TIndexedActors>, ProvidedActor>, Cast<Prop<TIndexedActions, keyof TIndexedActions>, ParameterizedObject>, Cast<Prop<TIndexedGuards, keyof TIndexedGuards>, ParameterizedObject>, Cast<Prop<TIndexedDelays, keyof TIndexedDelays>, ParameterizedObject>['type']>;
|
|
389
389
|
};
|
|
390
|
-
type MachineImplementationsActors<
|
|
391
|
-
[K in keyof TIndexedActors]?: Cast<Prop<TIndexedActors[K], 'logic'>, AnyActorLogic
|
|
392
|
-
src: Cast<Prop<TIndexedActors[K], 'logic'>, AnyActorLogic>;
|
|
393
|
-
input: Mapper<TContext, MaybeNarrowedEvent<TIndexedEvents, TEventsCausingActors, K>, InputFrom<Cast<Prop<TIndexedActors[K], 'logic'>, AnyActorLogic>>, Cast<Prop<TIndexedEvents, keyof TIndexedEvents>, EventObject>> | InputFrom<Cast<Prop<TIndexedActors[K], 'logic'>, AnyActorLogic>>;
|
|
394
|
-
};
|
|
390
|
+
type MachineImplementationsActors<_TContext extends MachineContext, TResolvedTypesMeta, TIndexedActors = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedActors'>, _TInvokeSrcNameMap = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'invokeSrcNameMap'>> = {
|
|
391
|
+
[K in keyof TIndexedActors]?: Cast<Prop<TIndexedActors[K], 'logic'>, AnyActorLogic>;
|
|
395
392
|
};
|
|
396
393
|
type MachineImplementationsDelays<TContext extends MachineContext, TResolvedTypesMeta, TEventsCausingDelays = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'eventsCausingDelays'>, TIndexedEvents = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedEvents'>, TIndexedActions = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedActions'>, TIndexedDelays = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedDelays'>> = {
|
|
397
394
|
[K in keyof TIndexedDelays]?: DelayConfig<TContext, MaybeNarrowedEvent<TIndexedEvents, TEventsCausingDelays, K>, Cast<Prop<Prop<TIndexedActions, keyof TIndexedActions>, 'params'>, ParameterizedObject['params'] | undefined> | undefined, Cast<Prop<TIndexedEvents, keyof TIndexedEvents>, EventObject>>;
|
|
@@ -777,14 +774,52 @@ export type Snapshot<TOutput> = {
|
|
|
777
774
|
output: undefined;
|
|
778
775
|
error: undefined;
|
|
779
776
|
};
|
|
777
|
+
/**
|
|
778
|
+
* Represents logic which can be used by an actor.
|
|
779
|
+
*
|
|
780
|
+
* @template TSnapshot - The type of the snapshot.
|
|
781
|
+
* @template TEvent - The type of the event object.
|
|
782
|
+
* @template TInput - The type of the input.
|
|
783
|
+
* @template TSystem - The type of the actor system.
|
|
784
|
+
*/
|
|
780
785
|
export interface ActorLogic<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TInput = unknown, TSystem extends ActorSystem<any> = ActorSystem<any>> {
|
|
786
|
+
/** The initial setup/configuration used to create the actor logic. */
|
|
781
787
|
config?: unknown;
|
|
788
|
+
/**
|
|
789
|
+
* Transition function that processes the current state and an incoming message
|
|
790
|
+
* to produce a new state.
|
|
791
|
+
* @param state - The current state.
|
|
792
|
+
* @param message - The incoming message.
|
|
793
|
+
* @param ctx - The actor scope.
|
|
794
|
+
* @returns The new state.
|
|
795
|
+
*/
|
|
782
796
|
transition: (state: TSnapshot, message: TEvent, ctx: ActorScope<TSnapshot, TEvent, TSystem>) => TSnapshot;
|
|
797
|
+
/**
|
|
798
|
+
* Called to provide the initial state of the actor.
|
|
799
|
+
* @param actorScope - The actor scope.
|
|
800
|
+
* @param input - The input for the initial state.
|
|
801
|
+
* @returns The initial state.
|
|
802
|
+
*/
|
|
783
803
|
getInitialState: (actorScope: ActorScope<TSnapshot, TEvent, TSystem>, input: TInput) => TSnapshot;
|
|
804
|
+
/**
|
|
805
|
+
* Called when Actor is created to restore the internal state of the actor given a persisted state.
|
|
806
|
+
* The persisted state can be created by `getPersistedState`.
|
|
807
|
+
* @param persistedState - The persisted state to restore from.
|
|
808
|
+
* @param actorScope - The actor scope.
|
|
809
|
+
* @returns The restored state.
|
|
810
|
+
*/
|
|
784
811
|
restoreState?: (persistedState: Snapshot<unknown>, actorScope: ActorScope<TSnapshot, TEvent>) => TSnapshot;
|
|
812
|
+
/**
|
|
813
|
+
* Called when the actor is started.
|
|
814
|
+
* @param state - The starting state.
|
|
815
|
+
* @param actorScope - The actor scope.
|
|
816
|
+
*/
|
|
785
817
|
start?: (state: TSnapshot, actorScope: ActorScope<TSnapshot, TEvent>) => void;
|
|
786
818
|
/**
|
|
787
|
-
*
|
|
819
|
+
* Obtains the internal state of the actor in a representation which can be be persisted.
|
|
820
|
+
* The persisted state can be restored by `restoreState`.
|
|
821
|
+
* @param state - The current state.
|
|
822
|
+
* @returns The a representation of the internal state to be persisted.
|
|
788
823
|
*/
|
|
789
824
|
getPersistedState: (state: TSnapshot, options?: unknown) => Snapshot<unknown>;
|
|
790
825
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AnyState } from "./index.js";
|
|
2
2
|
import type { StateNode } from "./StateNode.js";
|
|
3
3
|
import type { ActorLogic, AnyEventObject, EventObject, MachineContext, Mapper, Observer, ErrorActorEvent, SingleOrArray, StateLike, StateValue, Subscribable, TransitionConfigTarget, AnyActorRef, AnyTransitionConfig, NonReducibleUnknown, AnyStateMachine } from "./types.js";
|
|
4
4
|
export declare function keys<T extends object>(value: T): Array<keyof T & string>;
|
|
@@ -39,10 +39,4 @@ export declare function normalizeTarget<TContext extends MachineContext, TEvent
|
|
|
39
39
|
export declare function reportUnhandledExceptionOnInvocation(originalError: any, currentError: any, id: string): void;
|
|
40
40
|
export declare function toObserver<T>(nextHandler?: Observer<T> | ((value: T) => void), errorHandler?: (error: any) => void, completionHandler?: () => void): Observer<T>;
|
|
41
41
|
export declare function createInvokeId(stateNodeId: string, index: number): string;
|
|
42
|
-
export declare function resolveReferencedActor(machine: AnyStateMachine, src: string):
|
|
43
|
-
src: AnyActorLogic;
|
|
44
|
-
input: NonReducibleUnknown | Mapper<any, any, unknown, any>;
|
|
45
|
-
} | {
|
|
46
|
-
src: any;
|
|
47
|
-
input: undefined;
|
|
48
|
-
} | undefined;
|
|
42
|
+
export declare function resolveReferencedActor(machine: AnyStateMachine, src: string): any;
|
|
@@ -320,16 +320,9 @@ function resolveReferencedActor(machine, src) {
|
|
|
320
320
|
const [, indexStr] = src.match(/\[(\d+)\]$/);
|
|
321
321
|
const node = machine.getStateNodeById(src.slice(7, -(indexStr.length + 2)));
|
|
322
322
|
const invokeConfig = node.config.invoke;
|
|
323
|
-
return
|
|
324
|
-
src: (Array.isArray(invokeConfig) ? invokeConfig[indexStr] : invokeConfig).src,
|
|
325
|
-
input: undefined
|
|
326
|
-
};
|
|
323
|
+
return (Array.isArray(invokeConfig) ? invokeConfig[indexStr] : invokeConfig).src;
|
|
327
324
|
}
|
|
328
|
-
|
|
329
|
-
return referenced ? 'transition' in referenced ? {
|
|
330
|
-
src: referenced,
|
|
331
|
-
input: undefined
|
|
332
|
-
} : referenced : undefined;
|
|
325
|
+
return machine.implementations.actors[src];
|
|
333
326
|
}
|
|
334
327
|
|
|
335
328
|
const $$ACTOR_TYPE = 1;
|
package/dist/{interpreter-23e4041c.development.cjs.js → interpreter-4e8e2a0d.development.cjs.js}
RENAMED
|
@@ -323,16 +323,9 @@ function resolveReferencedActor(machine, src) {
|
|
|
323
323
|
const [, indexStr] = src.match(/\[(\d+)\]$/);
|
|
324
324
|
const node = machine.getStateNodeById(src.slice(7, -(indexStr.length + 2)));
|
|
325
325
|
const invokeConfig = node.config.invoke;
|
|
326
|
-
return
|
|
327
|
-
src: (Array.isArray(invokeConfig) ? invokeConfig[indexStr] : invokeConfig).src,
|
|
328
|
-
input: undefined
|
|
329
|
-
};
|
|
326
|
+
return (Array.isArray(invokeConfig) ? invokeConfig[indexStr] : invokeConfig).src;
|
|
330
327
|
}
|
|
331
|
-
|
|
332
|
-
return referenced ? 'transition' in referenced ? {
|
|
333
|
-
src: referenced,
|
|
334
|
-
input: undefined
|
|
335
|
-
} : referenced : undefined;
|
|
328
|
+
return machine.implementations.actors[src];
|
|
336
329
|
}
|
|
337
330
|
|
|
338
331
|
const $$ACTOR_TYPE = 1;
|
|
@@ -318,16 +318,9 @@ function resolveReferencedActor(machine, src) {
|
|
|
318
318
|
const [, indexStr] = src.match(/\[(\d+)\]$/);
|
|
319
319
|
const node = machine.getStateNodeById(src.slice(7, -(indexStr.length + 2)));
|
|
320
320
|
const invokeConfig = node.config.invoke;
|
|
321
|
-
return
|
|
322
|
-
src: (Array.isArray(invokeConfig) ? invokeConfig[indexStr] : invokeConfig).src,
|
|
323
|
-
input: undefined
|
|
324
|
-
};
|
|
321
|
+
return (Array.isArray(invokeConfig) ? invokeConfig[indexStr] : invokeConfig).src;
|
|
325
322
|
}
|
|
326
|
-
|
|
327
|
-
return referenced ? 'transition' in referenced ? {
|
|
328
|
-
src: referenced,
|
|
329
|
-
input: undefined
|
|
330
|
-
} : referenced : undefined;
|
|
323
|
+
return machine.implementations.actors[src];
|
|
331
324
|
}
|
|
332
325
|
|
|
333
326
|
const $$ACTOR_TYPE = 1;
|
package/dist/{interpreter-f2620ea7.development.esm.js → interpreter-80eb3bec.development.esm.js}
RENAMED
|
@@ -321,16 +321,9 @@ function resolveReferencedActor(machine, src) {
|
|
|
321
321
|
const [, indexStr] = src.match(/\[(\d+)\]$/);
|
|
322
322
|
const node = machine.getStateNodeById(src.slice(7, -(indexStr.length + 2)));
|
|
323
323
|
const invokeConfig = node.config.invoke;
|
|
324
|
-
return
|
|
325
|
-
src: (Array.isArray(invokeConfig) ? invokeConfig[indexStr] : invokeConfig).src,
|
|
326
|
-
input: undefined
|
|
327
|
-
};
|
|
324
|
+
return (Array.isArray(invokeConfig) ? invokeConfig[indexStr] : invokeConfig).src;
|
|
328
325
|
}
|
|
329
|
-
|
|
330
|
-
return referenced ? 'transition' in referenced ? {
|
|
331
|
-
src: referenced,
|
|
332
|
-
input: undefined
|
|
333
|
-
} : referenced : undefined;
|
|
326
|
+
return machine.implementations.actors[src];
|
|
334
327
|
}
|
|
335
328
|
|
|
336
329
|
const $$ACTOR_TYPE = 1;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var interpreter = require('./interpreter-
|
|
3
|
+
var interpreter = require('./interpreter-4e8e2a0d.development.cjs.js');
|
|
4
4
|
|
|
5
5
|
const cache = new WeakMap();
|
|
6
6
|
function memo(object, key, fn) {
|
|
@@ -52,25 +52,20 @@ function resolveSpawn(actorScope, state, actionArgs, _actionParams, {
|
|
|
52
52
|
input,
|
|
53
53
|
syncSnapshot
|
|
54
54
|
}) {
|
|
55
|
-
const
|
|
56
|
-
src,
|
|
57
|
-
input: undefined
|
|
58
|
-
};
|
|
55
|
+
const logic = typeof src === 'string' ? interpreter.resolveReferencedActor(state.machine, src) : src;
|
|
59
56
|
const resolvedId = typeof id === 'function' ? id(actionArgs) : id;
|
|
60
57
|
let actorRef;
|
|
61
|
-
if (
|
|
62
|
-
|
|
63
|
-
const configuredInput = input || referenced.input;
|
|
64
|
-
actorRef = interpreter.createActor(referenced.src, {
|
|
58
|
+
if (logic) {
|
|
59
|
+
actorRef = interpreter.createActor(logic, {
|
|
65
60
|
id: resolvedId,
|
|
66
61
|
src,
|
|
67
62
|
parent: actorScope?.self,
|
|
68
63
|
systemId,
|
|
69
|
-
input: typeof
|
|
64
|
+
input: typeof input === 'function' ? input({
|
|
70
65
|
context: state.context,
|
|
71
66
|
event: actionArgs.event,
|
|
72
67
|
self: actorScope?.self
|
|
73
|
-
}) :
|
|
68
|
+
}) : input
|
|
74
69
|
});
|
|
75
70
|
if (syncSnapshot) {
|
|
76
71
|
actorRef.subscribe({
|
|
@@ -1257,8 +1252,53 @@ function resolveStateValue(rootNode, stateValue) {
|
|
|
1257
1252
|
return getStateValue(rootNode, [...configuration]);
|
|
1258
1253
|
}
|
|
1259
1254
|
|
|
1260
|
-
function
|
|
1255
|
+
const machineSnapshotMatches = function matches(testValue) {
|
|
1256
|
+
return interpreter.matchesState(testValue, this.value);
|
|
1257
|
+
};
|
|
1258
|
+
const machineSnapshotHasTag = function hasTag(tag) {
|
|
1259
|
+
return this.tags.has(tag);
|
|
1260
|
+
};
|
|
1261
|
+
const machineSnapshotCan = function can(event) {
|
|
1262
|
+
if (!this.machine) {
|
|
1263
|
+
console.warn(`state.can(...) used outside of a machine-created State object; this will always return false.`);
|
|
1264
|
+
}
|
|
1265
|
+
const transitionData = this.machine.getTransitionData(this, event);
|
|
1266
|
+
return !!transitionData?.length &&
|
|
1267
|
+
// Check that at least one transition is not forbidden
|
|
1268
|
+
transitionData.some(t => t.target !== undefined || t.actions.length);
|
|
1269
|
+
};
|
|
1270
|
+
const machineSnapshotToJSON = function toJSON() {
|
|
1271
|
+
const {
|
|
1272
|
+
configuration,
|
|
1273
|
+
tags,
|
|
1274
|
+
machine,
|
|
1275
|
+
nextEvents,
|
|
1276
|
+
toJSON,
|
|
1277
|
+
can,
|
|
1278
|
+
hasTag,
|
|
1279
|
+
matches,
|
|
1280
|
+
...jsonValues
|
|
1281
|
+
} = this;
|
|
1261
1282
|
return {
|
|
1283
|
+
...jsonValues,
|
|
1284
|
+
tags: Array.from(tags)
|
|
1285
|
+
};
|
|
1286
|
+
};
|
|
1287
|
+
const machineSnapshotNextEvents = function nextEvents() {
|
|
1288
|
+
return memo(this, 'nextEvents', () => {
|
|
1289
|
+
return [...new Set(interpreter.flatten([...this.configuration.map(sn => sn.ownEvents)]))];
|
|
1290
|
+
});
|
|
1291
|
+
};
|
|
1292
|
+
const machineSnapshotMeta = function nextEvents() {
|
|
1293
|
+
return this.configuration.reduce((acc, stateNode) => {
|
|
1294
|
+
if (stateNode.meta !== undefined) {
|
|
1295
|
+
acc[stateNode.id] = stateNode.meta;
|
|
1296
|
+
}
|
|
1297
|
+
return acc;
|
|
1298
|
+
}, {});
|
|
1299
|
+
};
|
|
1300
|
+
function createMachineSnapshot(config, machine) {
|
|
1301
|
+
const snapshot = {
|
|
1262
1302
|
status: config.status,
|
|
1263
1303
|
output: config.output,
|
|
1264
1304
|
error: config.error,
|
|
@@ -1269,52 +1309,25 @@ function createMachineSnapshot(config, machine) {
|
|
|
1269
1309
|
tags: new Set(interpreter.flatten(config.configuration.map(sn => sn.tags))),
|
|
1270
1310
|
children: config.children,
|
|
1271
1311
|
historyValue: config.historyValue || {},
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
return !!transitionData?.length &&
|
|
1284
|
-
// Check that at least one transition is not forbidden
|
|
1285
|
-
transitionData.some(t => t.target !== undefined || t.actions.length);
|
|
1286
|
-
},
|
|
1287
|
-
get nextEvents() {
|
|
1288
|
-
return memo(this, 'nextEvents', () => {
|
|
1289
|
-
return [...new Set(interpreter.flatten([...this.configuration.map(sn => sn.ownEvents)]))];
|
|
1290
|
-
});
|
|
1291
|
-
},
|
|
1292
|
-
get meta() {
|
|
1293
|
-
return this.configuration.reduce((acc, stateNode) => {
|
|
1294
|
-
if (stateNode.meta !== undefined) {
|
|
1295
|
-
acc[stateNode.id] = stateNode.meta;
|
|
1296
|
-
}
|
|
1297
|
-
return acc;
|
|
1298
|
-
}, {});
|
|
1312
|
+
// this one is generic in the target and it's hard to create a matching non-generic source signature
|
|
1313
|
+
matches: machineSnapshotMatches,
|
|
1314
|
+
hasTag: machineSnapshotHasTag,
|
|
1315
|
+
can: machineSnapshotCan,
|
|
1316
|
+
toJSON: machineSnapshotToJSON
|
|
1317
|
+
};
|
|
1318
|
+
Object.defineProperties(snapshot, {
|
|
1319
|
+
nextEvents: {
|
|
1320
|
+
get: machineSnapshotNextEvents,
|
|
1321
|
+
configurable: true,
|
|
1322
|
+
enumerable: true
|
|
1299
1323
|
},
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
machine,
|
|
1305
|
-
nextEvents,
|
|
1306
|
-
toJSON,
|
|
1307
|
-
can,
|
|
1308
|
-
hasTag,
|
|
1309
|
-
matches,
|
|
1310
|
-
...jsonValues
|
|
1311
|
-
} = this;
|
|
1312
|
-
return {
|
|
1313
|
-
...jsonValues,
|
|
1314
|
-
tags: Array.from(tags)
|
|
1315
|
-
};
|
|
1324
|
+
meta: {
|
|
1325
|
+
get: machineSnapshotMeta,
|
|
1326
|
+
configurable: true,
|
|
1327
|
+
enumerable: true
|
|
1316
1328
|
}
|
|
1317
|
-
};
|
|
1329
|
+
});
|
|
1330
|
+
return snapshot;
|
|
1318
1331
|
}
|
|
1319
1332
|
function cloneMachineSnapshot(state, config = {}) {
|
|
1320
1333
|
return createMachineSnapshot(
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as resolveReferencedActor, d as createActor, P as ProcessingStatus, h as createErrorActorEvent, j as STATE_IDENTIFIER, n as normalizeTarget, t as toArray, N as NULL_EVENT, a as toTransitionConfigArray, S as STATE_DELIMITER, k as toStatePath, l as createDoneStateEvent, o as resolveOutput, X as XSTATE_STOP, q as XSTATE_INIT, W as WILDCARD, s as createAfterEvent, u as flatten,
|
|
1
|
+
import { r as resolveReferencedActor, d as createActor, P as ProcessingStatus, h as createErrorActorEvent, j as STATE_IDENTIFIER, n as normalizeTarget, t as toArray, N as NULL_EVENT, a as toTransitionConfigArray, S as STATE_DELIMITER, k as toStatePath, l as createDoneStateEvent, o as resolveOutput, X as XSTATE_STOP, q as XSTATE_INIT, W as WILDCARD, s as createAfterEvent, u as flatten, $ as $$ACTOR_TYPE, f as matchesState } from './interpreter-63c80754.esm.js';
|
|
2
2
|
|
|
3
3
|
const cache = new WeakMap();
|
|
4
4
|
function memo(object, key, fn) {
|
|
@@ -47,25 +47,20 @@ function resolveSpawn(actorScope, state, actionArgs, _actionParams, {
|
|
|
47
47
|
input,
|
|
48
48
|
syncSnapshot
|
|
49
49
|
}) {
|
|
50
|
-
const
|
|
51
|
-
src,
|
|
52
|
-
input: undefined
|
|
53
|
-
};
|
|
50
|
+
const logic = typeof src === 'string' ? resolveReferencedActor(state.machine, src) : src;
|
|
54
51
|
const resolvedId = typeof id === 'function' ? id(actionArgs) : id;
|
|
55
52
|
let actorRef;
|
|
56
|
-
if (
|
|
57
|
-
|
|
58
|
-
const configuredInput = input || referenced.input;
|
|
59
|
-
actorRef = createActor(referenced.src, {
|
|
53
|
+
if (logic) {
|
|
54
|
+
actorRef = createActor(logic, {
|
|
60
55
|
id: resolvedId,
|
|
61
56
|
src,
|
|
62
57
|
parent: actorScope?.self,
|
|
63
58
|
systemId,
|
|
64
|
-
input: typeof
|
|
59
|
+
input: typeof input === 'function' ? input({
|
|
65
60
|
context: state.context,
|
|
66
61
|
event: actionArgs.event,
|
|
67
62
|
self: actorScope?.self
|
|
68
|
-
}) :
|
|
63
|
+
}) : input
|
|
69
64
|
});
|
|
70
65
|
if (syncSnapshot) {
|
|
71
66
|
actorRef.subscribe({
|
|
@@ -1221,8 +1216,50 @@ function resolveStateValue(rootNode, stateValue) {
|
|
|
1221
1216
|
return getStateValue(rootNode, [...configuration]);
|
|
1222
1217
|
}
|
|
1223
1218
|
|
|
1224
|
-
function
|
|
1219
|
+
const machineSnapshotMatches = function matches(testValue) {
|
|
1220
|
+
return matchesState(testValue, this.value);
|
|
1221
|
+
};
|
|
1222
|
+
const machineSnapshotHasTag = function hasTag(tag) {
|
|
1223
|
+
return this.tags.has(tag);
|
|
1224
|
+
};
|
|
1225
|
+
const machineSnapshotCan = function can(event) {
|
|
1226
|
+
const transitionData = this.machine.getTransitionData(this, event);
|
|
1227
|
+
return !!transitionData?.length &&
|
|
1228
|
+
// Check that at least one transition is not forbidden
|
|
1229
|
+
transitionData.some(t => t.target !== undefined || t.actions.length);
|
|
1230
|
+
};
|
|
1231
|
+
const machineSnapshotToJSON = function toJSON() {
|
|
1232
|
+
const {
|
|
1233
|
+
configuration,
|
|
1234
|
+
tags,
|
|
1235
|
+
machine,
|
|
1236
|
+
nextEvents,
|
|
1237
|
+
toJSON,
|
|
1238
|
+
can,
|
|
1239
|
+
hasTag,
|
|
1240
|
+
matches,
|
|
1241
|
+
...jsonValues
|
|
1242
|
+
} = this;
|
|
1225
1243
|
return {
|
|
1244
|
+
...jsonValues,
|
|
1245
|
+
tags: Array.from(tags)
|
|
1246
|
+
};
|
|
1247
|
+
};
|
|
1248
|
+
const machineSnapshotNextEvents = function nextEvents() {
|
|
1249
|
+
return memo(this, 'nextEvents', () => {
|
|
1250
|
+
return [...new Set(flatten([...this.configuration.map(sn => sn.ownEvents)]))];
|
|
1251
|
+
});
|
|
1252
|
+
};
|
|
1253
|
+
const machineSnapshotMeta = function nextEvents() {
|
|
1254
|
+
return this.configuration.reduce((acc, stateNode) => {
|
|
1255
|
+
if (stateNode.meta !== undefined) {
|
|
1256
|
+
acc[stateNode.id] = stateNode.meta;
|
|
1257
|
+
}
|
|
1258
|
+
return acc;
|
|
1259
|
+
}, {});
|
|
1260
|
+
};
|
|
1261
|
+
function createMachineSnapshot(config, machine) {
|
|
1262
|
+
const snapshot = {
|
|
1226
1263
|
status: config.status,
|
|
1227
1264
|
output: config.output,
|
|
1228
1265
|
error: config.error,
|
|
@@ -1233,49 +1270,25 @@ function createMachineSnapshot(config, machine) {
|
|
|
1233
1270
|
tags: new Set(flatten(config.configuration.map(sn => sn.tags))),
|
|
1234
1271
|
children: config.children,
|
|
1235
1272
|
historyValue: config.historyValue || {},
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
},
|
|
1248
|
-
get nextEvents() {
|
|
1249
|
-
return memo(this, 'nextEvents', () => {
|
|
1250
|
-
return [...new Set(flatten([...this.configuration.map(sn => sn.ownEvents)]))];
|
|
1251
|
-
});
|
|
1252
|
-
},
|
|
1253
|
-
get meta() {
|
|
1254
|
-
return this.configuration.reduce((acc, stateNode) => {
|
|
1255
|
-
if (stateNode.meta !== undefined) {
|
|
1256
|
-
acc[stateNode.id] = stateNode.meta;
|
|
1257
|
-
}
|
|
1258
|
-
return acc;
|
|
1259
|
-
}, {});
|
|
1273
|
+
// this one is generic in the target and it's hard to create a matching non-generic source signature
|
|
1274
|
+
matches: machineSnapshotMatches,
|
|
1275
|
+
hasTag: machineSnapshotHasTag,
|
|
1276
|
+
can: machineSnapshotCan,
|
|
1277
|
+
toJSON: machineSnapshotToJSON
|
|
1278
|
+
};
|
|
1279
|
+
Object.defineProperties(snapshot, {
|
|
1280
|
+
nextEvents: {
|
|
1281
|
+
get: machineSnapshotNextEvents,
|
|
1282
|
+
configurable: true,
|
|
1283
|
+
enumerable: true
|
|
1260
1284
|
},
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
machine,
|
|
1266
|
-
nextEvents,
|
|
1267
|
-
toJSON,
|
|
1268
|
-
can,
|
|
1269
|
-
hasTag,
|
|
1270
|
-
matches,
|
|
1271
|
-
...jsonValues
|
|
1272
|
-
} = this;
|
|
1273
|
-
return {
|
|
1274
|
-
...jsonValues,
|
|
1275
|
-
tags: Array.from(tags)
|
|
1276
|
-
};
|
|
1285
|
+
meta: {
|
|
1286
|
+
get: machineSnapshotMeta,
|
|
1287
|
+
configurable: true,
|
|
1288
|
+
enumerable: true
|
|
1277
1289
|
}
|
|
1278
|
-
};
|
|
1290
|
+
});
|
|
1291
|
+
return snapshot;
|
|
1279
1292
|
}
|
|
1280
1293
|
function cloneMachineSnapshot(state, config = {}) {
|
|
1281
1294
|
return createMachineSnapshot(
|