I have a block of code that contains nested subscribe
calls:
this.http.post('/update1', newData).subscribe(
(response) => {
const r = response.json;
const id = r['id'];
this.http.post('/update2?id=' + id, newData).subscribe(
() => {
this.http.post('/update3?id=' + id, newData).subscribe(
() => {
console.log('success');
},
() => {
// revert changes made to update2
this.http.post('/update2', previousValues).subscribe();
// revert changes made to update1
this.http.post('/update1', previousValues).subscribe();
});
},
() => {
// revert changes made to update1
this.http.post('/update1', previousValues).subscribe();
}
);
},
(error) => {
console.log(error);
}
);
Looking for guidance on optimizing this code using RxJS 5?