How could I do something like this:
I have an observable that emits some result I load from an API. This is mapped into an ResultObject
that holds a state (loading, success, error) and the object or an error (I don't want to emit an error because this observable will update again).
For now, I merge two observables, one just emitting an ResultObject
with state loading
and the observable that really loads the data and then emits an ResultObject
with state success
.
Usually, if in a fast network, that loading part is quite fast, so the UI reacts to the loading
state, shows that for a few hundred millisecounds and then shows the data. Does not look that nice.
Now I want to show that loading indicator just, if the data loading takes longer than a second.
Before I fix that on UI side, I thought to ask this here:
Is there a possibility, to have an observable, have an operator that does something like this:
myObservable
.emitAfterTimeout(1000, new ResultObject(LOADING)
The normal timeout
operator does not help, because I need to keep the observable active, I want to have the result anyway.
Thanks for your help
debounce
on theObservable
. - flakes