ngrx

Angular 6 / NGRX Combine Reducers

て烟熏妆下的殇ゞ 提交于 2019-12-09 00:34:09
问题 I am using Angular 6 w/ NgRX 4. I have multiple reducers I would like to combine. app.module.ts import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { StoreModule } from '@ngrx/store'; import { EffectsModule } from '@ngrx/effects'; import { StoreDevtoolsModule } from '@ngrx/store-devtools'; import { AppComponent } from './app.component'; import counterEffects from './store/counter/counter.effects'; import reducers from './store/reducers';

Mocking ngrx/store

若如初见. 提交于 2019-12-08 18:13:34
问题 This is in regards to the Angular 2 official release. I know that unit testing has changed drastically between beta, RC, and the official release. What's a good way to mock @ngrx/store in a unit test when it's used as a parameter in a constructor? It's not as simple as mocking a service. For example, if I wanted to mock a service, then I could do something like this: let serviceStub = { }; // not a true mocked service, just a stub, right? let de: DebugElement; let el: HTMLElement; let

NgRX 8 effects - Type 'Observable<unknown>' is not assignable to type 'Observable<Action>'

不羁岁月 提交于 2019-12-08 16:53:04
问题 While working with NgRX 8 my colleagues and me are frequently facing a weird error message when implementing the effects. Type 'Observable<unknown>' is not assignable to type 'Observable<Action> | ((...args: any[]) => Observable<Action>)' It is related to type issues. It is really annoying that the message is so unspecific and it marks the complete effect. This appears frequently and is really hard to resolve. We are wondering if there is something we can do in order to quickly identify the

NGRX Effects how to pass parameter to withLatestFrom operator

大兔子大兔子 提交于 2019-12-08 08:26:27
问题 I am struggling with passing parameter to selector when by using withLatestFrom, which was mapped earlier from load action payload loadLocalSubServices$: Observable<Action> = this.actions$.pipe( ofType(LocalSubServiceTemplateActions.LocalSubServicesTemplateActionTypes.LoadLocalSubService), map((action: LocalSubServiceTemplateActions.LoadLocalSubService) => action.payload.globalSubServiceId), // and below I would like to pass globalSubServiceId withLatestFrom(this.store.pipe(select

What is the meaning of square brackets in the enum declaration in typescript?

一世执手 提交于 2019-12-08 07:58:15
问题 I was going through a typescript file in an Angular ngrx project named as collection.ts and there, I saw the following enum constant being declared. import { Action } from '@ngrx/store'; import { Book } from '../models/book'; export enum CollectionActionTypes { AddBook = '[Collection] Add Book', AddBookSuccess = '[Collection] Add Book Success', AddBookFail = '[Collection] Add Book Fail', RemoveBook = '[Collection] Remove Book', RemoveBookSuccess = '[Collection] Remove Book Success',

Unit testing NgRx effect to ensure the service method was called - ain't working

时光毁灭记忆、已成空白 提交于 2019-12-08 05:08:10
问题 I am using NgRx ^7.0.0 version. This is my NgRx effect class: import { Injectable } from '@angular/core'; import { ApisService } from '../apis.service'; import { Effect, Actions, ofType } from '@ngrx/effects'; import { Observable } from 'rxjs'; import { ApisActionTypes, ApisFetched } from './apis.actions'; import { mergeMap, map } from 'rxjs/operators'; @Injectable() export class ApisEffects { constructor(private apisS: ApisService, private actions$: Actions) { } @Effect() $fetchApisPaths:

How to correctly pass props to a component with RxJS in Angular 4?

本小妞迷上赌 提交于 2019-12-08 03:38:01
问题 Here is my component: @Component({ selector: 'bc-goods-detail', template: ` <span>good id: {{good?.id}}</span> <input [value]="good?.name" (input)="onInput($event)" /> <button (click)="onClick()">Save</button> `, styles: [] }) export class GoodsDetailComponent { @Input() good: Good; @Output() save = new EventEmitter<Good>(); onClick() { this.save.emit(this.good); } onInput ($event) { this.good.name = $event.target.value; } } When I change the name in input and then I am pressing save button

Angular2 NGRX Performance Issues On Dispatch?

岁酱吖の 提交于 2019-12-08 03:16:40
问题 I've been working on an application in Angular2/CLI/NGRX and things have been going well until recently. I'm noticing some pretty big spikes in performance especially with consecutive dispatches within the same container. For example lets say I have the following defined: public appEnvironment$: Observable<IEnvironment>; public assessment$: Observable<IAssessment>; public assessmentComments$: Observable<ICommentActivity[]>; public assessmentEvidence$: Observable<IEvidenceActivity[]>; public

NgRx - How are states combined and initialized

血红的双手。 提交于 2019-12-07 22:14:53
问题 When we initialize our Store: StoreModule.provideStore({r1: Reducer1, r2: Reducer2, ...}) we do pass the reducers to the Store to be stored. But we never actually pass the initial states to the store, except defining it in the reducers functions: const someReducer = (state = initialState, act: Action) => { ... } SO, is it that when application bootstraps, all the reducers are called once to acquire the initial state from reducer definition, and then store the state in the NgRx Store? If so,

How to handle errors inside reducers?

冷暖自知 提交于 2019-12-07 16:23:08
问题 I've my loggerService and I need to catch all errors in reducer and send it via my service to the server. How can I do it? I know that reducer should be a pure function, but still any ideas? I need to add in reduser try catch case actions.GAMES_LOADED{ ...... try{} catch(err){ this.loggerService.error(err); } } Or maybe throw something in reducer and catch it in some place... Thanks a lot 回答1: Short answer: You don't. Why? - The reducer is only responsible for updating the store, it should