ngrx

AsyncPipe initial value null only if subscription is not shared

若如初见. 提交于 2019-12-24 18:34:58
问题 Given a template that looks like something like this <some-component *ngIf="someColdObservable$ | async" [result]="someColdObservable$ | async" ></some-component> and an observable that looks like this: someColdObservable$: this.store.pipe( select(isAllowedToDoThis), filter(Boolean), flatMap(() => apiRequest()) ); The someColdObservable$ gets subscribed to twice (as expected), which in turn issues two api calls (this is obviously a code smell, but let's disregard that at the moment). In this

Facing issue in updating selected user state in angular using ngrx

给你一囗甜甜゛ 提交于 2019-12-24 16:53:31
问题 Hi guys i am new to ngrx in angular. I am showing a list of users and given a view button based on view click i want to display user info of only selected latest one. I am using ngrx for this but what happens it merge the new selected with existing one but i want latest one below is my stackbiltz link. Please check and let me know how can i modify it 回答1: The problem isn't the reducer, but how the state is structured. @ngrx/entity keeps a collection of loaded entities, it isn't fitted for a

Handling loading state of multiple async calls in an action/reducer based application

蓝咒 提交于 2019-12-24 12:16:58
问题 I don´t think this issue is bound to a specific framework or library, but applies to all store based application following the action - reducer pattern. For clarity, I am using Angular and @ngrx. In the application I am working on we need to track the loading state of individual resources. The way we handle other async requests is by this, hopefully familiar, pattern: Actions GET_RESOURCE GET_RESOURCE_SUCCESS GET_RESOURCE_FAILURE Reducer switch(action.type) case GET_RESOURCE: return { ..

How to update states of multiple reducers with a single action in ngrx store?

泄露秘密 提交于 2019-12-24 11:57:17
问题 I have multiple reducers in my application which are combined in app.reducers.ts. When my action happens state of one reducer should be update with single value from current state of the other reducer(so unplanned delivery will become scheduled) and then remove that value from state of second reducer. Here is how I can delete it, but before doing this I need to update other state. case UNPLANNED_ACTIONS.REMOVE_UNPLANNED_DELIVERY: return Object.assign({}, state, { deliveries: state.deliveries

NGRX Effect Typescript Error When Trying to Return Multiple Actions

落花浮王杯 提交于 2019-12-24 10:44:47
问题 I'm facing some difficulties when trying to return multiple actions in my NGRX effect. I know how to return multiple actions, but I'm trying to set up two sets of actions to fire based on a boolean value. The code is as follows: @Effect() loadCompanyDetail = this.actions$ .ofType(fromActions.COMPANY_DETAIL_LOAD) .pipe( switchMap(() => { return this.companyService .getCompanyByID( fromUtility.obs2Str( this.routerStore.select(fromRouter.getCompanyId) ) ) .pipe( switchMap(res => { switch (res

Get current state in ngrx

别来无恙 提交于 2019-12-24 08:48:06
问题 I'm trying to print the current state in ngrx using a minimal example: interface AppState { counter : number; } export function Reducer(state : AppState = { counter : 0 }, action : Action) { console.log(`counter: ${state.counter}`); return { counter: state.counter + 1 }; } @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { title = 'app'; constructor(private store : Store<AppState>) { let observable :

ngrx updating state based on the angular2-router route

自作多情 提交于 2019-12-24 08:36:08
问题 So, continuing working on the redux-based Angular2 app with REST server. In the app I have the following reducers: AuthReducer -> AuthState UserReducer -> UserState UserListReducer -> UserListState ArticleReducer -> ArticleState ArticleListReducer -> ArticleListState The app uses many of those reducers in multiple places (i.e. pages/routes). The app state itself is composed the following way (app routes are in the comments): export interface AppState { localUser: AuthState //homePage with

My NgRx effects not working, nothing happend

北城以北 提交于 2019-12-24 05:15:05
问题 I have problem with my NgRx effects. The application correctly adds to the store, unfortunately my effects with the request are not performed, i.e. at the time of launching the addition of a new car, add it to the store and that's it. The problem is that there are no console logs from my effects, no http error because of the wrong url, nothing at all. My app code: Reducer import { Action } from '@ngrx/store'; import * as CarActions from './car.actions'; import { Car } from 'src/models/car

No provider for Store! Error at injectionError

倾然丶 夕夏残阳落幕 提交于 2019-12-24 01:53:40
问题 app.component.html <page-router-outlet></page-router-outlet> app.component.ts import 'rxjs/add/operator/let'; import { Component, ViewEncapsulation } from '@angular/core'; import { EchoesState, getSidebarCollapsed$ } from './core/store'; import { Store } from '@ngrx/store'; @Component({ selector: "ns-app", templateUrl: "app.component.html", }) export class AppComponent { constructor(private store: Store<EchoesState>){} } app.module.ts import 'nativescript-localstorage'; import { NgModule, NO

store select not running because of ngIf statement

浪尽此生 提交于 2019-12-24 01:37:26
问题 I am busy with MeteorJS and RxJS, which is exiting but also a bit confusing sometimes. My current question is an Angular NgRx question only, not related to MeteorJS. As you can see in the example, there is a ngIf based on showChannels . This boolean is set to false . However, the async for loop inside is referenced to my store.select. However, operators in the pipe are never executed, because of the ngIf. It seems to be a deadlock. How do I enable the subscription to start working? When I do