vendredi 23 juin 2017

In Ember, AJAX callback should it be wrapped in Ember run loop?

The below statement is from ember guides,

The most common case for using the run loop is integrating with a non-Ember API that includes some sort of asynchronous callback. For example:

DOM update and event callbacks
setTimeout and setInterval callbacks
postMessage and messageChannel event handlers
AJAX callbacks
Websocket callbacks

I usually will do for AJAX request,

Ember.$.ajax(
{
 type: "POST",
 url:"someurl",
 contentType: "application/json",
 success: function(data) {
 //Should I wrap this success callback code in Run loop. or is it safe to leave
 //Here I will set properties to display, I might call sendAction/send to communicate with parent.
 }
})

I haven't faced any problem with that but sometime rendering is taking too much time after I change data in callback ?. does any one face that issue ?

Should I use ember-ajax addon to wrap success callback in Ember run loop?.

PS: Below is from ember guides, you should wrap any non-Ember async callbacks in Ember.run. If you don't, Ember will try to approximate a beginning and end for you. Relying on autoruns is not a rigorous or efficient way to use the run loop.




Aucun commentaire:

Enregistrer un commentaire