Run Ember Loading State Later

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:

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.

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: JS Bin - Collaborative JavaScript Debugging

Paging Mr. Router @machty

1 Like

Thanks a lot. This is great and works perfectly.