git ssb

16+

Dominic / patchbay



Tree: 0c056b3b97a2efd2fceb281c3d99ac1fe864be47

Files: 0c056b3b97a2efd2fceb281c3d99ac1fe864be47 / modules_core / app.js

1215 bytesRaw
1const fs = require('fs')
2const h = require('../h')
3const { Value } = require('@mmckegg/mutant')
4const insertCss = require('insert-css')
5
6exports.needs = {
7 screen_view: 'first',
8 styles: 'first'
9}
10
11exports.gives = {
12 app: true,
13 mcss: true
14}
15
16exports.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
42function 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