jeudi 21 mai 2015

code in willTransition callback executed after model callback after a window.alert

I've recently encountered a bug with Ember.js. Basically when I click the browser back button in Firefox, Ember.js executes the code in wrong order. The code in willTransition callback right after the line alert("..."); is executed after model callback, which should normally be executed right after alert("..."); is returned.

The code:

App = Ember.Application.create();
App.Router.reopen({
  location: 'history'
});
App.Router.map(function() {
  this.route('foo');
});
App.IndexRoute = Ember.Route.extend({
  actions:{
    willTransition: function(transition){
      console.log('start IndexRoute#willTransition');
      alert('See console logs. "start FooRoute#model" will be printed before "end IndexRoute#willTransition" is printed, if you go to Foo by clicking the browser back button.');
      console.log('end IndexRoute#willTransition');
    }
  }
});
App.FooRoute = Ember.Route.extend({
  model: function() {
    console.log('start FooRoute#model');
    return [];
  }
});

Since this bug involves browser back button which can't be reproduced with JSFiddle or JSBin, have to be reproduced locally. I've created a Github repo to store the code to reproduce the bug, it's here http://ift.tt/1HjqaAo.




Aucun commentaire:

Enregistrer un commentaire