ngrx-effects

Run ngrx/effect outside of Angular's zone to prevent timeout in Protractor

心已入冬 提交于 2019-12-03 08:29:58
问题 I just started to write e2e tests for my app and am running into timeout problems with Protractor and ngrx/effects. I have the following effect dispatching an action every couple of minutes: @Effect() setSessionTimer$ = this.actions$ .ofType(Auth.ActionTypes.SET_SECONDS_LEFT) .map(toPayload) .switchMap(secondsLeft => Observable.concat( Observable.timer((secondsLeft - 60) * 1000).map(_ => new Auth.SessionExpiringAction(60)), Observable.timer(60 * 1000).map(_ => new Auth.SessionExpiredAction())

When to use ngrx/effect in angular2

扶醉桌前 提交于 2019-12-03 02:51:11
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 action to save the returned values in my store. If your case stays that simple, then you won't need an

Run ngrx/effect outside of Angular's zone to prevent timeout in Protractor

最后都变了- 提交于 2019-12-02 21:03:34
I just started to write e2e tests for my app and am running into timeout problems with Protractor and ngrx/effects. I have the following effect dispatching an action every couple of minutes: @Effect() setSessionTimer$ = this.actions$ .ofType(Auth.ActionTypes.SET_SECONDS_LEFT) .map(toPayload) .switchMap(secondsLeft => Observable.concat( Observable.timer((secondsLeft - 60) * 1000).map(_ => new Auth.SessionExpiringAction(60)), Observable.timer(60 * 1000).map(_ => new Auth.SessionExpiredAction()) )); Trying to run a Protractor test causes the test to timeout with the following error, since Angular

How to do http polling in ngrx effect

天涯浪子 提交于 2019-12-02 19:51:16
问题 I have this effect, and I'm trying to use timer to poll for data every x seconds. But I can't figure out how timer is supposed to interact with the data streams. I tried adding another switchMap to the top, but then I couldn't pass the action and payload to the second switchmap. Any ideas? I looked at this post but my situation is a little different. I'm passing a payload with my action that I need to access, and I'm using ngrx 6. @Effect() getData = this.actions$ .ofType(appActions.GET_PLOT

How to do http polling in ngrx effect

大憨熊 提交于 2019-12-02 09:38:59
I have this effect, and I'm trying to use timer to poll for data every x seconds. But I can't figure out how timer is supposed to interact with the data streams. I tried adding another switchMap to the top, but then I couldn't pass the action and payload to the second switchmap. Any ideas? I looked at this post but my situation is a little different. I'm passing a payload with my action that I need to access, and I'm using ngrx 6. @Effect() getData = this.actions$ .ofType(appActions.GET_PLOT_DATA) .pipe( switchMap((action$: appActions.GetPlotDataAction) => { return this.http.post( `http://$

Why action doesn't trigger Effect the second time it runs?

余生颓废 提交于 2019-12-01 19:35:51
Effect: @Effect() loadDocsEffect$ = this.actions$.pipe( ofType(myActionTypes.LoadDocs), mergeMap(action => this.myService.getDocs()), map(data => new LoadDocsSuccess(data)), catchError(error => Observable.of(new LoadDocsFailure(error))) ); It works when I have data returned, but when the server responds with an error - 404 for example, the observable is complete and doesn't trigger the effect the second time I dispatch an action. I looked for a way to handle the error properly and to continue the observable stream so I could subscribe to it in my component and act accordingly. The solution in

Observable with rx broken after error

南楼画角 提交于 2019-12-01 18:29:05
问题 Im trying to write login flow for my app using ngrx store + ng effects. I have managed to write it and it works in happy scenerio, but when user inputs wrong values to the form, so that server responds with 401, the next login attempt has no effects. I have read that the exception must be catch when working with observables in order not to 'break' the stream, but as far i know I'm catch the exception and still its now working. belowe the code; export class LoginComponent { logged = new

Observable with rx broken after error

微笑、不失礼 提交于 2019-12-01 18:13:05
Im trying to write login flow for my app using ngrx store + ng effects. I have managed to write it and it works in happy scenerio, but when user inputs wrong values to the form, so that server responds with 401, the next login attempt has no effects. I have read that the exception must be catch when working with observables in order not to 'break' the stream, but as far i know I'm catch the exception and still its now working. belowe the code; export class LoginComponent { logged = new Observable<any>(); constructor(private store: Store<AppStore>) { this.logged = store.select('login'); } login

Why action doesn't trigger Effect the second time it runs?

≡放荡痞女 提交于 2019-12-01 17:47:50
问题 Effect: @Effect() loadDocsEffect$ = this.actions$.pipe( ofType(myActionTypes.LoadDocs), mergeMap(action => this.myService.getDocs()), map(data => new LoadDocsSuccess(data)), catchError(error => Observable.of(new LoadDocsFailure(error))) ); It works when I have data returned, but when the server responds with an error - 404 for example, the observable is complete and doesn't trigger the effect the second time I dispatch an action. I looked for a way to handle the error properly and to continue

defer() no longer allows the observable return type

℡╲_俬逩灬. 提交于 2019-12-01 06:25:47
Today I did an upgrade from angular 6 to 7 Along with it I had to upgrade rxjs from 6.1.0 to 6.3.3 and typescript from 2.7.2 to 3.1.1 And now this ngrx effects method is throwing a typescript error: @Effect() init$ = defer(() => { const userData = localStorage.getItem('user'); return (userData) ? of(new Login(JSON.parse(userData))) : of(new Logout()); }); Argument of type '() => Observable | Observable' is not assignable to parameter of type '() => void | Subscribable | Subscribable | PromiseLike | InteropObservable'. It seems that I can no longer use defer to dispatch an action like this, so