@ngrx/effects#Effect TypeScript Examples

The following examples show how to use @ngrx/effects#Effect. 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: service.effects.ts    From digital-bank-ui with Mozilla Public License 2.0 6 votes vote down vote up
@Effect()
  createTeller$: Observable<Action> = this.actions$.pipe(
    ofType(tellerActions.CREATE_TELLER),
    map((action: tellerActions.CreateTellerAction) => action.payload),
    mergeMap(payload =>
      this.tellerService.create(payload.officeId, payload.teller).pipe(
        map(
          () =>
            new tellerActions.CreateTellerSuccessAction({
              activatedRoute: payload.activatedRoute,
              resource: payload.teller,
            }),
        ),
        catchError(error => of(new tellerActions.CreateTellerFailAction(error))),
      ),
    ),
  );
Example #2
Source File: page.effects.ts    From spurtcommerce with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
// Pages Bulk Delete
  @Effect()
  doPagesBulkDelete$: Observable<Action> = this.action$.pipe(
    ofType(actions.ActionTypes.DO_PAGES_BULK_DELETE),
    map((action: actions.DoPagesBulkDelete) => action.payload),
    switchMap(state => {
      return this.apiCli.pagesBulkDelete(state).pipe(
        tap(response => {
          this.appState.dispatch(
            new actions.GetActiveCount({ count: 1, status: 1 })
          );
          this.appState.dispatch(
            new actions.GetInactiveCount({ count: 1, status: 0 })
          );
        }),
        switchMap(user => [new actions.DoPagesBulkDeleteSuccess(user)]),
        catchError(error => of(new actions.DoPagesBulkDeleteFail(error)))
      );
    })
  );
Example #3
Source File: service.effects.ts    From digital-bank-ui with Mozilla Public License 2.0 6 votes vote down vote up
@Effect()
  search$: Observable<Action> = this.actions$.pipe(
    ofType(userActions.SEARCH),
    debounceTime(300),
    switchMap(() => {
      const nextSearch$ = this.actions$.pipe(ofType(userActions.SEARCH), skip(1));

      return this.identityService.listUsers().pipe(
        takeUntil(nextSearch$),
        map(this.excludeSystemUsers),
        map(
          users =>
            new userActions.SearchCompleteAction({
              elements: users,
              totalPages: 1,
              totalElements: users.length,
            }),
        ),
        catchError(() => of(new userActions.SearchCompleteAction(emptySearchResult()))),
      );
    }),
  );
Example #4
Source File: projects.effects.ts    From nuxx with GNU Affero General Public License v3.0 6 votes vote down vote up
@Effect()
  ViewProject$ = this.actions$.pipe(
    ofType(ProjectActions.ViewRecipe),
    switchMap(({ data }) => {
      return this.restService.getRecipe(data).pipe(
        map((projectData) => {
          const project = {
            name: projectData.name,
            uuid: projectData.uuid,
            mutable: projectData.mutable,
            ...projectData.data,
          }
          this.eventEmitterService.broadcast('initialize:node', {})
          this.eventEmitterService.broadcast('load: code', projectData.code)
          return ProjectActions.SaveProjectSuccess({ data: project })
        }),
        catchError((error) => {
          if (error.status >= 500) return of(GlobalError.ServerError({message: error.error, _type: 'Error'}))
          else return of(ProjectActions.ApiProjectRequestFail({ data: error }))
        })
      )
    }),
  )
Example #5
Source File: service.effects.ts    From digital-bank-ui with Mozilla Public License 2.0 6 votes vote down vote up
@Effect()
  loadTeller$: Observable<Action> = this.actions$.pipe(
    ofType(tellerActions.LOAD_TELLER),
    map((action: tellerActions.LoadTellerAction) => action.payload),
    mergeMap(officeId =>
      this.tellerService.fetch(officeId).pipe(
        map(teller => new tellerActions.LoadTellerSuccessAction(teller)),
        catchError(error => of(new tellerActions.LoadTellerSuccessAction([]))),
      ),
    ),
  );