Files: c0bb55d9b169c5943cb5dfabbd5a58a241a238af / app / html / render.js
776 bytesRaw
1 | const fs = require('fs') |
2 | const h = require('../h') |
3 | const { Value } = require('mutant') |
4 | const insertCss = require('insert-css') |
5 | |
6 | exports.gives = nest([ |
7 | 'app.html.render', |
8 | 'app.mcss.render' |
9 | ]) |
10 | |
11 | exports.needs = nest({ |
12 | 'page.html.render': 'first', |
13 | styles: 'first' |
14 | }) |
15 | |
16 | exports.create = function (api) { |
17 | return { |
18 | app, |
19 | mcss: () => fs.readFileSync(__filename.replace(/js$/, 'mcss'), 'utf8') |
20 | } |
21 | |
22 | function app () { |
23 | process.nextTick(() => insertCss(api.styles())) |
24 | |
25 | var view = Value(getView()) |
26 | var screen = h('App', view) |
27 | |
28 | window.onhashchange = () => view.set(getView()) |
29 | document.body.appendChild(screen) |
30 | |
31 | return screen |
32 | } |
33 | |
34 | function getView () { |
35 | const view = window.location.hash.substring(1) || 'tabs' |
36 | return api.page(view) |
37 | } |
38 | } |
39 | |
40 |
Built with git-ssb-web