RxJs stops listening to click events when an inner observable errors (Ajax request). I'm trying to figure out how to keep the event listener hooked to the button click event and gracefully handle the inner ajax error.
Here is my example code and a link to plunkr
var input = $("#testBtn");
var test = Rx.Observable.fromEvent(input,'click');
var testAjax = function() {
return Rx.Observable.range(0,3).then(function(x){
if(x==2)throw "RAWR"; //Simulating a promise error.
return x;
});
}
test.map(function(){
return Rx.Observable.when(testAjax());
})
.switchLatest()
.subscribe(
function (x) {
console.log('Next: ', x);
},
function (err) {
console.log('Error: ' + err);
},
function () {
console.log('Completed');
});
http://plnkr.co/edit/NGMB7RkBbpN1ji4mfzih
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…