From 38cdbf6b208e419534ce1c878d56d0f477c0831d Mon Sep 17 00:00:00 2001 From: Shiba <44804845+DeepDoge@users.noreply.github.com> Date: Sat, 16 Nov 2024 21:24:56 +0000 Subject: [PATCH] ok i sleep --- project/app/src/features/feed/routes.ts | 2 +- project/app/src/features/profile/routes.ts | 2 +- project/app/src/shared/router/index.ts | 65 +++++++++------------- 3 files changed, 28 insertions(+), 41 deletions(-) diff --git a/project/app/src/features/feed/routes.ts b/project/app/src/features/feed/routes.ts index b5ec2a3..0ac8635 100644 --- a/project/app/src/features/feed/routes.ts +++ b/project/app/src/features/feed/routes.ts @@ -8,7 +8,7 @@ export const feedRoutes = { .transform((feedId) => ({ feedId })) .parse(pathname.split("/")); }, - toPathname(data) { + toPathname(data: { feedId: FeedId }) { return data.feedId; }, render(data) { diff --git a/project/app/src/features/profile/routes.ts b/project/app/src/features/profile/routes.ts index ce9ed32..5dddca7 100644 --- a/project/app/src/features/profile/routes.ts +++ b/project/app/src/features/profile/routes.ts @@ -16,7 +16,7 @@ export const profileRoutes = { })) .parse(pathname); }, - toPathname(data) { + toPathname(data: { address: Address }) { return data.address; }, render(data) { diff --git a/project/app/src/shared/router/index.ts b/project/app/src/shared/router/index.ts index 1d44a18..20bcb7c 100644 --- a/project/app/src/shared/router/index.ts +++ b/project/app/src/shared/router/index.ts @@ -33,7 +33,7 @@ export namespace Router { return `#/${pathname}${searchParams?.size ? `?${searchParams}` : ""}`; } - export class Client }> { + export class Client { public readonly routes: TRoutes; public readonly route = pathname.derive((pathname) => { for (const [name, route] of Object.entries(this.routes)) { @@ -68,68 +68,55 @@ export namespace Router { } } - export declare namespace Route { - type Init< - TData, - TRender extends MemberOf, - TTitle extends MemberOf, - > = { - toPathname(data: TData): string; - fromPathname(pathname: string): TData; - render(data: TData): TRender; - renderHeaderEnd?(data: TData): MemberOf; - title(data: TData): TTitle; - }; - } - export declare class Route< - TData = unknown, - TRender extends MemberOf = MemberOf, - TTitle extends MemberOf = MemberOf, - > { - constructor(init: Route.Init); - - fromPathname(pathname: string): TData | undefined; - toPathname(data: TData): string; - toHref(data: TData): string; - render(data: TData): TRender; - renderHeaderEnd(data: TData): MemberOf; - title(data: TData): TTitle; - } - Router.Route = class< - TData = unknown, + export type RouteInit< + TDataIn, + TDataOut extends TDataIn, + TRender extends MemberOf, + TTitle extends MemberOf, + > = { + toPathname(data: TDataIn): string; + fromPathname(pathname: string): TDataOut; + render(data: TDataOut): TRender; + renderHeaderEnd?(data: TDataOut): MemberOf; + title(data: TDataOut): TTitle; + }; + + export class Route< + TDataIn = unknown, + TDataOut extends TDataIn = TDataIn, TRender extends MemberOf = MemberOf, TTitle extends MemberOf = MemberOf, > { - readonly #init: Route.Init; + readonly #init: RouteInit; - constructor(init: Route.Init) { + constructor(init: RouteInit) { this.#init = init; } - public fromPathname(pathname: string): TData | undefined { + public fromPathname(pathname: string): TDataOut | undefined { return catchError(() => this.#init.fromPathname(pathname), [Error]).data; } - public toPathname(data: TData): string { + public toPathname(data: TDataIn): string { return this.#init.toPathname(data); } - public toHref(data: TData): string { + public toHref(data: TDataIn): string { return hrefFrom(this.toPathname(data)); } - public render(data: TData): TRender { + public render(data: TDataOut): TRender { return this.#init.render(data); } - public renderHeaderEnd(data: TData) { + public renderHeaderEnd(data: TDataOut) { return this.#init.renderHeaderEnd?.(data) ?? null; } - public title(data: TData): TTitle { + public title(data: TDataOut): TTitle { return this.#init.title(data); } - }; + } export class SearchParam extends Signal.State { public readonly name: string;