@ngrx/store#Action TypeScript Examples

The following examples show how to use @ngrx/store#Action. 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: auth.effects.ts    From svvs with MIT License 6 votes vote down vote up
signInRun$ = createEffect(() =>
  this.dataPersistence.fetch(AuthActions.signInRun, {
    id: (action, store) => this.getEffectIdFromPayload(this.getState(store).signIn),
    run: (action, store) => {
      return this.authApollo.signIn(this.getState(store).signIn).pipe(
        map<ISignAuthResponse, Action>(payload => {
          this.authStorage.setAccessToken(payload.accessToken)
          return AuthActions.signInSuccess({payload})
        })
      )
    },
    onError: (action, error) => this.errorHandler(action, error, AuthActions.signInFailure)
  })
  )
Example #2
Source File: notification.effects.ts    From digital-bank-ui with Mozilla Public License 2.0 6 votes vote down vote up
@Effect({ dispatch: false })
  createIdentificationCardScanSuccess$: Observable<Action> = this.actions$.pipe(
    ofType(identificationCardScanActions.CREATE_SUCCESS),
    tap(() =>
      this.notificationService.send({
        type: NotificationType.MESSAGE,
        message: 'Scan is going to be uploaded',
      }),
    ),
  );
Example #3
Source File: users.effects.ts    From svvs with MIT License 6 votes vote down vote up
loadUserRun$ = createEffect(() =>
    this.dataPersistence.fetch(UserActions.loadUserRun, {
      run: action =>
        this.userApollo.loadUser().pipe(
          map<IUser, Action>(payload => UserActions.loadUserSuccess({payload})),
        ),
      onError: (action, error) => this.errorHandler(action, error, UserActions.loadUserFailure),
    }),
  )
Example #4
Source File: notification.effects.ts    From digital-bank-ui with Mozilla Public License 2.0 6 votes vote down vote up
@Effect({ dispatch: false })
  deleteIdentificationCardScanSuccess$: Observable<Action> = this.actions$.pipe(
    ofType(identificationCardScanActions.DELETE_SUCCESS),
    tap(() =>
      this.notificationService.send({
        type: NotificationType.MESSAGE,
        message: 'Scan is going to be deleted',
      }),
    ),
  );
Example #5
Source File: abstract-effects.ts    From svvs with MIT License 6 votes vote down vote up
/**
   * Error handler to effects
   *
   * @param action
   * @param error
   * @param responseAction
   * @param debug
   */
  errorHandler(
    action: Action,
    error: Record<string, unknown> = {},
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    responseAction?: (payload?: any) => TypedAction<any>,
    debug = false): Action | never {

    if (debug) {
      console.error(error)
    }

    if (responseAction()) {
      return responseAction({payload: error})
    }

  }
Example #6
Source File: service.effects.ts    From digital-bank-ui with Mozilla Public License 2.0 6 votes vote down vote up
@Effect()
  deleteIdentificationCard$: Observable<Action> = this.actions$.pipe(
    ofType(identificationCards.DELETE),
    map((action: identificationCards.DeleteIdentityCardAction) => action.payload),
    mergeMap(payload =>
      this.customerService.deleteIdentificationCard(payload.customerId, payload.identificationCard.number).pipe(
        map(
          () =>
            new identificationCards.DeleteIdentityCardSuccessAction({
              resource: payload.identificationCard,
              activatedRoute: payload.activatedRoute,
            }),
        ),
        catchError(error => of(new identificationCards.DeleteIdentityCardFailAction(error))),
      ),
    ),
  );
Example #7
Source File: app.reducer.ts    From Angular-Cookbook with MIT License 5 votes vote down vote up
export function reducer(state: AppState = initialState, action: Action) {
  console.log('state', state);
  console.log('action', action);
  return appReducer(state, action);
}
Example #8
Source File: product.actions.ts    From digital-bank-ui with Mozilla Public License 2.0 5 votes vote down vote up
export class ExecuteCommandSuccessAction implements Action {
  readonly type = EXECUTE_COMMAND_SUCCESS;

  constructor(public payload: ExecuteCommandPayload) {}
}