-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview.mjs
More file actions
22 lines (20 loc) · 780 Bytes
/
view.mjs
File metadata and controls
22 lines (20 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { intents } from "./sam/actions.mjs";
import routes from "./pages/index.mjs";
export const view = {
init() {
for (let [intent, action] of Object.entries(intents)) window[intent] = action;
let page = new URLSearchParams(window.location.search).get("path")
intents.goto(page || 'home');
window.onpopstate = ()=>{
let path = new URLSearchParams(window.location.search).get("path")
intents.goto(path)
}
},
render(model) {
let { title, content, css } = routes[model.page](model)
document.title = title;
document.querySelector("h1").innerHTML = title;
document.querySelector("main").innerHTML = content;
document.querySelector("style").innerHTML = css;
},
}