Skip to content

Commit

Permalink
fix(init): should run initial trigger and bound signal immediate
Browse files Browse the repository at this point in the history
  • Loading branch information
christianalfoni authored and Guria committed Jun 21, 2016
1 parent a69b327 commit 3ae7273
Show file tree
Hide file tree
Showing 2 changed files with 18 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
8 changes: 6 additions & 2 deletions tests/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,11 @@ module.exports = {
cb()
},

'should trigger on modulesLoaded': function (test) {
'should trigger sync with modulesLoaded event and run signal immediate': function (test) {
test.expect(1)

this.controller.addSignals({
test: [ function checkAction () { test.done() } ]
test: [ function checkAction () { test.ok(true) } ]
})

this.controller.addModules({
Expand All @@ -129,6 +131,8 @@ module.exports = {
'/': 'test'
})
})

test.done()
},

'should delay auto trigger if there is running signals': function (test) {
Expand Down

0 comments on commit 3ae7273

Please sign in to comment.