Skip to content

Commit

Permalink
Merge pull request #14237 from trentmwillis/engine-deactivate
Browse files Browse the repository at this point in the history
[BUGFIX release] Ensure Engine Routes are deactivated before destruction
  • Loading branch information
rwjblue authored Sep 10, 2016
2 parents 4598864 + 1c48f67 commit c45d219
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 c45d219

Please sign in to comment.