mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-02 11:07:10 +00:00
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:
1 parent
7b7d051edd
commit
97d7269ba5
2 files changed
+14
No files matched your search
@@ -17,6 +17,19 @@ export function actions(generator: () => Action[]): ActionGenerator {
|
||||
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 {
|
||||
return globalThis.__sanderling__.weighted(...entries);
|
||||
}
|
||||
|
||||
@@ -38,4 +38,5 @@ export {
|
||||
taps,
|
||||
waitOnce,
|
||||
weighted,
|
||||
whenRoute,
|
||||
} from "./actions.ts";
|
||||
Reference in new issue
Block a user