jeudi 26 février 2015

Odd behavior when using Ember Data under a high-latency network

Saving my Ember Data model causes the data store to update the record from the response from the server.


For most cases, this functionality is expected and works perfectly fine. However, I ran into a case where if the server response is slow, then any fields that were modified post-save are now reset.


We had a requirement where we needed to "save on input blur", so I reopened some of the built-in view helpers to send a 'save' event to the current controller. For example:



Ember.Select.reopen(Ember.TargetActionSupport, {
_sendSave: function() {
this.triggerAction({
action: 'save',
target: this.get('controller')
});
}.on('change')
});


As for my current solution, I am simply throttling the save action:



save: function() {
Ember.run.throttle(this, this._save, 5000); // saves the model if `isDirty`
}


I was wondering if anyone has any ideas on the best way to handle this? One solution that was mentioned from my team was to not sync the data from the incoming response. I do not think that this is a good idea, and I would prefer that the current record merges itself into the response's record. Please let me know if further elaboration is needed.





Aucun commentaire:

Enregistrer un commentaire