Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX release] Use resetCache on container destroy #16605

Merged
merged 1 commit into from
May 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/container/lib/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export default class Container {
@return {any}
*/
lookup(fullName, options) {
assert('expected container not to be destroyed', !this.isDestroyed);
assert('fullName must be a proper full name', this.registry.isValidFullName(fullName));
return lookup(this, this.registry.normalize(fullName), options);
}
Expand All @@ -95,7 +96,7 @@ export default class Container {
@method destroy
*/
destroy() {
destroyDestroyables(this);
resetCache(this);
this.isDestroyed = true;
}

Expand All @@ -107,6 +108,7 @@ export default class Container {
@param {String} fullName optional key to reset; if missing, resets everything
*/
reset(fullName) {
if (this.isDestroyed) return;
if (fullName === undefined) {
resetCache(this);
} else {
Expand Down Expand Up @@ -138,6 +140,7 @@ export default class Container {
@return {any}
*/
factoryFor(fullName, options = {}) {
assert('expected container not to be destroyed', !this.isDestroyed);
let normalizedName = this.registry.normalize(fullName);

assert('fullName must be a proper full name', this.registry.isValidFullName(normalizedName));
Expand All @@ -156,6 +159,7 @@ export default class Container {
return factoryFor(this, normalizedName, fullName);
}
}

/*
* Wrap a factory manager in a proxy which will not permit properties to be
* set on the manager.
Expand Down
34 changes: 34 additions & 0 deletions packages/container/tests/container_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,40 @@ moduleFor(
assert.deepEqual(Object.keys(instance), []);
}

[`@test assert when calling lookup after destroy on a container`](assert) {
let registry = new Registry();
let container = registry.container();
let Component = factory();
registry.register('component:foo-bar', Component);
let instance = container.lookup('component:foo-bar');
assert.ok(instance, 'precond lookup successful');

this.runTask(() => {
container.destroy();
});

expectAssertion(() => {
container.lookup('component:foo-bar');
});
}

[`@test assert when calling factoryFor after destroy on a container`](assert) {
let registry = new Registry();
let container = registry.container();
let Component = factory();
registry.register('component:foo-bar', Component);
let instance = container.factoryFor('component:foo-bar');
assert.ok(instance, 'precond lookup successful');

this.runTask(() => {
container.destroy();
});

expectAssertion(() => {
container.factoryFor('component:foo-bar');
});
}

// this is skipped until templates and the glimmer environment do not require `OWNER` to be
// passed in as constructor args
['@skip #factoryFor does not add properties to the object being instantiated'](assert) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class LifeCycleHooksTest extends RenderingTest {
this.components = {};
this.componentRegistry = [];
this.teardownAssertions = [];
this.viewRegistry = this.owner.lookup('-view-registry:main');
}

afterEach() {
Expand Down Expand Up @@ -59,7 +60,7 @@ class LifeCycleHooksTest extends RenderingTest {
}

assertRegisteredViews(label) {
let viewRegistry = this.owner.lookup('-view-registry:main');
let viewRegistry = this.viewRegistry;
let topLevelId = getViewId(this.component);
let actual = Object.keys(viewRegistry)
.sort()
Expand Down