@xstate/graph
Advanced tools
Comparing version 2.0.0-beta.5 to 2.0.0-beta.6
import { ActorLogic, ActorSystem, EventObject, Snapshot } from 'xstate'; | ||
import { TraversalOptions } from "./types.js"; | ||
import { AdjacencyMap } from "./graph.js"; | ||
export declare function getAdjacencyMap<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TInput, TPersisted = TSnapshot, TSystem extends ActorSystem<any> = ActorSystem<any>>(logic: ActorLogic<TSnapshot, TEvent, TInput, TPersisted, TSystem>, options: TraversalOptions<TSnapshot, TEvent>): AdjacencyMap<TSnapshot, TEvent>; | ||
export declare function getAdjacencyMap<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TInput, TSystem extends ActorSystem<any> = ActorSystem<any>>(logic: ActorLogic<TSnapshot, TEvent, TInput, TSystem>, options: TraversalOptions<TSnapshot, TEvent>): AdjacencyMap<TSnapshot, TEvent>; |
import { ActorLogic, ActorSystem, EventObject, Snapshot } from 'xstate'; | ||
import { StatePath, TraversalOptions } from "./types.js"; | ||
export declare function getPathsFromEvents<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TInput, TPersisted = TSnapshot, TSystem extends ActorSystem<any> = ActorSystem<any>>(logic: ActorLogic<TSnapshot, TEvent, TInput, TPersisted, TSystem>, events: TEvent[], options?: TraversalOptions<TSnapshot, TEvent>): Array<StatePath<TSnapshot, TEvent>>; | ||
export declare function getPathsFromEvents<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TInput, TSystem extends ActorSystem<any> = ActorSystem<any>>(logic: ActorLogic<TSnapshot, TEvent, TInput, TSystem>, events: TEvent[], options?: TraversalOptions<TSnapshot, TEvent>): Array<StatePath<TSnapshot, TEvent>>; |
@@ -7,3 +7,3 @@ 'use strict'; | ||
function createMockActorContext() { | ||
function createMockActorScope() { | ||
const emptyActor = xstate.createEmptyActor(); | ||
@@ -16,3 +16,4 @@ return { | ||
defer: () => {}, | ||
system: emptyActor, | ||
system: emptyActor.system, | ||
// TODO: mock system? | ||
stopChild: () => {} | ||
@@ -22,6 +23,2 @@ }; | ||
function flatten(array) { | ||
return [].concat(...array); | ||
} | ||
/** | ||
@@ -75,3 +72,3 @@ * Returns all state nodes of the given `node`. | ||
const events = typeof getEvents === 'function' ? getEvents(state) : getEvents ?? []; | ||
return flatten(state.nextEvents.map(type => { | ||
return xstate.__unsafe_getAllOwnEventDescriptors(state).flatMap(type => { | ||
const matchingEvents = events.filter(ev => ev.type === type); | ||
@@ -84,5 +81,5 @@ if (matchingEvents.length) { | ||
}]; | ||
})); | ||
}); | ||
}, | ||
fromState: machine.getInitialState(createMockActorContext()), | ||
fromState: machine.getInitialSnapshot(createMockActorScope()), | ||
...otherOptions | ||
@@ -101,3 +98,3 @@ }; | ||
const edges = flatten([...stateNode.transitions.values()].flat().map((t, transitionIndex) => { | ||
const edges = [...stateNode.transitions.values()].flat().flatMap((t, transitionIndex) => { | ||
const targets = t.target ? t.target : [stateNode]; | ||
@@ -129,3 +126,3 @@ return targets.map((target, targetIndex) => { | ||
}); | ||
})); | ||
}); | ||
const graph = { | ||
@@ -198,4 +195,4 @@ id: stateNode.id, | ||
} = resolveTraversalOptions(logic, options); | ||
const actorContext = createMockActorContext(); | ||
const fromState = customFromState ?? logic.getInitialState(actorContext, | ||
const actorScope = createMockActorScope(); | ||
const fromState = customFromState ?? logic.getInitialSnapshot(actorScope, | ||
// TODO: fix this | ||
@@ -234,10 +231,10 @@ undefined); | ||
for (const nextEvent of events) { | ||
const nextState = transition(state, nextEvent, actorContext); | ||
if (!options.filter || options.filter(nextState, nextEvent)) { | ||
const nextSnapshot = transition(state, nextEvent, actorScope); | ||
if (!options.filter || options.filter(nextSnapshot, nextEvent)) { | ||
adj[serializedState].transitions[serializeEvent(nextEvent)] = { | ||
event: nextEvent, | ||
state: nextState | ||
state: nextSnapshot | ||
}; | ||
queue.push({ | ||
nextState, | ||
nextState: nextSnapshot, | ||
event: nextEvent, | ||
@@ -285,4 +282,4 @@ prevState: state | ||
const resolvedOptions = resolveTraversalOptions(logic, options); | ||
const actorContext = createMockActorContext(); | ||
const fromState = resolvedOptions.fromState ?? logic.getInitialState(actorContext, undefined); | ||
const actorScope = createMockActorScope(); | ||
const fromState = resolvedOptions.fromState ?? logic.getInitialSnapshot(actorScope, undefined); | ||
const serializeState = resolvedOptions.serializeState; | ||
@@ -354,3 +351,3 @@ const adjacency = getAdjacencyMap(logic, resolvedOptions); | ||
const serializeState = resolvedOptions.serializeState; | ||
const fromState = resolvedOptions.fromState ?? logic.getInitialState(createMockActorContext(), undefined); | ||
const fromState = resolvedOptions.fromState ?? logic.getInitialSnapshot(createMockActorScope(), undefined); | ||
const adjacency = getAdjacencyMap(logic, resolvedOptions); | ||
@@ -448,4 +445,4 @@ | ||
}, isMachine(logic) ? createDefaultMachineOptions(logic) : createDefaultLogicOptions()); | ||
const actorContext = createMockActorContext(); | ||
const fromState = resolvedOptions.fromState ?? logic.getInitialState(actorContext, | ||
const actorScope = createMockActorScope(); | ||
const fromState = resolvedOptions.fromState ?? logic.getInitialSnapshot(actorScope, | ||
// TODO: fix this | ||
@@ -452,0 +449,0 @@ undefined); |
@@ -1,4 +0,4 @@ | ||
import { createEmptyActor, StateMachine } from 'xstate'; | ||
import { createEmptyActor, StateMachine, __unsafe_getAllOwnEventDescriptors } from 'xstate'; | ||
function createMockActorContext() { | ||
function createMockActorScope() { | ||
const emptyActor = createEmptyActor(); | ||
@@ -11,3 +11,4 @@ return { | ||
defer: () => {}, | ||
system: emptyActor, | ||
system: emptyActor.system, | ||
// TODO: mock system? | ||
stopChild: () => {} | ||
@@ -17,6 +18,2 @@ }; | ||
function flatten(array) { | ||
return [].concat(...array); | ||
} | ||
/** | ||
@@ -70,3 +67,3 @@ * Returns all state nodes of the given `node`. | ||
const events = typeof getEvents === 'function' ? getEvents(state) : getEvents ?? []; | ||
return flatten(state.nextEvents.map(type => { | ||
return __unsafe_getAllOwnEventDescriptors(state).flatMap(type => { | ||
const matchingEvents = events.filter(ev => ev.type === type); | ||
@@ -79,5 +76,5 @@ if (matchingEvents.length) { | ||
}]; | ||
})); | ||
}); | ||
}, | ||
fromState: machine.getInitialState(createMockActorContext()), | ||
fromState: machine.getInitialSnapshot(createMockActorScope()), | ||
...otherOptions | ||
@@ -96,3 +93,3 @@ }; | ||
const edges = flatten([...stateNode.transitions.values()].flat().map((t, transitionIndex) => { | ||
const edges = [...stateNode.transitions.values()].flat().flatMap((t, transitionIndex) => { | ||
const targets = t.target ? t.target : [stateNode]; | ||
@@ -124,3 +121,3 @@ return targets.map((target, targetIndex) => { | ||
}); | ||
})); | ||
}); | ||
const graph = { | ||
@@ -193,4 +190,4 @@ id: stateNode.id, | ||
} = resolveTraversalOptions(logic, options); | ||
const actorContext = createMockActorContext(); | ||
const fromState = customFromState ?? logic.getInitialState(actorContext, | ||
const actorScope = createMockActorScope(); | ||
const fromState = customFromState ?? logic.getInitialSnapshot(actorScope, | ||
// TODO: fix this | ||
@@ -229,10 +226,10 @@ undefined); | ||
for (const nextEvent of events) { | ||
const nextState = transition(state, nextEvent, actorContext); | ||
if (!options.filter || options.filter(nextState, nextEvent)) { | ||
const nextSnapshot = transition(state, nextEvent, actorScope); | ||
if (!options.filter || options.filter(nextSnapshot, nextEvent)) { | ||
adj[serializedState].transitions[serializeEvent(nextEvent)] = { | ||
event: nextEvent, | ||
state: nextState | ||
state: nextSnapshot | ||
}; | ||
queue.push({ | ||
nextState, | ||
nextState: nextSnapshot, | ||
event: nextEvent, | ||
@@ -280,4 +277,4 @@ prevState: state | ||
const resolvedOptions = resolveTraversalOptions(logic, options); | ||
const actorContext = createMockActorContext(); | ||
const fromState = resolvedOptions.fromState ?? logic.getInitialState(actorContext, undefined); | ||
const actorScope = createMockActorScope(); | ||
const fromState = resolvedOptions.fromState ?? logic.getInitialSnapshot(actorScope, undefined); | ||
const serializeState = resolvedOptions.serializeState; | ||
@@ -349,3 +346,3 @@ const adjacency = getAdjacencyMap(logic, resolvedOptions); | ||
const serializeState = resolvedOptions.serializeState; | ||
const fromState = resolvedOptions.fromState ?? logic.getInitialState(createMockActorContext(), undefined); | ||
const fromState = resolvedOptions.fromState ?? logic.getInitialSnapshot(createMockActorScope(), undefined); | ||
const adjacency = getAdjacencyMap(logic, resolvedOptions); | ||
@@ -443,4 +440,4 @@ | ||
}, isMachine(logic) ? createDefaultMachineOptions(logic) : createDefaultLogicOptions()); | ||
const actorContext = createMockActorContext(); | ||
const fromState = resolvedOptions.fromState ?? logic.getInitialState(actorContext, | ||
const actorScope = createMockActorScope(); | ||
const fromState = resolvedOptions.fromState ?? logic.getInitialSnapshot(actorScope, | ||
// TODO: fix this | ||
@@ -447,0 +444,0 @@ undefined); |
{ | ||
"name": "@xstate/graph", | ||
"version": "2.0.0-beta.5", | ||
"version": "2.0.0-beta.6", | ||
"description": "XState graph utilities", | ||
@@ -43,8 +43,8 @@ "keywords": [ | ||
"peerDependencies": { | ||
"xstate": "^5.0.0-beta.30" | ||
"xstate": "^5.5.1" | ||
}, | ||
"devDependencies": { | ||
"xstate": "5.0.0-beta.30" | ||
"xstate": "5.5.1" | ||
}, | ||
"dependencies": {} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
40855
1135