I am monitoring the status of a variable called radioStatus
within a Vue
instance:
watch: {
radioStatus: function(val) {
if (!this.discovery) {
$.ajax({ url: '/switch/api/radio/' + (val ? 'on' : 'off') })
}
}
This variable may be updated during an AJAX call triggered upon page refresh:
$.ajax({
url: "/api",
cache: false
})
.done(function(response) {
vm.discovery = true;
vm.radioStatus = response.radio.ison; // <-- the change I mention below is here
vm.discovery = false;
});
Is it safe to assume that all functions triggered by a change in radioStatus
will complete before moving on to the next line (vm.discovery = false
)?
My concern lies in the fact that vm.discovery
serves as a flag for multiple watched variables (similarly to radioStatus
), and it may switch states before the functions related to the watched variables are fully executed.