Skip to content

Commit

Permalink
Merge pull request #14087 from trentmwillis/lazy-handler
Browse files Browse the repository at this point in the history
[BUGFIX beta] Check that handler exists before triggering event
  • Loading branch information
rwjblue authored Aug 19, 2016
2 parents 4d6b7d0 + ce72c7e commit 205e5ac
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/ember-routing/lib/system/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,7 @@ export function triggerEvent(handlerInfos, ignoreFailure, args) {
handlerInfo = handlerInfos[i];
handler = handlerInfo.handler;

if (handler.actions && handler.actions[name]) {
if (handler && handler.actions && handler.actions[name]) {
if (handler.actions[name].apply(handler, args) === true) {
eventWasHandled = true;
} else {
Expand Down
66 changes: 65 additions & 1 deletion packages/ember-routing/tests/system/router_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import HashLocation from 'ember-routing/location/hash_location';
import HistoryLocation from 'ember-routing/location/history_location';
import AutoLocation from 'ember-routing/location/auto_location';
import NoneLocation from 'ember-routing/location/none_location';
import Router from 'ember-routing/system/router';
import Router, { triggerEvent } from 'ember-routing/system/router';
import { runDestroy } from 'ember-runtime/tests/utils';
import buildOwner from 'container/tests/test-helpers/build-owner';
import { setOwner } from 'container/owner';
Expand Down Expand Up @@ -192,3 +192,67 @@ QUnit.test('Router#handleURL should remove any #hashes before doing URL transiti

router.handleURL('/foo/bar?time=morphin#pink-power-ranger');
});

QUnit.test('Router#triggerEvent allows actions to bubble when returning true', function(assert) {
assert.expect(2);

let handlerInfos = [
{
name: 'application',
handler: {
actions: {
loading() {
assert.ok(false, 'loading not handled by application route');
}
}
}
},
{
name: 'about',
handler: {
actions: {
loading() {
assert.ok(true, 'loading handled by about route');
return false;
}
}
}
},
{
name: 'about.me',
handler: {
actions: {
loading() {
assert.ok(true, 'loading handled by about.me route');
return true;
}
}
}
}
];

triggerEvent(handlerInfos, false, ['loading']);
});

QUnit.test('Router#triggerEvent ignores handlers that have not loaded yet', function(assert) {
assert.expect(1);

let handlerInfos = [
{
name: 'about',
handler: {
actions: {
loading() {
assert.ok(true, 'loading handled by about route');
}
}
}
},
{
name: 'about.me',
handler: undefined
}
];

triggerEvent(handlerInfos, false, ['loading']);
});

0 comments on commit 205e5ac

Please sign in to comment.