vendredi 6 février 2015

Don't notify changes from the route to the template in Ember

I'm trying to find a way to do not notify the template that a change has been made.


In my case, I have a model that allows me to populate a form. If the user didn't save the modification and transition to another route, I need to rollback the model to its default state:



export default Ember.Route.extend({
actions: {
willTransition: function (transition) {
this.get('controller.model').rollback();
}
}
}


By doing that, because the transition didn't happen yet, I can see the form content disappearing in the template, then it will transition to my new route. In some cases, it's not nice for the user experience to see all information going back to its previous state before the transition did happen and I would like to rollback only when the view has been removed.


Or maybe it is possible to don't notify the template that the route did change something?


I was thinking about using a promise on the transition, but it doesn't rollback my model:



willTransition: function (transition) {
var self = this;
transition.then(function () {
self.get('controller.model').rollback();
}
}


What can be the best solution to do so?


Thanks.





1 commentaire:

  1. willTransition() {
    // rollbackAttributes() removes the record from the store
    // if the model 'isNew'
    this.controller.get('model').rollbackAttributes();
    }

    RépondreSupprimer