Files: 8943d5337c4f14e8cf7746fafc3943d3ccc3b1f6 / app / html / app.js
1539 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 | // 'history.sync.push': 'first', |
20 | // 'history.obs.location': 'first', |
21 | // 'history.obs.store': 'first', |
22 | 'router.sync.router': 'first', |
23 | 'styles.css': 'first' |
24 | }) |
25 | |
26 | exports.create = (api) => { |
27 | |
28 | var nav = HyperNav(api.router.sync.router, function (nav) { |
29 | return h('Header', [ |
30 | h('h1', [ |
31 | computed(nav.last, function (e) { return e.element.title }) |
32 | ]), |
33 | h('Nav', [ |
34 | h('div.back', { 'ev-click': nav.back }, '←'), |
35 | h('div', { 'ev-click': () => nav.push({page:'home'}) }, 'Home') |
36 | ]) |
37 | ]) |
38 | }) |
39 | |
40 | return nest({ |
41 | 'app.html.app': function app () { |
42 | const css = values(api.styles.css()).join('\n') |
43 | insertCss(css) |
44 | |
45 | api.app.async.catchLinkClick(document.body, (link, { isExternal }) => { |
46 | if (isExternal) return openExternal(link) |
47 | nav.push(link) |
48 | }) |
49 | nav.push({page: 'home'}) |
50 | document.body.appendChild(nav) |
51 | }, |
52 | 'history.sync.push': (location) => nav.push(location), |
53 | 'history.sync.back': () => nav.back(), |
54 | 'history.obs.location': () => nav.history, |
55 | }) |
56 | } |
57 | |
58 |
Built with git-ssb-web