如何将现有的Ember初始值设定项转换为使用较新的instanceInitializer格式?

时间:2015-07-03 06:52:10

标签: ember.js coffeescript ember-cli

我试图弄清楚如何将现有的初始化程序转换为Ember 1.11+中的较新的instanceInitializer / initializer格式(http://emberjs.com/deprecations/v1.x/#toc_deprecate-access-to-instances-in-initializers

这是我现有的初始化程序:

app / initializers / session.coffee(ps这是使用ember-simple-auth将登录用户粘贴到客户端会话上)

import Ember from 'ember'
import Session from 'simple-auth/session'


UserSession = Session.extend
  # Here we set the 'session.context' property which is used for 
  # filtering the User contexts throughout the site.
  context: (->
    user = @get 'user'

    # Check for a defaultContext and use that otherwise use empty.
    if user and user.defaultContext
      @container.lookup('store:main')
                .find('context', user.defaultContext)
                .then (context)=>
        @set 'context', context
    else
      @container.lookup('store:main').createRecord 'context'
  ).property 'user'

# Takes two parameters: container and app
initialize = (container, app) ->
  container.register 'session:usersession', UserSession

UserSessionInitializer =
  name: 'session'
  before: 'simple-auth'
  initialize: initialize

export default UserSessionInitializer

所以我尝试将包含@ container.lookup的UserSession内容拆分到app / instance-initializers / session.coffee中,但后来我需要在初始化程序/ session.coffee中导入它,因为容器.register使用UserSession

对此应如何工作的任何帮助表示赞赏!

由于

0 个答案:

没有答案