From 27e9e892e74b852fd224a4a3b7c2773a040d8041 Mon Sep 17 00:00:00 2001 From: Ken Sternberg Date: Thu, 14 Mar 2024 14:40:19 -0700 Subject: [PATCH] web: update the type names for routes. While writing up the commit message for the previous commit, I realized that I didn't really like the typenames as they're outlaid in `routeUtils`. This is much more explicit, describing the four types of routes we have: ListRoute, ViewRoute, InternalRedirect, ExternalRedirect. --- web/src/elements/router/routeUtils.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/web/src/elements/router/routeUtils.ts b/web/src/elements/router/routeUtils.ts index 702a3713f1..303dfa1224 100644 --- a/web/src/elements/router/routeUtils.ts +++ b/web/src/elements/router/routeUtils.ts @@ -3,13 +3,17 @@ import { P, match } from "ts-pattern"; import { TemplateResult } from "lit"; -type RouteInvoke = - | ((_1: RouteArgs) => Promise>) - | (() => Promise>); +type ListRoute = () => Promise>; +type ViewRoute = (_1: RouteArgs) => Promise>; +type InternalRedirect = string; +type ExternalRedirect = [string, boolean]; -type _RawRedirect = [string, string | [string, boolean]]; -type _RawRoute = [string, RouteInvoke]; -export type RawRoute = _RawRoute | _RawRedirect; +type RouteInvoke = ViewRoute | ListRoute; + +type RedirectRoute = [string, InternalRedirect | ExternalRedirect]; +type PageRoute = [string, RouteInvoke]; + +export type RawRoute = PageRoute | RedirectRoute; // eslint-disable-next-line @typescript-eslint/no-explicit-any const isLoader = (v: any): v is RouteInvoke => typeof v === "function";