A machine that arrives as a value can still be commanded, so a name may name its state (#58)
game-maker / suite (push) Successful in 6m12s
game-maker / suite (push) Successful in 6m12s
Set state and State branch derived their ports from the graph, so a machine that came out of a variable or a list had no ports at all: nothing to set, nowhere to branch. It could be passed around but not operated. stateByName() resolves id first, then name; a name two states carry answers with nothing, the same rule transitionTo already follows for two transitions of one name — without something in the graph that decides between them, any pick would be a guess. Set state by name takes the machine and a text, and has a second exec output not found, so a typo is not swallowed in silence. State branch gains a derived else that fires whenever no state output matches — no state set, a state of another machine, or a machine that arrives as a value and therefore has no state outputs at all. A flow that enters State branch now always leaves it somewhere. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7e5003b590
commit
1135205d69
7 files changed
+218
-14
No files matched your search
@@ -76,6 +76,19 @@ export function transitionTo(machine: StateMachine, current: string, name: strin
|
||||
return targets.length === 1 ? targets[0]! : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* The state a text names: its id where one matches, else the state of that name. A name two states
|
||||
* share answers nothing – the same rule `transitionTo` follows, and for the same reason: with
|
||||
* nothing in the graph to pick between them, either choice would be a guess. `''` for no match,
|
||||
* which is what a node reports as "not found" rather than moving the machine somewhere arbitrary.
|
||||
*/
|
||||
export function stateByName(machine: StateMachine | null, text: string): string {
|
||||
if (!machine || !text) return '';
|
||||
if (machine.states.some((s) => s.id === text)) return text;
|
||||
const named = machine.states.filter((s) => s.name === text);
|
||||
return named.length === 1 ? named[0]!.id : '';
|
||||
}
|
||||
|
||||
/** The names a machine's transitions carry, deduped and in edge order – what a node may ask for. */
|
||||
export function transitionNames(machine: StateMachine | null): string[] {
|
||||
return [...new Set((machine?.transitions ?? []).map((t) => t.name).filter((name) => name))];
|
||||
|
||||
Reference in new issue
Block a user