feat(spec): add whenRoute action gating helper

whenRoute(route, allowedRoutes, body) wraps an actions() generator
that returns [] unless route.current matches one of the allowed
values. Accepts a single route or an array.
This commit is contained in:
pj committed 2026-04-27 00:05:30 +07:00
1 parent 7b7d051edd
commit 97d7269ba5
2 files changed
+14

No files matched your search

+13
View File
@@ -17,6 +17,19 @@ export function actions(generator: () => Action[]): ActionGenerator {
return globalThis.__sanderling__.actions(generator); return globalThis.__sanderling__.actions(generator);
} }
export function whenRoute(
routeExtractor: { readonly current: string | null },
routes: string | readonly string[],
body: () => Action[],
): ActionGenerator {
const allowed = typeof routes === "string" ? [routes] : routes;
return actions(() => {
const current = routeExtractor.current;
if (current === null || !allowed.includes(current)) return [];
return body();
});
}
export function weighted(...entries: WeightedEntry[]): ActionGenerator { export function weighted(...entries: WeightedEntry[]): ActionGenerator {
return globalThis.__sanderling__.weighted(...entries); return globalThis.__sanderling__.weighted(...entries);
} }
+1
View File
@@ -38,4 +38,5 @@ export {
taps, taps,
waitOnce, waitOnce,
weighted, weighted,
whenRoute,
} from "./actions.ts"; } from "./actions.ts";