git ssb

16+

Dominic / patchbay



Tree: f5236ec7d9785b1d484e110695fedb1d602d6579

Files: f5236ec7d9785b1d484e110695fedb1d602d6579 / modules_core / app.js

1117 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.appendChild(
44 h('Error', [
45 h('h1', e.message),
46 h('big', [
47 h('code', e.filename + ':' + e.lineno)
48 ]),
49 h('pre', e.error
50 ? (e.error.stack || e.error.toString())
51 : e.toString()
52 )
53 ])
54 )
55}
56
57

Built with git-ssb-web