Skip to content

Commit

Permalink
Ensure Engine Routes are deactivated before destruction
Browse files Browse the repository at this point in the history
  • Loading branch information
Trent Willis authored and trentmwillis committed Sep 10, 2016
1 parent 07a2395 commit dd95e05
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,27 @@ moduleFor('Application test: engine rendering', class extends ApplicationTest {
], 'the expected hooks were fired');
});
}

['@test deactivate should be called on Engine Routes before destruction'](assert) {
assert.expect(3);

this.setupAppAndRoutableEngine();

this.registerEngine('blog', Engine.extend({
init() {
this._super(...arguments);
this.register('template:application', compile('Engine{{outlet}}'));
this.register('route:application', Route.extend({
deactivate() {
assert.notOk(this.isDestroyed, 'Route is not destroyed');
assert.notOk(this.isDestroying, 'Route is not being destroyed');
}
}));
}
}));

return this.visit('/blog').then(() => {
this.assertText('ApplicationEngine');
});
}
});
15 changes: 8 additions & 7 deletions packages/ember-routing/lib/system/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,20 +452,21 @@ const EmberRouter = EmberObject.extend(Evented, {
},

willDestroy() {
let instances = this._engineInstances;
for (let name in instances) {
for (let id in instances[name]) {
run(instances[name][id], 'destroy');
}
}

if (this._toplevelView) {
this._toplevelView.destroy();
this._toplevelView = null;
}

this._super(...arguments);

this.reset();

let instances = this._engineInstances;
for (let name in instances) {
for (let id in instances[name]) {
run(instances[name][id], 'destroy');
}
}
},

/*
Expand Down

0 comments on commit dd95e05

Please sign in to comment.