git ssb

2+

mixmix / ticktack



Tree: f1e1c0f3aedd176590017f411e2a923155169442

Files: f1e1c0f3aedd176590017f411e2a923155169442 / app / html / app.js

1250 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.obs.store()(his => console.log('history', his)) // REMOVE)
32 api.history.sync.push({ page: 'home' })
33 }
34
35 function render (location) {
36 const newView = api.router.sync.router(location)
37
38 if (!newView) {
39 api.history.obs.store().pop() // remove bogus location
40 return
41 }
42
43 const oldView = document.body.firstChild
44 oldView
45 ? document.body.replaceChild(newView, oldView)
46 : document.body.appendChild(newView)
47 }
48}
49

Built with git-ssb-web