I have this code
allEditChanges
.debounce(250)
.distinctUntilChanged()
.flatMapLatest(function (text) {return $.ajaxAsObservable({url:..., data:....} }).subscribe()
I need to make this conditionall so sometimes just omit the request. I tried this way
allEditChanges
.debounce(250)
.distinctUntilChanged(
.flatMapLatest(function (text) {if(myFlag){
return $.ajaxAsObservable({url:..., data:....}))
}else{
return $.ajaxAsObservable({}); } }).subscribe()
but when myFlag is true , calls request to the current page.
Question how to omit the request ? How to not call any request on some condition
You can use filter
allEditChanges
.debounce(250)
.distinctUntilChanged()
.filter(() => !myFlag)
.flatMapLatest(function (text) {return $.ajaxAsObservable({url:..., data:....} })
.subscribe()
Or return Rx.Observable.empty()
allEditChanges
.debounce(250)
.distinctUntilChanged()
.filter(() => !myFlag)
.flatMapLatest(function (text) {
if(myFlag){
return Rx.Observable.empty();
}
return $.ajaxAsObservable({url:..., data:....} })
.subscribe()