-
Notifications
You must be signed in to change notification settings - Fork 524
/
Copy pathindex.js
70 lines (60 loc) · 1.87 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import Vue from 'vue'
import upperFirst from 'lodash/upperFirst'
import camelCase from 'lodash/camelCase'
import Store from './store.js'
import styles from './styles/global.scss'
const requireComponent = require.context(
'./components', // The relative path of the components folder
true, // Whether or not to look in subfolders
/[A-Za-z]\w+\.vue$/ // The regular expression used to match base component filenames
)
requireComponent.keys().forEach(fileName => {
const componentConfig = requireComponent(fileName)
const componentName = upperFirst(
camelCase(
// Strip the leading `'./` and extension from the filename
fileName.replace(/^\.\/(.*)\.\w+$/, '$1')
)
)
Vue.component(
componentName,
componentConfig.default || componentConfig
)
})
var state = JSON.parse(document.getElementById('initialstate').innerHTML)
Store.loadState(state)
global.receveUIState = (jsonState) => {
Store.loadState(JSON.parse(jsonState))
}
window.setInterval(() => {
Store.state.wtime += 2
}, 200)
var app = new Vue({
el: '#app',
data: Store.state,
render (createElement) {
return createElement('view-' + this.$root.$data.active)
},
watch: {
state: {
handler(val) {
if (Store.isUpdating) return
var r = new XMLHttpRequest()
r.open("GET", "?src=" + this.uiref + "&vueuistateupdate=" + encodeURIComponent(JSON.stringify(Store.state)), true);
r.send()
},
deep: true
}
}
})
var header = new Vue({
el: '#header',
data: Store.state
})
if (document.getElementById("dapp")) {
var dapp = new Vue({
el: '#dapp',
data: Store.state,
template: '<div><h1>Current data of UI:</h1><pre>{{ JSON.stringify(this.$root.$data, null, \' \') }}</pre></div>'
})
}