@ngrx/effects#concatLatestFrom TypeScript Examples

The following examples show how to use @ngrx/effects#concatLatestFrom. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: members.effects.ts    From dating-client with MIT License 6 votes vote down vote up
LoadMoreMembers$ = createEffect(() => {
    const currentParams$ = combineLatest([
      this.store.select(fromMembers.selectMembersPagination),
      this.store.select(fromMembers.selectMembersFilters)
    ]).pipe(
      map(([pagination, filters]) => ({
        currentFilters: filters,
        currentPagination: pagination
      }))
    );

    return this.actions$.pipe(
      ofType(MembersPageActions.loadMoreMembers),
      concatLatestFrom(() => currentParams$),
      switchMap(([action, { currentFilters, currentPagination }]) => {
        const newPaginationParams = new QueryParams(
          (currentPagination.currentPage + 1).toString(),
          currentPagination.itemsPerPage.toString()
        );
        const params = { ...newPaginationParams, ...currentFilters };

        return this.memberService.getMembers(params).pipe(
          map(({ result, pagination }) =>
            MembersApiActions.loadMoreMembersSuccess({ members: result, pagination })
          ),
          catchError(error => of(MembersApiActions.loadMoreMembersFailure({ error }))),
        );
      })
    );
  });
Example #2
Source File: photos.effects.ts    From dating-client with MIT License 6 votes vote down vote up
loadUserPhoto$ = createEffect(() => this.actions$.pipe(
    ofType(loadUserProfilePhotos),
    concatLatestFrom(() => this.store.select(selectAuthUserId)),
    switchMap(([action, id]) => {
      return this.photoService.getUserPhotos(id).pipe(
        map(photos => loadUserProfilePhotosSuccess({ photos })),
        catchError(error => of(loadUserProfilePhotosFailure({ error }))),
      );
    })
  ));
Example #3
Source File: photos.effects.ts    From dating-client with MIT License 6 votes vote down vote up
uploadPhoto$ = createEffect(() => this.actions$.pipe(
    ofType(uploadPhoto),
    concatLatestFrom(() => this.store.select(selectAuthUserId)),
    switchMap(([{ payload }, userId]) => {
      return this.photoService.uploadPhoto(payload, userId).pipe(
        map(photo => uploadPhotoSuccess({ photo })),
        catchError(error => of(uploadPhotoFailure({ error }))),
      );
    })
  ));
Example #4
Source File: photos.effects.ts    From dating-client with MIT License 6 votes vote down vote up
setMainPhoto$ = createEffect(() => this.actions$.pipe(
    ofType(setMainPhoto),
    concatLatestFrom(() => this.store.select(selectAuthUserId)),
    switchMap(([{ photoId }, userId]) => {
      return this.photoService.setMainPhoto(userId, photoId).pipe(
        map(() => {
          return setMainPhotoSuccess({ photoId });
        }),
        catchError(error => {
          this.toast.warning(error);
          return of(setMainPhotoFailure({ error }));
        })
      );
    })
  ));
Example #5
Source File: photos.effects.ts    From dating-client with MIT License 6 votes vote down vote up
deletePhoto$ = createEffect(() => this.actions$.pipe(
    ofType(deletePhoto),
    concatLatestFrom(() => this.store.select(selectAuthUserId)),
    switchMap(([{ photoId }, userId]) => {
      return this.photoService.deletePhoto(userId, photoId).pipe(
        map(() => deletePhotoSuccess({ photoId })),
        catchError(error => {
          this.toast.warning(error);
          return of(deletePhotoFailure({ error }));
        })
      );
    })
  ));
Example #6
Source File: settings.effects.ts    From dating-client with MIT License 6 votes vote down vote up
EditUserProfile$ = createEffect(() => this.actions$.pipe(
    ofType(SettingsActions.editUserSettings),
    concatLatestFrom(() => this.store.select(selectUserProfileSettings)),
    exhaustMap(([{ userData }, userProfile]) => {
      const payload: User = { ...userProfile, ...userData };
      return this.memberService.editMember(payload).pipe(
        map(user => {
          this.toast.success('Profile was successfully updated!');
          return SettingsActions.editUserSettingsSuccess({ user });
        }),
        catchError(error => {
          this.toast.error(error);
          return of(SettingsActions.editUserSettingsFailure({ error }));
        }),
      );
    })
  ));
Example #7
Source File: photos.effects.ts    From dating-client with MIT License 5 votes vote down vote up
changeUserImageLocally$ = createEffect(() => this.actions$.pipe(
    ofType(setMainPhotoSuccess),
    concatLatestFrom(() => this.store.select(selectUserPhotosState)),
    switchMap(([action, photosState]) => {
      const photoUrl = photosState.photos.find(p => p.isMain)?.url ?? '';
      return of(changeUserImageLocally({ photoUrl }));
    })
  ));