ngrx

ngrx store subscription not called when state changes

偶尔善良 提交于 2019-12-21 09:35:04
问题 I am creating an application with dummy data defined in my service. In one component, I have the following function that deletes a product: removeItem(productId: string) { this.cartService.removeItem(productId); } and the service as follows: removeItem(productId: string) { const itemIndex = this.cart.products.findIndex(el => el.id === productId); if (itemIndex > -1) { this.cart.products.splice(itemIndex, 1); return Observable.of(this.cart) .subscribe((cartResponse: Cart) => { this.store

What is the best structure for app using ngrx?

ぐ巨炮叔叔 提交于 2019-12-21 07:22:33
问题 Structure 1 reducers index.ts //Combine all reducers user.reducer.ts product.reducer.ts actions index.ts //Combine all actions user.action.ts product.action.ts effects index.ts //Combine all effects user.effect.ts product.effect.ts selector //Combine all selectors user.selector.ts product.selector.ts OR user user.reducer.ts user.action.ts user.effect.ts user.selector.ts product product.reducer.ts product.action.ts product.effect.ts product.selector.ts reducers.ts //Combine all reducers

@ngrx/store combine multiple reducers from feature module

血红的双手。 提交于 2019-12-20 19:47:35
问题 I am currently working on a simple test app to learn more about the @ngrx/store. I have a module called TrainingModule which should store some exercises and more information. The code works, but i try to improve here. What i currently have is my feature module that looks like this: @NgModule({ imports: [ CommonModule, TrainingRoutingModule, StoreModule.forFeature('exercises', exerciseReducer) ], declarations: [ TrainingDashboardComponent, TrainingCoreComponent, TrainingNavComponent,

ngrx dealing with nested array in object

别说谁变了你拦得住时间么 提交于 2019-12-20 10:37:09
问题 I am learning the redux pattern and using ngrx with angular 2. I am creating a sample blog site which has following shape. export interface BlogContent { id: string; header: string; tags: string[]; title: string; actualContent: ActualContent[]; } and my reducer and actions are as following: import { ActionReducer, Action } from '@ngrx/store'; import * as _ from 'lodash'; export interface ActualContent { id: string; type: string; data: string; } export interface BlogContent { id: string;

dispatch multiple actions in one effect

ぐ巨炮叔叔 提交于 2019-12-20 09:39:10
问题 I would like to diapatch two actions in one effect. Currently I have to declare two effects to achieve this : // first effect @Effect() action1$ = this.actions$ .ofType(CoreActionTypes.MY_ACTION) .map(res => { return { type: "ACTION_ONE"} }) .catch(() => Observable.of({ type: CoreActionTypes.MY_ACTION_FAILED })); // second effect @Effect() action2$ = this.actions$ .ofType(CoreActionTypes.MY_ACTION) .map(res => { return { type: "ACTION_TWO"} }) .catch(() => Observable.of({ type:

Ngrx : Cannot assign to read only property 'Property' of object '[Object]'

我的未来我决定 提交于 2019-12-20 02:48:06
问题 I'm using ngrx store. In my state I have to items export interface ISchedulesState { schedulings: ISchedules; actualTrips: ISchedule[]; } Here are my interfaces export interface ISchedules { [key: string]: ISchedule[]; } export interface ISchedule { dest: number; data: string } In reducer I update actualTrips export const SchedulingReducers = ( state = initialSchedulingState, action: SchedulesAction ): ISchedulesState => { switch (action.type) { case ESchedulesActions.GetSchedulesByDate: {

Ngrx 6.1.0 - Select is deprecated - What is the new syntax?

一曲冷凌霜 提交于 2019-12-19 05:16:07
问题 The following ngrx select is deprecated. this.store.select(state => state.academy.academy).subscribe((academy) => { this.academy = academy; }); I found this at store.d.ts @deprecated from 6.1.0. Use the pipeable `select` operator instead. So... what's the correct syntax? I try this.store.pipe(select(state => state.academy.academy).subscribe((academy) => { this.academy = academy; })) Error: Cannot find name 'select'. Did you mean 'onselect'? 回答1: import {Component, OnInit} from '@angular/core'

How to reset all states of ngrx/store?

非 Y 不嫁゛ 提交于 2019-12-18 14:11:30
问题 I am using Angular 2 with ngrx/store. I want to reset the whole store states when user dispatch USER_LOGOUT . I read the Dan Abramov's answer of How to reset the state of a Redux store?, but I didn't figure out how to write rootReducer correctly and where to put it when using ngrx/store. Or is there any other way to handle this in ngrx/store? bootstrap(App, [ provideStore( compose( storeFreeze, storeLogger(), combineReducers )({ router: routerReducer, foo: fooReducer, bar: barReducer }) ) ]);

Providing root reducer in @ngrx/store 4.0

丶灬走出姿态 提交于 2019-12-18 12:34:17
问题 In @ngrx/store 2.0 we could provide the root reducer as a function and from there we split our logic inside the application. After I updated to @ngrx/store 4.0 I cannot use this feature any more from what I can see the reducers need to be a map of reducers which will create objects under the same keys in the state. Is there a way to use the old behavoir in @ngrx/store 4.0 In my state components are aware one of another and I need to be able to split my state dynamically also I need to be able

Providing root reducer in @ngrx/store 4.0

帅比萌擦擦* 提交于 2019-12-18 12:34:14
问题 In @ngrx/store 2.0 we could provide the root reducer as a function and from there we split our logic inside the application. After I updated to @ngrx/store 4.0 I cannot use this feature any more from what I can see the reducers need to be a map of reducers which will create objects under the same keys in the state. Is there a way to use the old behavoir in @ngrx/store 4.0 In my state components are aware one of another and I need to be able to split my state dynamically also I need to be able