git ssb

2+

mixmix / ticktack



Tree: 165f298ed05493f7f1381ef269c0eca496e4679b

Files: 165f298ed05493f7f1381ef269c0eca496e4679b / app / html / app.js

1381 bytesRaw
1const nest = require('depnest')
2const values = require('lodash/values')
3const insertCss = require('insert-css')
4const openExternal = require('open-external')
5
6const HyperNav = require('hyper-nav')
7const computed = require('mutant/computed')
8const h = require('mutant/h')
9
10exports.gives = nest({
11 'app.html.app': true,
12 'history.obs.location': true,
13 'history.sync.push': true,
14 'history.sync.back': true,
15})
16
17exports.needs = nest({
18 'app.async.catchLinkClick': 'first',
19 'router.sync.router': 'first',
20 'styles.css': 'first'
21})
22
23exports.create = (api) => {
24
25 var nav = HyperNav(api.router.sync.router, function (nav) {
26 return h('Header', [
27 h('nav', [
28 h('div.back', { 'ev-click': nav.back }, '←'),
29 h('div', { 'ev-click': () => nav.push({page:'home'}) }, 'Home')
30 ]),
31 h('h1', computed(nav.last, e => e.element.title)),
32 ])
33 })
34
35 return nest({
36 'app.html.app': function app () {
37 const css = values(api.styles.css()).join('\n')
38 insertCss(css)
39
40 api.app.async.catchLinkClick(document.body, (link, { isExternal }) => {
41 if (isExternal) return openExternal(link)
42 nav.push(link)
43 })
44 nav.push({page: 'home'})
45 return nav
46 },
47 'history.sync.push': (location) => nav.push(location),
48 'history.sync.back': () => nav.back(),
49 'history.obs.location': () => nav.history,
50 })
51}
52
53
54
55

Built with git-ssb-web