My code does a check of word.statusId to see if it's dirty. If it is then it does an update of word and then if that works it updates wordForms. If it's clean then it just updates wordForms. Can someone advise me if this is the correct way to handle running one promise after another?
update = (): ng.IPromise<any> => {
var self = this;
if (self.word.statusId != 3) {
return self.wordEditSubmit()
.then(() => {
return self.wordFormCheckAndUpdate();
})
} else {
return self.wordFormCheckAndUpdate();
}
}
What you have described as the desired behaviour is indeed the actual behaviour.
As you are using arrow functions you do not need to store the value of this:
update = (): ng.IPromise<any> => {
if (this.word.statusId != 3) {
return this.wordEditSubmit()
.then(() => this.wordFormCheckAndUpdate())
} else {
return this.wordFormCheckAndUpdate();
}
}
Simplified again using a ternary condition:
update = (): ng.IPromise<any> => {
return this.word.statusId != 3
? this.wordEditSubmit().then(() => this.wordFormCheckAndUpdate())
: this.wordFormCheckAndUpdate();
}
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