import { computed, NAME, pattern, UI, type VNode, Writable, } from "commonfabric"; import { type RouteContext, Router } from "./router.tsx"; // deno-lint-ignore no-empty-interface interface HomeInput {} export interface HomeOutput { [NAME]: string; [UI]: VNode; } // deno-lint-ignore no-empty-interface interface BooksInput {} export interface BooksOutput { [NAME]: string; [UI]: VNode; } interface BookInput { route: RouteContext; } export interface BookOutput { [NAME]: string; [UI]: VNode; } // deno-lint-ignore no-empty-interface interface MainInput {} export interface MainOutput { [NAME]: string; [UI]: VNode; } const Home = pattern(() => { return { [NAME]: "Home", [UI]: (

The Home pattern

Books
), }; }); const Books = pattern(() => { return { [NAME]: "Books", [UI]: (

The Books pattern

), }; }); const Book = pattern(({ route }) => { const bookId = computed(() => route.params.id); const edition = computed(() => route.query.edition || "unknown"); return { [NAME]: computed(() => `Book ${bookId}`), [UI]: (

Book ID: {bookId}

Edition: {edition}

), }; }); export default pattern(() => { const routeContext = new Writable({ path: "/", params: {}, query: {}, }); const { path, Pattern } = Router({ routeContext, routes: [ { path: "/", pattern: Home({}) }, { path: "/books", pattern: Books({}) }, { path: "/books/{id}", pattern: Book({ route: routeContext }) }, ], }); return { [NAME]: "Main", [UI]: (
Current path: {path}
{Pattern}
), }; });