Using Instance Initializers with Ember 1.12.0 and the Ember CLI

最后都变了- 提交于 2019-12-01 13:52:48

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/30241691/using-instance-initializers-with-ember-1-12-0-and-the-ember-cli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!