Skip to content

Commit

Permalink
more timings
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshuawuyts committed Oct 8, 2017
1 parent 0497302 commit 236e73f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = Choo
var HISTORY_OBJECT = {}

function Choo (opts) {
var timing = nanotiming('choo.constructor')
if (!(this instanceof Choo)) return new Choo(opts)
opts = opts || {}

Expand Down Expand Up @@ -54,9 +55,11 @@ function Choo (opts) {
self.state.title = title
if (self._hasWindow) document.title = title
})
timing()
}

Choo.prototype.route = function (route, handler) {
var timing = nanotiming("choo.route('" + route + "')")
assert.equal(typeof route, 'string', 'choo.route: route should be type string')
assert.equal(typeof handler, 'function', 'choo.handler: route should be type function')

Expand All @@ -65,27 +68,29 @@ Choo.prototype.route = function (route, handler) {
return function () {
self.state.params = params
self.state.route = route
var routeTiming = nanotiming("choo.route('" + route + "')")
var routeTiming = nanotiming("choo.router('" + route + "')")
var res = handler(self.state, function (eventName, data) {
self.emitter.emit(eventName, data)
})
routeTiming()
return res
}
})
timing()
}

Choo.prototype.use = function (cb) {
assert.equal(typeof cb, 'function', 'choo.use: cb should be type function')
var msg = 'choo.use'
msg = cb.storeName ? msg + '(' + cb.storeName + ')' : msg
var endTiming = nanotiming(msg)
var timing = nanotiming(msg)
cb(this.state, this.emitter, this)
endTiming()
timing()
}

Choo.prototype.start = function () {
assert.equal(typeof window, 'object', 'choo.start: window was not found. .start() must be called in a browser, use .toString() if running in Node')
var timing = nanotiming('choo.start')

var self = this
if (this._historyEnabled) {
Expand Down Expand Up @@ -155,10 +160,12 @@ Choo.prototype.start = function () {
self._loaded = true
})

timing()
return this._tree
}

Choo.prototype.mount = function mount (selector) {
var timing = nanotiming("choo.mount('" + selector + "')")
assert.equal(typeof window, 'object', 'choo.mount: window was not found. .mount() must be called in a browser, use .toString() if running in Node')
assert.equal(typeof selector, 'string', 'choo.mount: selector should be type string')

Expand All @@ -180,6 +187,7 @@ Choo.prototype.mount = function mount (selector) {

renderTiming()
})
timing()
}

Choo.prototype.toString = function (location, state) {
Expand Down

0 comments on commit 236e73f

Please sign in to comment.