deferReadiness for ember-cli

In a globals-based Ember application, you can usually do:

var App = Ember.Application.createWithMixins({...});
App.deferReadiness();

But now with ember-cli you can not create the application: instead you have to extend and export:

var App = Ember.Application.extend({...});

export default App;

Since the application is not created, I can not deferReadiness here. How can this pattern be implemented for ember-cli based applications?

Thanks.

DanG

My recommendation would be to use an Initializer:

/* global jQuery */
var Initializer = {

  name: 'initializeAsynchronously',

  initialize: function(container, app) {
    app.deferReadiness();
    jQuery.get('http://www.google.com/', function(data) {
      // Do stuff with data.
    }).always(function() {
      app.advanceReadiness();
    });
  }

};

export default Initializer;

Makes sense, thanks!

I can’t find the reference at the moment but someone from the core team told me you should never use deferReadiness in intializers. A better place for this sort of logic is in the model or setupController hooks in your application controller.

One problem with deferReadiness is that it prevents the router from displaying a ‘loading’ state. The router does not proceed until the app has finished initialization. Potentially long-running XHR is not a good use case for an initializer and I would agree that the Route.model() hook is a better fit for this.

@opsb Could you give an example, how to use deferReadiness in model & setupController in Ember CLI?

in your routes/application.js you could do something lik the following:

export default Em.Route.extend({
    model: function () {
        return yourPreviousDeferReadinessLogic();
    }

This will stop the setupController execution until the yourPreviousDeferReadinessLogic promise resolves. If you previously had any other code inside the model hook you could do something like return yourPreviousDeferReadinessLogic().then(...)

But In ember engine initializer, it throws err like deferReadiness and advanceReadiness is not a function why? @lfridael

@Viki this thread is very old so the code posted above is probably going to need some updating before it works. Are you using an “instance initializer”?

@dknutsen Hi, I’m using initializer in my engine. Not using instance initializer

Ah it looks like engines may not support it yet. Unfortunately that issue is pretty old and there doesn’t seem to be any traction on it :frowning_face:

Of course in this issue it sounds like that may have been an intentional decision…

ok thank you mate :slightly_smiling_face: