ngrx-effects

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 =>

Polling server after each server response + delay

巧了我就是萌 提交于 2020-01-15 07:45:11
问题 I am working on an effect, that will be polling server. What I want to achieve is as follows: 1) Send GET request to server 2) After response is received, wait 3 seconds 3) Send same GET request 4) After response is received, wait 3 seconds 5) Send same GET request ... and so on. The code that I have now, doesn't quite work, as it polls server every 3 seconds, no matter if response was received or not: @Effect() pollEntries$ = this.actions$.pipe( ofType(SubnetBrowserPageActions

Angular NgRx - Effect to continue polling a service only called the first time

流过昼夜 提交于 2020-01-04 14:16:23
问题 I have an application where I have just added NgRX where I wish to use effects to switch polling on and off. Sample outline I followed this post which seemed like a good approach. I have a simplified example of this here, with the bulk of the code is in app.effects.ts . Similar to the example, I have the effects startPolling$ , stopPolling$ and continuePolling$ , except I am using the newer createEffect factory methods. Also, I have moved the delay(2000) above the takeWhile() , as I found if

Getting [Object Object] in angular2 application

余生长醉 提交于 2020-01-03 02:24:47
问题 I have developed angular2 application using ngrx/effects for making http calls. I have used GIT as reference application. Once the response come from http, i am not able to display it on screen. Its showing [object Object]. Here is my code. HTML page linked to component.html <div class="container"> <div class="left-container cf"> <mat-tab-group> <mat-tab label="Configuration">{{jsons}}</mat-tab> <mat-tab label="Captured Output"> </mat-tab> </mat-tab-group> </div> </div> Component.ts export

Returning the result of a forkJoin from an ngrx/store effect

↘锁芯ラ 提交于 2019-12-24 22:42:47
问题 I am trying to return the result of a forkJoin in my effect using ngrx store, like this pseudocode demonstrates: @Effect() someEffect$: Observable<Action> = this.action$.pipe( ofType<SomeActionType>(ActionTypes.SomeActionType), switchMap((action: any) => this.http.get<any>('some/url').pipe( map(someResult => { // this implementation is unimportant, just the gist of the flow I'm after const potentialResults = oneOrMany(someResult); if( potentialResults.length === 1 ) { return new SomeAction

Effect dispatched an invalid action:

£可爱£侵袭症+ 提交于 2019-12-24 19:27:32
问题 I use Angular 7.1.4 My Effect: @Injectable() export class LoginEffects { constructor(private actions$: Actions, private authService: AuthenticationService) { } @Effect({dispatch: true}) loginRequest$: Observable<any> = this.actions$.pipe( ofType(LoginActionsType.LOGIN_REQUEST), exhaustMap(payload => { // it might be switchMap, the error is the same. console.log(payload); return this.authService.login(payload.user, payload.password) // TypeScript Errors: Property 'user' does not exist on type

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

NgRX Effect for downloading media file and dispatching progress; how to deal with the stream and throttling

只愿长相守 提交于 2019-12-22 18:05:02
问题 I am struggling a bit with understanding and applying @Effects for my episode Download option. I got some help in another question and this is my latest concoction. Quick overview: User clicks download which dispatches a DOWNLOAD_EPISODE action which is captured in the first Effect. The download call returns a stream of HttpEvents and a final HttpResponse. During the event.type === 3 I want to report download progress. When event.type === 4 the body has arrived and I can call the success

@ngrx/effects: testing an effect returns empty()

有些话、适合烂在心里 提交于 2019-12-18 08:46:36
问题 I am using @ngrx/effects 4.1.1. I have an effect that returns an empty observable like this: @Effect() showDialog$: Observable<Action> = this .actions$ .ofType( ActionTypes.DIALOG_SHOW ) .map( ( action: DialogAction ) => action.payload ) .switchMap( payload => { this.dialogsService.showDialog( payload.className ); return empty(); } ); I am trying to write a unit test following these guidelines that will test that the effect yields an empty observable. I have this: describe( 'DialogEffects', (

Angular router guard and ROUTER_NAVIGATION effect order

时光毁灭记忆、已成空白 提交于 2019-12-13 12:12:23
问题 There is a simple (Angular 4) route guard, which waits for some data to be loaded from backend: @Injectable() export class ContractsLoadedGuard implements CanActivate { constructor(private store: Store<State>) { } waitForData(): Observable<boolean> { return this.store.select(state => state.contracts) .map(contractList => !!contractList) .filter(loaded => loaded) .take(1); } canActivate(): Observable<boolean> { return this.waitForData(); } } Routing: const routes: Routes = [ { path: 'app-list'