RxJS enthusiastAngular
someStream.pipe(
/*merge || switch || concat || exhaust*/map((value) => otherStream(value))
)Perform flattening + mapping
this.actions$.pipe(
ofType<PostsActions.GetPostsById>(
PostsActions.PostsActionTypes.GetById
),
map(action => action.payload),
switchMap((id: string)=> {
return this.postsService.get(id).pipe(
map((post: Post) => new PostsApiActions.GetSuccess(post)),
catchError(err => of(new PostsApiActions.GetFailure(err)))
);
})
);fromEvent(this.button.nativeElement, 'click').pipe(
mergeMap(() => backend())
);fromEvent(this.button.nativeElement, 'click').pipe(
switchMap(() => backend())
);fromEvent(this.button.nativeElement, 'click').pipe(
concatMap(() => backend())
);fromEvent(this.button.nativeElement, 'click').pipe(
exhaustMap(() => backend())
);mergeMap - Map to observable, emit valuesswitchMap - Map to observable, complete previous inner observable, emit valuesconcatMap - Map values to inner observable, subscribe and emit in orderexhaustMap - Map to inner observable, ignore other values until that observable completes