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.
This worked for me. Basically, you just need to wrap the actions/callbacks in run.bind loop. https://github.com/ember-cli/eslint-plugin-ember/blob/master/docs/rules/jquery-ember-run.md
import $ from 'jquery';
import { bind } from '@ember/runloop';
$.ajax({
type: "POST",
url:"someurl",
contentType: "application/json",
}).then(bind(this, (data) => {
// Handle success here
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With