Files: 0f5f9e807fb3a5d6443be8feb5b7c37d511ac125 / app / html / app.js
1405 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.html.header': 'first', |
19 | 'app.async.catchLinkClick': 'first', |
20 | 'router.sync.router': 'first', |
21 | 'styles.css': 'reduce', |
22 | 'about.async.suggest': 'first', |
23 | 'channel.async.suggest': 'first', |
24 | }) |
25 | |
26 | exports.create = (api) => { |
27 | var nav = null |
28 | |
29 | return nest({ |
30 | 'app.html.app': function app () { |
31 | |
32 | // DIRTY HACK - initializes the suggestion indexes |
33 | api.about.async.suggest() |
34 | api.channel.async.suggest() |
35 | |
36 | const css = values(api.styles.css()).join('\n') |
37 | insertCss(css) |
38 | |
39 | api.app.async.catchLinkClick(document.body, (link, { isExternal }) => { |
40 | if (isExternal) return openExternal(link) |
41 | nav.push(link) |
42 | }) |
43 | |
44 | nav = HyperNav( |
45 | api.router.sync.router, |
46 | api.app.html.header |
47 | ) |
48 | |
49 | nav.push({page: 'home'}) |
50 | return 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 | |
59 | |
60 |
Built with git-ssb-web