jeudi 28 mai 2015

Fixing Initializers deprecation in Ember 1.12.0

I am refering to this particular depreacation that was introduced in Ember 1.12

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

I looked at the guide, but I am unsure on how to fix this.

Here's a snippet of the code I have at the moment

initialize = (container, app) ->
  auth = container.lookup('auth-manager:main')

  local_config = ($.ajax
    type: 'GET'
    url: '/config.json'
    async:false
  ).responseJSON

  external_config = ($.ajax
    type: 'GET'
    url: local_config.crm.provisioning.url + '/v1/configurations'
    dataType: 'json'
    headers:
      'Authorization': auth.get 'token'
      'Accept': 'application/json'
      'Content-Type': 'application/json'
    async: false
    error: (e)->
      if e.status == 401
        window.location.href = window.location.origin + '/auth.html?src_url=' + window.location.href
  ).responseJSON

ConfigInitializer =
  name: 'config'
  after: 'auth-manager'
  initialize: initialize

The problem is that I require the auth-manager initializer in order to initialize my config initializer. Most of my other initializers require both the config and auth-manager initializers to get an access_token and connection endpoints.

In a ember-cli project should there be one file for the instance initializer and one for the registration of the initializer ?

The example given in the ember doc really confuses me.




Aucun commentaire:

Enregistrer un commentaire