add timing API support (#448)

* add timing API support

* fixup! bump package.json
This commit is contained in:
Yoshua Wuyts
2017-03-29 10:43:42 +02:00
committed by GitHub
parent e1462acf1d
commit 4ef1f411b5
4 changed files with 19 additions and 4 deletions
+9
View File
@@ -19,6 +19,8 @@ function Framework (opts) {
curry: true
}
var timingEnabled = opts.timing === undefined ? true : opts.timing
var hasPerformance = window.performance && window.performance.mark
var router = nanorouter(routerOpts)
var bus = nanobus()
var rerender = null
@@ -49,8 +51,15 @@ function Framework (opts) {
function start () {
tree = router(createLocation(), state, emit)
rerender = nanoraf(function () {
if (hasPerformance && timingEnabled) {
window.performance.mark('choo:renderStart')
}
var newTree = router(createLocation(), state, emit)
tree = nanomorph(tree, newTree)
if (hasPerformance && timingEnabled) {
window.performance.mark('choo:renderEnd')
window.performance.measure('choo:render', 'choo:renderStart', 'choo:renderEnd')
}
})
bus.on('render', rerender)