Run Ember Loading State Later


#1

Hi, I use the ember loading states and it works great so far. But there is one thing I really would like to add.

Is there a possibility to set a small timeout before starting the intermediate transition? Means, I would like to show the loading template only if the transition takes more than half a second, for example.

I can imagine ways without using the ember states but I really would like to walk the ember way :wink:


#2

I’ve managed to do this in the past, but unfortunately no longer have access to the codebase :expressionless:

If no one responds, I can attempt to recreate it.


#3

Yes, you’re mucking with a private method but this is the only way I’ve been able to achieve this.

App.Router.reopen({
  loaderDelay: 500, // delays transitions by 0.5s
  init: function() {
    this._super.apply(this, arguments);

    var originalScheduler = this._scheduleLoadingEvent;
    this._scheduleLoadingEvent = function() {
      var eventArgs = Array.prototype.slice.call(arguments);
      Ember.run.later(this, function() {
        originalScheduler.apply(this, eventArgs);
      }, this.loaderDelay);
    }
  }
});

Demo: http://jsbin.com/lobejojuge/1/edit?html,js,output

Paging Mr. Router @machty


#4

Thanks a lot. This is great and works perfectly.