In my current setup, when a user navigates in a view, an API call is made to fetch the data for that specific view. This data is then used later on to decide whether a dialog should pop up when a user performs an action.
While the solution is functional at the moment, I foresee a potential issue if a user with high latency triggers the above action before the API request completes. I don't want to display a loading indicator every time a user navigates as it can be quite annoying to deal with. Instead, I prefer to have the user wait until they actually intend to perform the action.
Furthermore, I have an observable indicating whether the API request is currently loading or not, which I plan to utilize somehow.
actionPerformed$ = createEffect(() =>
this.actions$.pipe(
ofType(performAction),
withLatestFrom(entities$),
mergeMap(data => {
let payload = data[0];
let dataFromApi = data[1];
...
...
})
One idea that came to mind, although it may not be efficient, was to have an operator that checks the condition and throws an error if it's still loading, then retrying after a short delay.
Do you have any better suggestions? I've explored using `delayWhen`, but it seems inefficient to introduce a delay like that. I'd prefer something more like a "gate" that only opens the stream when `loading$` is set to false and emits the value immediately once that condition is met.
Thank you in advance!