Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

index: add raf guard #135

Merged
merged 2 commits into from
Jul 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const href = require('sheet-router/href')
const hash = require('sheet-router/hash')
const hashMatch = require('hash-match')
const barracks = require('barracks')
const nanoraf = require('nanoraf')
const assert = require('assert')
const xtend = require('xtend')
const yo = require('yo-yo')
Expand All @@ -22,6 +23,7 @@ function choo (opts) {
var _defaultRoute = null
var _rootNode = null
var _routes = null
var _frame = null

start.toString = toString
start.router = router
Expand Down Expand Up @@ -85,8 +87,13 @@ function choo (opts) {
opts.onStateChange(data, state, prev, name, createSend)
}

const newTree = _router(state.location.pathname, state, prev)
_rootNode = yo.update(_rootNode, newTree)
if (!_frame) {
_frame = nanoraf(function (state, prev) {
const newTree = _router(state.location.pathname, state, prev)
_rootNode = yo.update(_rootNode, newTree)
})
}
_frame(state, prev)
}

// register all routes on the router
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"document-ready": "~1.0.2",
"global": "^4.3.0",
"hash-match": "^1.0.2",
"nanoraf": "^2.0.0",
"sheet-router": "^3.1.0",
"xhr": "^2.2.0",
"xtend": "^4.0.1",
Expand Down