-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
55 lines (43 loc) · 1.07 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
var h = require('virtual-dom/h')
var loop = require('virtual-raf')
var store = require('./lib/store')
var actions = require('./lib/actions')
var router = require('./lib/router' )
var header = require('./elements/header')(h)
var dataset = require('./elements/dataset')(h)
router.on('/', function () {
console.log('route: /')
if (!tree) init()
})
router.on('/map', function () {
console.log('route: /map')
if (!tree) init()
})
router.on('/list', function () {
console.log('route: /list')
if (!tree) init()
})
router.on('/grid', function () {
console.log('route: /grid')
if (!tree) init()
})
router.start()
function render (state) {
console.log('%c render: ', 'background-color:pink;', state)
return h('div.app', [
header.render(state),
dataset.render(state)
])
}
var tree
function init () {
actions.activeDataset.getPlaces()
var state = store.getState()
tree = loop(state, render, require('virtual-dom'))
document.body.appendChild(tree())
store.subscribe(function () {
var state = store.getState()
tree.update(state)
})
return tree
}