limpiar y reducir dependencias circulares
This commit is contained in:
parent
5b4d9ffa51
commit
1943c829f1
6 changed files with 43 additions and 41 deletions
|
@ -1,5 +1,5 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { currentRoute } from "./lib/routes";
|
import { currentRoute } from "./lib/router";
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<main>
|
<main>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { Schema, type Attrs } from "prosemirror-model";
|
import { Schema, type Attrs } from "prosemirror-model";
|
||||||
import { parse, inject } from "regexparam";
|
import { parse } from "regexparam";
|
||||||
import { routes } from "../lib/routes";
|
import { routes } from "../lib/routes";
|
||||||
|
|
||||||
const hex = (x: string) => ("0" + parseInt(x).toString(16)).slice(-2);
|
const hex = (x: string) => ("0" + parseInt(x).toString(16)).slice(-2);
|
||||||
|
|
37
src/lib/router.ts
Normal file
37
src/lib/router.ts
Normal file
|
@ -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<string, string>;
|
||||||
|
}>({ 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();
|
|
@ -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<string, string>;
|
|
||||||
}>({ component: ChooseWorld });
|
|
||||||
|
|
||||||
export const routes = {
|
export const routes = {
|
||||||
ChooseWorld: "/",
|
ChooseWorld: "/",
|
||||||
CreateWorld: "/create",
|
CreateWorld: "/create",
|
||||||
|
@ -24,21 +5,3 @@ export const routes = {
|
||||||
JoinWorld: "/w/:worldId/join", // password as hash
|
JoinWorld: "/w/:worldId/join", // password as hash
|
||||||
Page: "/w/:worldId/:pageId",
|
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();
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { generateNewWorld } from "../lib/doc";
|
import { generateNewWorld } from "../lib/doc";
|
||||||
import { router, routes } from "../lib/routes";
|
import { routes } from "../lib/routes";
|
||||||
|
import { router } from "../lib/router";
|
||||||
import { writeWorlds } from "../lib/worldStorage";
|
import { writeWorlds } from "../lib/worldStorage";
|
||||||
|
|
||||||
function crear(
|
function crear(
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { router, routes } from "../lib/routes";
|
import { routes } from "../lib/routes";
|
||||||
|
import { router } from "../lib/router";
|
||||||
import { inject } from "regexparam";
|
import { inject } from "regexparam";
|
||||||
import { writeWorlds } from "../lib/worldStorage";
|
import { writeWorlds } from "../lib/worldStorage";
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue