ngrx

Re-using an RxJS Observable to repeat an asynchronous call?

末鹿安然 提交于 2020-02-02 13:04:31
问题 How can an RxJS Observable emit a new value, if the underlying event stream doesn't emit a new value? Given an Angular component which uses an async pipe to display a user's name; export class MyComponent implements OnInit { public user$!: Observable<User>; constructor(private readonly ms: MyService) ngOnInit() { this.user$ = this.ms.getUser(); } } <ng-container *ngIf="user$ | async as user; else empty"> {{ user.name }} </ng-container> <ng-template #empty> No user here. </ng-template> ..

Angular, ngrx - problem with infinitive loop in selector

ⅰ亾dé卋堺 提交于 2020-01-25 08:39:05
问题 There is possible to dispatch action in selector in one store? this.store$.pipe(select(selectPersonByName, {personSelectorProps: this.id[]0})) .subscribe(history => { this.store$.dispatch(selectAssignWorkHistory({historyArray: history})); }); } When I run that code, I have infinitive loop. Dispatch action refresh the store, and re-run selector and so on... 回答1: If this action meant to be fired once upon subscribing to the store selector, you may chain the above statement the RxJS take()

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,

Why should I use Redux in Angular as far as Angular is two-way data binding?

时光总嘲笑我的痴心妄想 提交于 2020-01-23 07:59:06
问题 As far as I understand Redux is mainly intended to enable the two-way data binding in a javascript app. This is very usefull for frameworks that are not two-way data binding, as React for instance. But why using it in Angular that is already natively two-way data binding ? To illustrate my question here is the code that I use in native Angular to make a store that enables the communication of a variable state between two Angular components : 1) The store import { Injectable } from '@angular

Angular - Karma - ngrx - No provider for Store

半城伤御伤魂 提交于 2020-01-23 07:22:42
问题 In one of my unit tests, I'm trying to mock @ngrx/store. I've used the technique successfully in another spec file, but when trying to use it in this one, I'm getting an injection error saying No provider for Store! Below is the relevant code from the spec file: beforeEach(async(() => { const emptyState = { opportunities: { list: { items: [], page: 1, total: 0 } } }; const mockStore = new MockStore<MockAppState>(emptyState); TestBed.configureTestingModule({ declarations: [

Reducers and immutability in ngrx

a 夏天 提交于 2020-01-22 20:36:29
问题 When creating a reducer function in ngrx, everywhere I read says that I should return a copy of the original/previous state. Either by using spread operators or by using a library or tricks like JSON.parse(JSON.stringify(state)) . But I found one catch there and I couldn't find anyone talking about it. The last state returned in a reducer is the state that's going to be shared with all current subscribers and with future subscribers too. That means that all components that use a certain store

Independent instances of the same NgRx feature module

ⅰ亾dé卋堺 提交于 2020-01-22 13:49:50
问题 I am working on an Angular 5 project using NgRx 5. So far I've implemented a skeleton app and a feature module called "Search" which handles its own state, actions and reducers in an encapsulated fashion (by using the forFeature syntax). This module has one root component ( search-container ) which renders an entire tree of child components - together they make up the search UI and functionality, which has a complex state model and a good number of actions and reducers. There are strong

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

NGRX effects - mapping actions to make sequential service calls and updating store

落花浮王杯 提交于 2020-01-16 04:06:06
问题 I want to pass the same action 2 successive times with different entities, for example i want to add 2 entities, entity 1; entity 2; this.store.dispatch(new Add(entity1)); this.store.dispatch(new Add(entity2)); the problem that i encountered is that i got the result of only one action (the entity 2 one) and this is the effect of my action. I want to wait for the result of the first action before passing the second action. @effect() add$ = this.actions$ .ofType<Add>(ADD) .pipe(switchMap(a =>