-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
43 lines (33 loc) · 853 Bytes
/
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
// import choo
var choo = require('choo')
// import template
var main = require('./templates/main')
// initialize choo
var app = choo()
app.use(function (state, emitter) {
// initialize state
state.animals = [
{type: 'lion', x: 200, y: 100},
{type: 'crocodile', x: 50, y: 300}
]
// add animal
emitter.on('addAnimal', function (data) {
var animals = ['crocodile', 'koala', 'lion', 'tiger', 'walrus']
var type = Math.floor(Math.random() * 5)
var x = data.x
var y = data.y
var obj = {type: animals[type], x: x, y: y}
state.animals.push(obj)
emitter.emit('render')
})
// remove animal
emitter.on('removeAnimal', function (i) {
state.animals.splice(i, 1)
emitter.emit('render')
})
})
// declare routes
app.route('/', main)
app.route('/filter/:type', main)
// start app
app.mount('div')