I have this ngrx effect that is calling in this example to movies service, but is depending of a value selector, if this values is as expected in validation, the effect sould send a new action, this way I avoid to call the service because the condition. Right now I cannot use another action (this would be more descriptive) in the if block because of this error:
Type 'Observable' is not assignable to type 'Observable | ((...args: any[]) => Observable)'.
Type 'Observable' is not assignable to type 'Observable'.ts(2322).
What is the better way to handle this scenario?
loadMovies$ = createEffect(() => this.actions$.pipe(
ofType('[Movies Page] Load Movies'),
concatMap(action => of(action).pipe(withLatestFrom(this.store.select(getBlockBuster)))),
mergeMap(([{payload}, foundBlockBuster]) => {
if (!foundBlockBuster) {
// in order to avoid errors we need to use this({ type: '[Movies API] Movies Loaded Success', payload: movies }))
return of({ type: '[Movies] The block busters are rent' })
}
return this.moviesService.getAll()
.pipe(
map(movies => ({ type: '[Movies API] Movies Loaded Success', payload: movies })),
catchError(() => of({ type: '[Movies API] Movies Loaded Error' }))
)
})
)
);