-
Notifications
You must be signed in to change notification settings - Fork 5
/
app.js
38 lines (32 loc) · 867 Bytes
/
app.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
var assert = require('assert')
var nanobus = require('nanobus')
var nanotiming = require('nanotiming')
// Choo Style app without DOM
function App(opts) {
if (!(this instanceof App)) return new App(opts)
opts = opts || {}
// define events used by choo
this.__events = {
INIT: 'app:init',
LOG: 'app:log',
WARN: 'app:warn',
RENDER: 'app:render',
ERROR: 'app:error'
}
this.state = {
__events: this.__events
}
this.emitter = nanobus('app.emit')
}
App.prototype.use = function(cb) {
assert.equal(typeof cb, 'function', 'app.use: cb should be type function')
var msg = 'app.use'
msg = cb.storeName ? msg + '(' + cb.storeName + ')' : msg
var endTiming = nanotiming(msg)
cb(this.state, this.emitter, this)
endTiming()
}
App.prototype.start = function() {
this.emitter.emit(this.__events.INIT)
}
module.exports = App