Files: 1445c8065b8c93c516ef1df601881a70c5201081 / modules_core / app.js
1215 bytesRaw
1 | const fs = require('fs') |
2 | const h = require('../h') |
3 | const { Value } = require('@mmckegg/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 | window.addEventListener('error', window.onError = displayError) |
32 | |
33 | return screen |
34 | } |
35 | |
36 | function getView () { |
37 | const view = window.location.hash.substring(1) || 'tabs' |
38 | return api.screen_view(view) |
39 | } |
40 | } |
41 | |
42 | function displayError (e) { |
43 | document.body.querySelector('.\\.content').appendChild( |
44 | h('div.page', [ |
45 | h('Error', { title: e.message }, [ |
46 | h('h1', e.message), |
47 | h('big', [ |
48 | h('code', e.filename + ':' + e.lineno) |
49 | ]), |
50 | h('pre', e.error |
51 | ? (e.error.stack || e.error.toString()) |
52 | : e.toString() |
53 | ) |
54 | ]) |
55 | ]) |
56 | ) |
57 | } |
58 | |
59 |
Built with git-ssb-web