jeudi 2 juillet 2015

ember.js initializer called twice, on second time with event as container object

I have the following custom initializer:

// django-rest.js
import Ember from 'ember';
import Authenticator from './../authenticators/django-rest';
import Authorizer    from './../authorizers/django-rest';

export function initialize(container, application ) {

console.debug("INITIALIZER CALLED");
console.debug(container);
console.debug(application);
container.register('authorizer:django-rest', Authorizer);
container.register('simple-auth-authenticator:django-rest', Authenticator);
}

export default Ember.Application.instanceInitializer({
  name:       'django-rest-auth',
  before:      'simple-auth',
  initialize: initialize,

});

and for some reason its called twice - one time when app is loaded, and second time after transition to page, eg right after I see in ember log:

"Preparing to transition from '' to 'index'"

Now why does it bother me you ask? well on the first time it init everything works great, but on the second time I'm getting exception because container.register is undefined. so I tried to log out container and app.

On first run I get a Registry instance and what appears to by my ENV:

Registry {fallback: null, registrations: Object, _typeInjections: Object, _injections: Object, _factoryTypeInjections: Object…}
Class {API_HOST: "http://localhost:8000", API_NAMESPACE: "rest/api", LOG_TRANSITIONS: true, LOG_TRANSITIONS_INTERNAL: true, name: "agent"…}

and on second time initializer is called I'm getting an event (??) and undefined:

Class {customEvents: null, rootElement: "body", applicationRegistry: Registry, registry: Registry, container: Container…}
undefined

What is going on here? why is this initializer called twice? why are params wrong?

I'm new to ember and very confused about this. Any idea or lead will be appreciated.

Thanks!




Aucun commentaire:

Enregistrer un commentaire