Skip to content

Commit

Permalink
Finished! Sort of
Browse files Browse the repository at this point in the history
  • Loading branch information
trentmwillis committed May 20, 2016
1 parent 0db566c commit 6462567
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/router/handler-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
7 changes: 6 additions & 1 deletion lib/router/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
3 changes: 0 additions & 3 deletions test/tests/query_params_async_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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' } });
}
},
Expand Down
5 changes: 3 additions & 2 deletions test/tests/router_async_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {}));
},

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 6462567

Please sign in to comment.