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] Clear cached instances when factories are unregistered. #12680

Merged
merged 1 commit into from
Dec 3, 2015
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
15 changes: 15 additions & 0 deletions packages/ember-application/lib/system/application-instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,21 @@ let ApplicationInstance = EmberObject.extend(RegistryProxy, ContainerProxy, {
willDestroy() {
this._super(...arguments);
run(this.__container__, 'destroy');
},

/**
Unregister a factory.

Overrides `RegistryProxy#unregister` in order to clear any cached instances
of the unregistered factory.

@public
@method unregister
@param {String} fullName
*/
unregister(fullName) {
this.__container__.reset(fullName);
this._super(...arguments);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Application from 'ember-application/system/application';
import ApplicationInstance from 'ember-application/system/application-instance';
import run from 'ember-metal/run_loop';
import jQuery from 'ember-views/system/jquery';
import factory from 'container/tests/test-helpers/factory';

let app, appInstance;

Expand Down Expand Up @@ -124,3 +125,26 @@ QUnit.test('customEvents added to the application instance before setupEventDisp

appInstance.setupEventDispatcher();
});

QUnit.test('unregistering a factory clears all cached instances of that factory', function(assert) {
assert.expect(3);

run(function() {
appInstance = ApplicationInstance.create({ application: app });
});

let PostController = factory();

appInstance.register('controller:post', PostController);

let postController1 = appInstance.lookup('controller:post');
assert.ok(postController1, 'lookup creates instance');

appInstance.unregister('controller:post');
appInstance.register('controller:post', PostController);

let postController2 = appInstance.lookup('controller:post');
assert.ok(postController2, 'lookup creates instance');

assert.notStrictEqual(postController1, postController2, 'lookup creates a brand new instance, because previous one was reset');
});