2015-10-26 20 views
0

我正在將我們的ember/ember-cli版本從1.11.3升級到1.12,準備在不久之後升級到1.13和2.0。從ember.js 1.11.3升級到1.12以刪除棄用警告時,如何將這些初始值設定項轉換爲實例初始值設定項?

但是,我在解釋確切地說是什麼改變了初始化程序和實例初始化程序......查看了文檔並閱讀了很多帖子,但仍不清楚它們是如何工作的。我對application.register和container.register之間的區別以及何時應該使用應用程序,容器或實例感到特別困惑。

從ember.js 1.11.3去ember.js 1.12,燼-CLI 0.2.2至燼-CLI 0.2.7

我的初始化是相當簡單的,有人可以幫助我將它們轉換?在初始化/實例初始化過程中,如何精確定義燼的簡要概述或鏈接也是有幫助的。

這裏是我從1.11.3現有的初始化:

初始化/ 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); 
    } 
}; 

初始化/注入會話 - 到 - service.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'); 
     } 
    }; 

初始化/ injection-store-into-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'); 
    } 
}; 

回答

0

我對初始化程序並不熟悉,但是我看到了這個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」,但你仍然可以使用注入/註冊。

此外,從最新版本(2.0+)的餘燼指南。初始化程序不再獲得container,但是您具有注入/註冊方法的應用程序。

希望可以幫到

相關問題