Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Instance Initializers with Ember 1.12.0 and the Ember CLI

After updating my app to Ember 1.12.0, I notice lots of warnings like this:

lookup was called on a Registry. The initializer API no longer receives a container, and you should use an instanceInitializer to look up objects from the container. See http://emberjs.com/guides/deprecations#toc_deprecate-access-to-instances-in-initializers for more details.

This seems to be caused by using container.lookup from an initializer, which was fine in older versions of Ember.

From the blog post about Ember 1.12.0, it seems like in a Global-based Ember application, the difference between making an Initializer and an Instance Initializer is using

App.initializer({
    ...
});

vs

App.instanceInitializer({
    ...
});

However, it doesn't seem to describe how to use instance initializers with the Ember CLI. Does anyone know how to use them?

EDIT: Turns out a browser plugin of all things was blocking the information I needed on the original blog post. I'll leave this here in case it's useful to anyone, but in the CLI regular initializers go inside

app/initializers/__my__initializer.js

while Instance Initializers are defined like

app/instance-initializers/__my__initializer.js

EDIT 2: If anyone is coming here because they're experiencing the same problem, this issue on the Ember.js repo references this problem and includes a link to a jsfiddle demonstrating the problem.

like image 773
Alex LaFroscia Avatar asked May 14 '15 15:05

Alex LaFroscia


1 Answers

Turns out a browser plugin of all things was blocking the information I needed on the original blog post. I'll leave this here in case it's useful to anyone, but in the CLI regular initializers go inside

app/initializers/__my__initializer.js

while Instance Initializers are defined like

app/instance-initializers/__my__initializer.js
like image 195
Alex LaFroscia Avatar answered Oct 04 '22 11:10

Alex LaFroscia