当从ember.js1.11.3升级到1.12以删除弃用警告时,我如何将这些初始化程序转换为实例初始化程序
How do I convert these initializers to instance initializers when upgrading from ember.js 1.11.3 to 1.12 to remove the deprecation warnings?
我正在将我们的ember/ember-cli版本从1.11.3升级到1.12,为不久后达到1.13和2.0做准备。
然而,我在准确解读wrt初始化器和实例初始化器的变化时遇到了一些困难。。。我看过这些文档,读了很多帖子,但仍然不清楚这些是如何工作的。我特别困惑application.register和container.register之间的区别,以及我应该在什么时候使用application、container或instance。
从ember.js1.11.3到ember.js1.12,从ember cli 0.2.2到ember cli 0.2.7
我的初始化程序相当简单,有人能帮我转换它们吗?关于ember在初始化/实例初始化过程中的确切工作方式的简要概述或链接也会有所帮助。
以下是1.11.3中我现有的初始化程序:
initializers/auth.js
import Ember from 'ember';
import Session from 'simple-auth/session';
import CustomAuthenticator from 'soxhub-client/authenticators/soxhub';
import CustomAuthorizer from 'soxhub-client/authenticators/soxhub';
export default {
name: 'authentication',
before: 'simple-auth',
initialize: function(container, application) {
Session.reopen({
user: function() {
var userId = this.get('user_id');
if (!Ember.isEmpty(userId)) {
return container.lookup('store:application').find('user', userId);
}
}.property('accountId')
});
console.log('registering authenticator on container');
container.register('authenticator:soxhub', CustomAuthenticator);
container.register('authorizer:soxhub', CustomAuthorizer);
}
};
initializers/inject-session-into-services.js
import Ember from 'ember';
export default {
name: 'inject-session-into-service',
after: 'simple-auth',
initialize: function(container, application) {
console.log('ran initializer for sesion');
application.inject('service:pusher', 'session', 'simple-auth-session:main');
}
};
initializers/inject-store-in-to-component.js
export default {
name: "injectStoreIntoComponent",
after: "store",
initialize: function(container, application) {
console.log('injecting store onto component');
// container.typeInjection('component', 'store', 'store:main');
application.inject('component', 'store', 'store:application');
}
};
我不熟悉初始化程序,但我看到了这篇关于初始化程序的Ember NYC Meetup Talk,我认为它可能会对你有所帮助。整个演讲非常有趣,但我链接到初始化程序寻址的部分
看看你的初始化程序,我会说这个片段
Session.reopen({
user: function() {
var userId = this.get('user_id');
if (!Ember.isEmpty(userId)) {
return container.lookup('store:application').find('user', userId);
}
}.property('accountId')
});
可能被移动到应用程序路由上的beforeModel
挂钩。做这样的事?
beforeModel() {
let user = this.get('store').find('user', accountId);
this.get('session').set('user', user);
}
从那个演讲中,我认为你不应该使用"*.lookup",但你仍然可以使用inject/register。
此外,来自最新版本(2.0+)的ember指南。初始化程序不再获得container
,而是拥有注入/注册方法的应用程序。
希望对有所帮助
- datepicker引导程序再次初始化
- 如何使用onDeviceReady设置AngularJS应用程序并初始化Cordova的功能
- Rails应用程序中的每个javascript文件都需要.on('page:change',初始化)吗?
- 引导程序巡回未初始化
- $(this.el).find()在事件处理程序中工作,而不是在初始化函数(主干.js)中工作
- CoffeeScript:对象初始化程序中的Getter/Setter
- 如何初始化Twitter引导程序表单助手日期选择器
- Angular 2应用程序基础初始化
- 在 Rails 上初始化应用程序 CSS 和 JavaScript 标签时,未显示 FullCalendar 标题工具栏
- $http AngularJS 应用程序初始化之前的请求
- AngularJS在应用程序初始化后注入模块
- 通过C++应用程序初始化节点.js环境
- Cordova(PhoneGap)在jQuery Mobile应用程序的每一页上重新初始化
- 修改 .appendChild() 的目标,它会导致程序重新初始化
- 如何使用需要异步初始化的提供程序配置 angular
- 未定义的函数初始化标签输入引导程序 3.
- 重新初始化煎茶触摸应用程序,而不执行页面重新加载
- Ember-cli 创建/初始化应用程序.js两次
- 当从ember.js1.11.3升级到1.12以删除弃用警告时,我如何将这些初始化程序转换为实例初始化程序
- Emberjs中的实例初始化程序