Injection controllers in controllers no longer work during initialization (canary)

I just upgraded to the latest Canadian version of ember and noticed that my initializer, which introduced the currentUser controller in all controllers, no longer works.

Here is the code.

Ember.Application.initializer({
  name: "fetchUsers",
  after: "store",

  initialize: function(container, application) {

    var store, controller;

    application.deferReadiness();

    store      = container.lookup('store:main');
    controller = container.lookup('controller:currentUser');

    return store.find('user').then( function(users) {
      var currentUser;

      currentUser = users.findBy('isCurrent', true);

      controller.set('content', currentUser);

      application.inject('controller', 'currentUser', 'controller:currentUser');

      application.advanceReadiness();
   });
  }
});

This works great in release and beta branches, but for canary I get the following error.

Error: Cannot inject a `controller:current-user` on other controller(s). Register the `controller:current-user` as a different type and perform the typeInjection.

How can I fix this? I would like currentUser to be an ObjectController, is this possible?

+4
source share
1 answer

Ok, this is my current initializer. I just changed currentUser ObjectController to ObjectProxy. My only hang now is where to store the CurrentUserObjectProxy file. I tend to models.

Ember.Application.initializer({
  name: "fetchUsers",
  after: "store",

  initialize: function(container, application) {

    var store, user, proxy;

    application.deferReadiness();

    store = container.lookup('store:main');

    proxy = App.CurrentUserObjectProxy.extend();

    container.register('user:current', proxy, {singleton: true});

    proxy = container.lookup('user:current');

    store.find('user').then( function(users) {

      user = users.findBy('isCurrent', true);

      proxy.set('content', user);

      application.inject('controller', 'currentUser', 'user:current');

      application.advanceReadiness();
    });
  }
});

Hope this helps someone.

+6

Source: https://habr.com/ru/post/1533978/


All Articles