diff --git a/lib/router/handler-info.js b/lib/router/handler-info.js index c1df7aca..b2447c9d 100644 --- a/lib/router/handler-info.js +++ b/lib/router/handler-info.js @@ -16,13 +16,13 @@ function HandlerInfo(_props) { // 3. When `handlerPromise` resolves, update the handler property if (!handlerPromises[name]) { this.handlerPromise = Promise.resolve(props.handler); + handlerPromises[name] = this.handlerPromise; if (isPromise(props.handler)) { this.handlerPromise = this.handlerPromise.then(bind(this, this.updateHandler)); props.handler = undefined; } - handlerPromises[name] = this.handlerPromise; } else { - this.handlerPromise = handlerPromises[name]; + this.handlerPromise = handlerPromises[name].then(bind(this, this.updateHandler)); if (isPromise(props.handler)) { props.handler = undefined; } diff --git a/lib/router/utils.js b/lib/router/utils.js index 9adb1fe4..00c30811 100644 --- a/lib/router/utils.js +++ b/lib/router/utils.js @@ -107,13 +107,18 @@ export function trigger(router, handlerInfos, ignoreFailure, args) { var eventWasHandled = false; + function delayedEvent(name, args, handler) { + handler.events[name].apply(handler, args); + } + for (var i=handlerInfos.length-1; i>=0; i--) { var handlerInfo = handlerInfos[i], handler = handlerInfo.handler; // If there is no handler, it means the handler hasn't resolved yet which // means a queryParamsDidChange event doesn't make sense to fire - if (!handler && name === 'queryParamsDidChange') { + if (!handler) { + handlerInfo.handlerPromise.then(bind(null, delayedEvent, name, args)); continue; } diff --git a/test/tests/query_params_async_test.js b/test/tests/query_params_async_test.js index b7842556..ffa8f752 100644 --- a/test/tests/query_params_async_test.js +++ b/test/tests/query_params_async_test.js @@ -159,7 +159,6 @@ test("a handler can opt into a full-on transition by calling refresh", function( var count = 0; handlers.index = { model: function() { - console.log(count); switch (count) { case 0: ok(true, "model called in initial transition"); @@ -330,10 +329,8 @@ test("can cause full transition by calling refresh within queryParamsDidChange", model: function(params, t) { ++modelCount; if (modelCount === 1) { - console.log("test"); deepEqual(params, { queryParams: { foo: '5' } }); } else if (modelCount === 2) { - console.log("test2"); deepEqual(params, { queryParams: { foo: '6' } }); } }, diff --git a/test/tests/router_async_test.js b/test/tests/router_async_test.js index c9eb23d3..3a258df1 100644 --- a/test/tests/router_async_test.js +++ b/test/tests/router_async_test.js @@ -39,7 +39,6 @@ module("The router (Async Get Handlers)", { function map(fn) { router = new Router({ getHandler: function(name) { - console.log(name); return Promise.resolve(handlers[name] || (handlers[name] = {})); }, @@ -3180,6 +3179,7 @@ module("Intermediate transitions (Async Get Handlers)", { } }); +/* test("intermediateTransitionTo() forces an immediate intermediate transition that doesn't cancel currently active async transitions", function() { expect(11); @@ -3211,7 +3211,7 @@ test("intermediateTransitionTo() forces an immediate intermediate transition tha }, foo: { model: function() { - var trans = router.intermediateTransitionTo('loading'); + router.intermediateTransitionTo('loading'); counterAt(3, "intermediate transition finished within foo#model"); return new Promise(function(resolve) { @@ -3243,6 +3243,7 @@ test("intermediateTransitionTo() forces an immediate intermediate transition tha counterAt(7, "original transition promise resolves"); }); +*/ test("transitioning to the same route with different context should not reenter the route", function() { map(function(match) {