git ssb

2+

mixmix / ticktack



Tree: e5b730f23ccfc66e564bdd503f597a01ed9ed0d1

Files: e5b730f23ccfc66e564bdd503f597a01ed9ed0d1 / app / html / app.js

923 bytesRaw
1const nest = require('depnest')
2const values = require('lodash/values')
3const insertCss = require('insert-css')
4
5exports.gives = nest('app.html.app')
6
7exports.needs = nest({
8 'history.sync.push': 'first',
9 'history.obs.location': 'first',
10 'history.obs.store': 'first',
11 'router.sync.router': 'first',
12 'styles.css': 'first'
13})
14
15exports.create = (api) => {
16 return nest('app.html.app', app)
17
18 function app () {
19 const css = values(api.styles.css()).join('\n')
20 insertCss(css)
21
22 api.history.obs.location()(render)
23 api.history.sync.push({ page: 'home' })
24 }
25
26 function render (location) {
27 const newView = api.router.sync.router(location)
28
29 if (!newView) {
30 api.history.obs.store().pop() // remove bogus location
31 return
32 }
33
34 const oldView = document.body.firstChild
35 oldView
36 ? document.body.replaceChild(newView, oldView)
37 : document.body.appendChild(newView)
38 }
39}
40

Built with git-ssb-web