Files: 567e4d92c4e33c4df6f3dbaee5e7a29e2e93eebb / app / html / app.js
1385 bytesRaw
1 | const nest = require('depnest') |
2 | const values = require('lodash/values') |
3 | const insertCss = require('insert-css') |
4 | const openExternal = require('open-external') |
5 | |
6 | const HyperNav = require('hyper-nav') |
7 | const computed = require('mutant/computed') |
8 | const h = require('mutant/h') |
9 | |
10 | exports.gives = nest({ |
11 | 'app.html.app': true, |
12 | 'history.obs.location': true, |
13 | 'history.sync.push': true, |
14 | 'history.sync.back': true, |
15 | }) |
16 | |
17 | exports.needs = nest({ |
18 | 'app.async.catchLinkClick': 'first', |
19 | 'router.sync.router': 'first', |
20 | 'styles.css': 'first' |
21 | }) |
22 | |
23 | exports.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.location, 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