Skip to content

Commit

Permalink
fix(init): should run initial signal immediately
Browse files Browse the repository at this point in the history
  • Loading branch information
christianalfoni committed Jun 19, 2016
1 parent 37eeb03 commit 9814b19
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
17 changes: 12 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function Router (routesConfig, options) {
rememberedUrl = null
}

function onUrlChange (event) {
function onUrlChange (event, forceImmediate) {
var url = event ? event.target.value : addressbar.value
url = url.replace(addressbar.origin, '')

Expand All @@ -61,9 +61,16 @@ function Router (routesConfig, options) {
event && event.preventDefault()
addressbar.value = url

signals[map.match].signal(map.values, {
isRouted: true
})
if (forceImmediate === true) {
signals[map.match].signal(map.values, {
isRouted: true,
immediate: true
})
} else {
signals[map.match].signal(map.values, {
isRouted: true
})
}
} else {
if (options.allowEscape) return

Expand Down Expand Up @@ -113,8 +120,8 @@ function Router (routesConfig, options) {
function onModulesLoaded (event) {
if (rememberedUrl) return
if (Array.isArray(initialSignals) && initialSignals.length === 0) {
setTimeout(onUrlChange)
initialSignals = null
onUrlChange(null, true)
}
}

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"pretest": "standard",
"test": "nodeunit tests && npm i cerebral@^0.34.0-rc.5 && nodeunit tests",
"test": "nodeunit tests && npm i cerebral@^0.34.0 && nodeunit tests",
"posttest": "npm i",
"coverage": "nyc --reporter=lcov --reporter=text npm run test",
"postcoverage": "cat ./coverage/lcov.info | coveralls",
Expand Down Expand Up @@ -64,7 +64,7 @@
"validate-commit-msg": "^2.5.0"
},
"peerDependencies": {
"cerebral": "^0.33.31 || ^0.34.0-0"
"cerebral": "^0.33.31 || ^0.34.0"
},
"nyc": {
"exclude": [
Expand Down

0 comments on commit 9814b19

Please sign in to comment.