Files: bd801655ad6ba5f09a31d3037c468c45f3ff0bb7 / modules_core / app.js
1314 bytesRaw
1 | const fs = require('fs') |
2 | const h = require('../h') |
3 | const { Value } = require('mutant') |
4 | const insertCss = require('insert-css') |
5 | |
6 | exports.needs = { |
7 | screen_view: 'first', |
8 | styles: 'first' |
9 | } |
10 | |
11 | exports.gives = { |
12 | app: true, |
13 | mcss: true |
14 | } |
15 | |
16 | exports.create = function (api) { |
17 | return { |
18 | app, |
19 | mcss: () => fs.readFileSync(__filename.replace(/js$/, 'mcss'), 'utf8') |
20 | } |
21 | |
22 | function app () { |
23 | process.nextTick(() => insertCss(api.styles())) |
24 | |
25 | var view = Value(getView()) |
26 | var screen = h('App', view) |
27 | |
28 | window.onhashchange = () => view.set(getView()) |
29 | document.body.appendChild(screen) |
30 | |
31 | // tabs (another core module) currently handles this |
32 | // window.addEventListener('error', window.onError = displayError) |
33 | |
34 | return screen |
35 | } |
36 | |
37 | function getView () { |
38 | const view = window.location.hash.substring(1) || 'tabs' |
39 | return api.screen_view(view) |
40 | } |
41 | } |
42 | |
43 | // function displayError (e) { |
44 | // document.body.querySelector('.\\.content').appendChild( |
45 | // h('div.page', [ |
46 | // h('Error', { title: e.message }, [ |
47 | // h('h1', e.message), |
48 | // h('big', [ |
49 | // h('code', e.filename + ':' + e.lineno) |
50 | // ]), |
51 | // h('pre', e.error |
52 | // ? (e.error.stack || e.error.toString()) |
53 | // : e.toString() |
54 | // ) |
55 | // ]) |
56 | // ]) |
57 | // ) |
58 | // } |
59 | |
60 |
Built with git-ssb-web