From 1943c829f14ab880aa703e3b7e4d08612e4415a8 Mon Sep 17 00:00:00 2001 From: Nulo Date: Sat, 25 Mar 2023 23:30:12 +0000 Subject: [PATCH] limpiar y reducir dependencias circulares --- src/App.svelte | 2 +- src/editor/schema.ts | 2 +- src/lib/router.ts | 37 ++++++++++++++++++++++++++++++++++++ src/lib/routes.ts | 37 ------------------------------------ src/views/CreateWorld.svelte | 3 ++- src/views/JoinWorld.svelte | 3 ++- 6 files changed, 43 insertions(+), 41 deletions(-) create mode 100644 src/lib/router.ts diff --git a/src/App.svelte b/src/App.svelte index deb5cb0..e02da57 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -1,5 +1,5 @@
diff --git a/src/editor/schema.ts b/src/editor/schema.ts index 5c44419..434eadb 100644 --- a/src/editor/schema.ts +++ b/src/editor/schema.ts @@ -1,5 +1,5 @@ import { Schema, type Attrs } from "prosemirror-model"; -import { parse, inject } from "regexparam"; +import { parse } from "regexparam"; import { routes } from "../lib/routes"; const hex = (x: string) => ("0" + parseInt(x).toString(16)).slice(-2); diff --git a/src/lib/router.ts b/src/lib/router.ts new file mode 100644 index 0000000..d79b7bf --- /dev/null +++ b/src/lib/router.ts @@ -0,0 +1,37 @@ +import navaid from "navaid"; +import { writable } from "svelte/store"; + +import ChooseWorld from "../views/ChooseWorld.svelte"; +import CreateWorld from "../views/CreateWorld.svelte"; +import JoinWorld from "../views/JoinWorld.svelte"; +import NotFound from "../views/NotFound.svelte"; +import Page from "../views/Page.svelte"; +import ShareWorld from "../views/ShareWorld.svelte"; +import { routes } from "./routes"; + +export let currentRoute = writable<{ + // XXX: in lack of a better type for Svelte components + component: any; + params?: Record; +}>({ component: ChooseWorld }); + +export let router = navaid("/", () => + currentRoute.set({ component: NotFound }) +); +router.on(routes.ChooseWorld, () => + currentRoute.set({ component: ChooseWorld }) +); +router.on(routes.CreateWorld, () => + currentRoute.set({ component: CreateWorld }) +); +router.on(routes.ShareWorld, (params) => + currentRoute.set({ component: ShareWorld, params }) +); +router.on(routes.JoinWorld, (params) => + currentRoute.set({ component: JoinWorld, params }) +); +router.on(routes.Page, (params) => + currentRoute.set({ component: Page, params }) +); + +router.listen(); diff --git a/src/lib/routes.ts b/src/lib/routes.ts index 0527e75..b26b9b1 100644 --- a/src/lib/routes.ts +++ b/src/lib/routes.ts @@ -1,22 +1,3 @@ -import navaid from "navaid"; -import { writable } from "svelte/store"; - -import ChooseWorld from "../views/ChooseWorld.svelte"; -import CreateWorld from "../views/CreateWorld.svelte"; -import JoinWorld from "../views/JoinWorld.svelte"; -import NotFound from "../views/NotFound.svelte"; -import Page from "../views/Page.svelte"; -import ShareWorld from "../views/ShareWorld.svelte"; - -export let router = navaid("/", () => - currentRoute.set({ component: NotFound }) -); -export let currentRoute = writable<{ - // XXX: in lack of a better type for Svelte components - component: any; - params?: Record; -}>({ component: ChooseWorld }); - export const routes = { ChooseWorld: "/", CreateWorld: "/create", @@ -24,21 +5,3 @@ export const routes = { JoinWorld: "/w/:worldId/join", // password as hash Page: "/w/:worldId/:pageId", }; - -router.on(routes.ChooseWorld, () => - currentRoute.set({ component: ChooseWorld }) -); -router.on(routes.CreateWorld, () => - currentRoute.set({ component: CreateWorld }) -); -router.on(routes.ShareWorld, (params) => - currentRoute.set({ component: ShareWorld, params }) -); -router.on(routes.JoinWorld, (params) => - currentRoute.set({ component: JoinWorld, params }) -); -router.on(routes.Page, (params) => - currentRoute.set({ component: Page, params }) -); - -router.listen(); diff --git a/src/views/CreateWorld.svelte b/src/views/CreateWorld.svelte index fb41d31..3d1efae 100644 --- a/src/views/CreateWorld.svelte +++ b/src/views/CreateWorld.svelte @@ -1,6 +1,7 @@