使用Ember 1.12.0的实例初始化程序和Ember CLI [英] Using Instance Initializers with Ember 1.12.0 and the Ember CLI

查看:101
本文介绍了使用Ember 1.12.0的实例初始化程序和Ember CLI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将我的应用程序更新为Ember 1.12.0后,我注意到很多警告,如下所示:


查找在注册表中被调用。 initializer API不再收到容器,您应该使用 instanceInitializer 从容器中查找对象。请参阅 http://emberjs.com/guides/deprecations#toc_deprecate-


这似乎是由于使用 container.lookup 从一个初始化器,这是较好的旧版本的Ember。



从关于Ember 1.12.0的博文,似乎在基于全局的Ember应用程序中,使初始化程序和实例初始化程序之间的区别在于使用

  App.initializer({
...
});

vs

  App.instanceInitializer({
...
});

但是,似乎没有描述如何使用Ember CLI实例初始化程序。有没有人知道如何使用它们?



编辑:结束所有事情的浏览器插件阻止了我在原始博客上所需的信息帖子。我会离开这里,以防万一它对任何人都有用,但在CLI常规初始化程序进入

  app / initializers / __ my__initializer而实例初始化程序被定义为



pre> app / instance-initializers / __ my__initializer.js

EDIT 2:如果有任何人来到这里,因为他们遇到同样的问题,这个问题在Ember.js repo 上引用了这个问题,并提供了一个jsfiddle的链接,证明了这个问题。

解决方案

所有事情的浏览器插件都会阻止原始博文上需要的信息。我会离开这里,以防万一它对任何人都有用,但在CLI常规初始化程序进入

  app / initializers / __ my__initializer而实例初始化程序被定义为



pre> app / instance-initializers / __ my__initializer.js


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.

解决方案

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

这篇关于使用Ember 1.12.0的实例初始化程序和Ember CLI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆