-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: split schedule in dynamic (new) and static
- Loading branch information
1 parent
8a72c1c
commit 3362755
Showing
20 changed files
with
406 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import type { Plugin } from "../../plugin" | ||
import { LogicalButtonInput, PhysicalButtonInput } from "../resources" | ||
import { Schedule } from "../../schedule" | ||
import { Last } from "../../schedule" | ||
import { resetLogicalButtonInput, resetPhysicalButtonInput } from "../systems/buttonInput" | ||
import { Commands } from "../../commands" | ||
|
||
export const DefaultPlugin: Plugin = (app) => { | ||
Commands.insertResource(new LogicalButtonInput()) | ||
Commands.insertResource(new PhysicalButtonInput()) | ||
app.addSystem(Schedule.Last, resetLogicalButtonInput) | ||
app.addSystem(Schedule.Last, resetPhysicalButtonInput) | ||
app.addSystem(Last, resetLogicalButtonInput) | ||
app.addSystem(Last, resetPhysicalButtonInput) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from "./default" | ||
export * from "./html" | ||
export * from "./router" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { App } from "../../app" | ||
import { Location } from "../state" | ||
import { updateLocationState } from "../systems/location" | ||
import { Startup } from "../../schedule" | ||
import { BasePath } from "../resources/basePath" | ||
|
||
export function RouterPlugin(app: App) { | ||
app.insertResource(new BasePath("/")).insertState(Location.windowLocation()).addSystem(Startup, updateLocationState) | ||
} | ||
|
||
RouterPlugin.withBasePath = (basePath: string) => (app: App) => { | ||
app.insertResource(new BasePath(basePath)) | ||
.insertState(Location.windowLocation()) | ||
.addSystem(Startup, updateLocationState) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export class BasePath { | ||
public readonly basePath: string | ||
|
||
public constructor(basePath: string) { | ||
this.basePath = basePath | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { nextState } from "../../state" | ||
import { Location } from "../state" | ||
import { inWorld, useWorld } from "../../world" | ||
|
||
export function updateLocationState() { | ||
const origin = window.location.origin | ||
const world = useWorld() | ||
|
||
window.addEventListener("popstate", (ev) => { | ||
ev.preventDefault() | ||
inWorld(world, () => { | ||
nextState(Location.windowLocation()) | ||
}) | ||
}) | ||
|
||
window.addEventListener("click", (ev) => { | ||
let ns: Location | null = null | ||
|
||
for (const el of parentChain(ev.target as Element)) { | ||
if (el.tagName === "A") { | ||
const url = new URL((el as HTMLAnchorElement).href) | ||
if (url.origin !== origin) { | ||
return | ||
} | ||
ev.preventDefault() | ||
history.pushState({}, "", (el as HTMLAnchorElement).href) | ||
ns = new Location(url.pathname) | ||
break | ||
} | ||
} | ||
|
||
if (ns) { | ||
inWorld(world, () => { | ||
nextState(ns!) | ||
}) | ||
} | ||
}) | ||
} | ||
|
||
function* parentChain(el: Element): IterableIterator<Element> { | ||
yield el | ||
let p = el.parentElement | ||
while (p) { | ||
yield p | ||
p = p.parentElement | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { useWorld } from "./world" | ||
|
||
export function res<T>(type: { new (...args: any[]): T }): T { | ||
export function res<T extends Object>(type: { new (...args: any[]): T }): T { | ||
const world = useWorld() | ||
return world.getResource(type) | ||
} |
Oops, something went wrong.