git ssb

2+

mixmix / ticktack



Tree: 8737709db876420b4db1aea9a323d248fd75fe20

Files: 8737709db876420b4db1aea9a323d248fd75fe20 / app / html / app.js

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

Built with git-ssb-web