我试图弄清楚如何将现有的初始化程序转换为Ember 1.11+中的较新的instanceInitializer / initializer格式(http://emberjs.com/deprecations/v1.x/#toc_deprecate-access-to-instances-in-initializers)
这是我现有的初始化程序:
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
对此应如何工作的任何帮助表示赞赏!
由于