'return empty ajaxAsObservable
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
Solution 1:[1]
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()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
