Skip to content

Instantly share code, notes, and snippets.

@raido
Last active June 6, 2016 07:57
Show Gist options
  • Save raido/918ee5f4d473abe786f6e5a102b7b619 to your computer and use it in GitHub Desktop.
Save raido/918ee5f4d473abe786f6e5a102b7b619 to your computer and use it in GitHub Desktop.
Application.reset() issue since v1.11.0 up to latest
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
actions: {
someAction() {
this.container.lookup('application:main').reset();
}
}
});
import Ember from 'ember';
export function initialize(container, app) {
container.register('port:main', Ember.Object.extend());
container.typeInjection('controller', 'port', 'port:main');
}
export default {
name: 'setup',
initialize
}
<h1>Welcome to {{appName}}</h1>
<p>This gist shows a regression? with v1.10.0 - v1.11.0 where calling Application.reset() will fail with error "cannot re-register something, because it is already resolved", because since v1.11.0 ApplicationInstance was introduced, registry/container is not reset.</p>
<p>In v1.11.0 reset() method always built a new container - <a href="https://github.com/emberjs/ember.js/blob/v1.10.0/packages/ember-application/lib/system/application.js#L658">https://github.com/emberjs/ember.js/blob/v1.10.0/packages/ember-application/lib/system/application.js#L658</a></p>
<p>In v1.12.0 reset() method no longer builds new container/registry - <a href="https://github.com/emberjs/ember.js/blob/v1.12.0/packages/ember-application/lib/system/application.js#L658">https://github.com/emberjs/ember.js/blob/v1.12.0/packages/ember-application/lib/system/application.js#L658</a> but rather uses existing registry in buildInstance()</p>
<p>Because initializers always run then it is impossible to protect your app with "registry.has('my:module'), because one can't protect against third party initializers</p>
<p>Click reset button and error pops up in console.</p>
<br>
<button {{action 'someAction'}}>Reset</button>
{
"version": "0.8.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.5.1",
"ember-data": "2.5.2",
"ember-template-compiler": "2.5.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment