diff --git a/index.js b/index.js index 36d2f66..daf8a3a 100644 --- a/index.js +++ b/index.js @@ -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, '') @@ -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 @@ -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) } } diff --git a/tests/browser.js b/tests/browser.js index 9ee2712..d558196 100644 --- a/tests/browser.js +++ b/tests/browser.js @@ -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({ @@ -129,6 +131,8 @@ module.exports = { '/': 'test' }) }) + + test.done() }, 'should delay auto trigger if there is running signals': function (test) {