ngrx

Synchronously process an Observable dependent on another Observable using NGRX & Angular

北城以北 提交于 2021-02-10 06:31:40
问题 ngOnInit(): void { this.store.dispatch(new patients.Load([])); this.patients$ = this.store.select(fromPatients.getAll); this.patients$.map(p =>{ // patients$: Observable<Patient[]>; this.rows = p.map(pat => { //I use this on the front end return { username: pat.username, id: pat.id, hasAlert: this.hasAlerts(pat), //made this an observable for the async pipe in view settings: "Settings" }; }); this.table.recalculatePages(); console.log(this.rows); console.log("This happens first"); })

Using payload of action on ActionsSubject subscription on NGRX

萝らか妹 提交于 2021-02-08 05:08:09
问题 I got the old and bad Property 'payload' does not exist on type 'Action doing this actions subscription: Since is a Creation Action, I need the payload to checkout the userId of the recently created User and navigate to /users/userId BTW: I'm following this really nice tutorial @Component({ selector: 'app-sample', templateUrl: 'sample.html', }) export class AppComponent { subs = new Subscription(); constructor(private actionsSubject: ActionsSubject) { this.subs = actionsSubject.subscribe

Getting error while registering reducers using ActionReducerMap: “not assignable to type 'ActionReducerMap<AppState, Action>”

天大地大妈咪最大 提交于 2021-02-04 22:43:50
问题 Below is simplified version of my Angular 5 application. I have a reducer, which I want to register in my root module. In LINE A I am getting following error: ERROR in src/app/store/app.reducers.ts(7,14): error TS2322: Type '{ post: (state: State, action: Action) => void; }' is not assignable to type 'ActionReducerMap<AppState, Action>'. Types of property 'post' are incompatible. Type '(state: State, action: Action) => void' is not assignable to type 'ActionReducer<State, Action>'. Type 'void

Getting error while registering reducers using ActionReducerMap: “not assignable to type 'ActionReducerMap<AppState, Action>”

橙三吉。 提交于 2021-02-04 22:43:04
问题 Below is simplified version of my Angular 5 application. I have a reducer, which I want to register in my root module. In LINE A I am getting following error: ERROR in src/app/store/app.reducers.ts(7,14): error TS2322: Type '{ post: (state: State, action: Action) => void; }' is not assignable to type 'ActionReducerMap<AppState, Action>'. Types of property 'post' are incompatible. Type '(state: State, action: Action) => void' is not assignable to type 'ActionReducer<State, Action>'. Type 'void

Shouldn't the state be immutable?

好久不见. 提交于 2021-01-29 11:24:54
问题 I have the folling code: reducer: export function testReducer(state = [], action:TestActions):any[] { switch (action.type) { case TestAction1Success: { return [...action.payload]; } case TestAction2Success: { return [ ...state, action.payload ]; } case TestAction3Success: { const list = state.map(x => { if(x.id === action.payload.id){ return action.payload } return x; }) return [ ...list ]; } default: { return state; } } } component: ngOnInit() { this.store.dispatch(new TestAction1()); //

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

Adding service dependent logic to NGRX actions in an Angular application

瘦欲@ 提交于 2021-01-29 04:46:09
问题 I have an actions file like this: export enum ActionTypes { FailureAction = 'Failure action', } export class FailureAction implements Action { readonly type = ActionTypes.FailureAction; constructor(public payload: any) { } } export type ActionTypes = FailureAction; I want to add some logic in the FailureAction class so that whenever this action gets called, we call a service that decides how to show an error (the only parameter is a code). I created a class that has the code parameter in the

Angular NGRX looping response data

风格不统一 提交于 2021-01-28 21:21:43
问题 // action export class LoadPlayersWinLoseCount implements Action { readonly type = PlayersActionTypes.LOAD_PLAYERS_WIN_LOSE_COUNT; constructor(public accountId, public queryParams, public payload?: IWinlose, ) {} } // reducer export function playersWinLoseCount(state = initialStateWinLose, action: PlayersActions): IWinlose { switch (action.type) { case PlayersActionTypes.LOAD_PLAYERS_WIN_LOSE_COUNT: console.log(JSON.stringify(state)); console.log(action.payload); return { ...state, ...action

Dispatch ngrx store action in route resolver

北城余情 提交于 2021-01-27 05:31:30
问题 I'm currently have a container (stateful) component which dispatches a select and a get action based on a route param (id) in the ngOnInit method. The point of these actions to have the data and the selected id in my store. I'm curious would it be correct to dispatch these actions in a resolver? Thanks for the replies. My component: @Component({ selector: 'app-container', templateUrl: './container.component.html', styleUrls: ['./container.component.css'] }) export class ContainerComponent

Mocking MatSnackBar in Angular 8 & Jasmine

你。 提交于 2021-01-24 18:58:36
问题 I have an Angular 8 application that uses the Angular Material MatSnackBar and I am trying to test that the open() method of the class is called. The call to the open() method is within the body of an NgRx store selector, like this: ngOnInit() { this.store.dispatch(fromStore.getFeaturedPlaylists()); this.subscription = this.store.pipe( select(fromStore.selectError), filter(err => !!err), switchMap((err) => this.snackBar.open( `Error: ${err.message}`, 'Try again', {duration: 5000})