ngrx-effects

Angular Effects - how to get 100 percent test result (coverage in funcs )?

亡梦爱人 提交于 2021-02-11 13:40:51
问题 here is my effects: import { Injectable } from '@angular/core'; import { Action } from '@ngrx/store'; import { Actions, createEffect, ofType } from '@ngrx/effects'; import { of, Observable } from 'rxjs'; import { catchError, map, switchMap } from 'rxjs/operators'; import * as courseAttributeActions from '../actions/candidate-registration-management.action'; import { CandidateRegistrationManagementService } from '../../services/candidate-registration-management.service'; @Injectable() export

Multiple dispatches while using ngrx/store

萝らか妹 提交于 2021-02-10 17:07:15
问题 I am working on a sample Angular 2 application , and using ngrx/store , ngrx/effects for state management. Below image depicts one of the screens of my application. In order to display books list , categories and authors from the server, below dispatch calls are made to the store. this.store.dispatch(loadCatgories()); this.store.dispatch(loadAuthors()); this.store.dispatch(loadBooks()); And below the are the related effects @Effect() authors$ = this.actions$ .ofType(AuthorActionTypes.LOAD

How to combine this two sevice call with in the single effect one out put result as input of other?

社会主义新天地 提交于 2021-01-29 07:32:57
问题 This is my original effect. It loads data from a service call. getReviewEffect$ = createEffect(() => this.actions$.pipe( ofType(INIT), mergeMap(({ Id }) => this.ReviewService.findByP(Id, new Date(new Date().setDate(new Date().getDate() -30)), new Date(new Date().setDate(new Date().getDate() + 30)), 'Approval') .pipe( mergeMap(reviews => { return [ReviewLoadSuccess({ drugReviews: getReviews(reviews) }) ]; }), catchError(error => { return of(ReviewLoadFailure({ error: error })); }) ) ))); But

Get error response from ngrx@effects to component

狂风中的少年 提交于 2021-01-27 07:10:47
问题 I need to set server error validation for every input field in form. Problem is, I use ngrx@store and in effect I have @Effect({ dispatch: false }) error$ = this.actions$.pipe( ofType(actions.UserActionTypes.Error), map( (error: actions.Error) => { new actions.Error(error); } //this.notificationService.warn(error.error.message) ) ); With this code, I store errors to store. Now I need to get these errors in my component, where I want to check for which input field I get an error, and set error

angular: ngrx effects not firing

余生长醉 提交于 2020-03-19 06:19:52
问题 I've worked on a few Angular apps that implemented Redux (NgRx). I can't figure out my current project's issue. Actions: export class GetUserFromStorage implements Action { readonly type = UserActionTypes.GetUserFromStorage; } export class GetUserFromStorageSuccess implements Action { readonly type = UserActionTypes.GetUserFromStorageSuccess; constructor(public payload: User | null) { } } export class GetUserFromStorageFail implements Action { readonly type = UserActionTypes

ngrx/store state not updating in reducer function called

痴心易碎 提交于 2020-01-25 00:48:27
问题 I am starting to add ngrx(8.4.0) to an existing Angular(8.2) application but one of my actions (see action below) when triggered does not mutate state. auth.actions.ts (partial) export const loginSuccess = createAction( '[SIGN IN] Login Success', props<{ user: any; isNewUser: boolean }>() The loginSuccess action is handled by the reducer function below. auth.reducer.ts (partial) export interface AuthState { user: any; isNewUser: boolean; } export const initialState: AuthState = { user: null,

When to use ngrx/effect in angular2

那年仲夏 提交于 2020-01-22 09:47:24
问题 I have an anuglar2 project that communicates with an api. Recently, I decided to integrate ngrx/store to maintain the state of the components, and follow the dump-smart component architecture. But then while moving on, I read about ngrx/effect which can be used upon the api requests. And here my question comes, why should I use the ngrx/effect library, over just calling the corresponding function in my service from my container component to perform the api request and on success dispatch

How to create local effect in ngrx/effects

匆匆过客 提交于 2020-01-17 06:58:57
问题 How can I do something like that in ngrx/effects: // I want to handle a sign up effect return this.actions$.ofType(user.SIGN_UP_SUCCESS) .map((action: user.SignUpSuccessAction) => action.payload) .mergeMap(() => { // then I have to call two other async actions to add new records return [ new userOptions.Add(new UserOptionsModel()); new userInfo.Add(new UserInfoModel()); ]; }) How can I handle success actions for both userOptions and userInfo actions and then redirect to a Dashboard page? I