ngrx-effects

Ngrx Store, Effects, Http Ajax Polling Setup on Angular 2

别说谁变了你拦得住时间么 提交于 2019-12-01 06:08:10
I'm creating an Ngrx Angular 2 app and was trying to get my http calls to continue polling after a time interval. I have seen the use of the interval() function, but in case of Ngrx, when service calls are done inside @Effect() , it gives an error. Please advise: @Injectable() export class TasksEffects { constructor( private actions$: Actions, private TS: TaskService ){} @Effect() onLoadTasksLoadTasks$: Observable<Action> = this.actions$.ofType(tasksActions.ActionTypes.LOAD_TASKS) .switchMap(() => { return this.TS.index() .map((res) => new tasksActions.LoadTasksSuccessAction(res.json()))

defer() no longer allows the observable return type

喜夏-厌秋 提交于 2019-12-01 05:03:04
问题 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 |

Ngrx Store, Effects, Http Ajax Polling Setup on Angular 2

浪尽此生 提交于 2019-12-01 03:21:43
问题 I'm creating an Ngrx Angular 2 app and was trying to get my http calls to continue polling after a time interval. I have seen the use of the interval() function, but in case of Ngrx, when service calls are done inside @Effect() , it gives an error. Please advise: @Injectable() export class TasksEffects { constructor( private actions$: Actions, private TS: TaskService ){} @Effect() onLoadTasksLoadTasks$: Observable<Action> = this.actions$.ofType(tasksActions.ActionTypes.LOAD_TASKS) .switchMap(

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

风格不统一 提交于 2019-11-29 15:44:44
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', () => { let effects: DialogEffects; let actions: Observable<any>; const mockDialogService = { showDialog

Testing and mocking lettable operators in RxJS 5.5

家住魔仙堡 提交于 2019-11-29 06:47:43
Before lettable operator, I did a helper to modify debounceTime method, so it uses a TestScheduler: export function mockDebounceTime( scheduler: TestScheduler, overrideTime: number, ): void { const originalDebounce = Observable.prototype.debounceTime; spyOn(Observable.prototype, 'debounceTime').and.callFake(function( time: number, ): void { return originalDebounce.call( this, overrideTime, scheduler, ); }); } So the test of the following Observable was easy: @Effect() public filterUpdated$ = this.actions$ .ofType(UPDATE_FILTERS) .debounceTime(DEFAULT_DEBOUNCE_TIME) .mergeMap(action => [...])

Testing and mocking lettable operators in RxJS 5.5

99封情书 提交于 2019-11-28 00:04:41
问题 Before lettable operator, I did a helper to modify debounceTime method, so it uses a TestScheduler: export function mockDebounceTime( scheduler: TestScheduler, overrideTime: number, ): void { const originalDebounce = Observable.prototype.debounceTime; spyOn(Observable.prototype, 'debounceTime').and.callFake(function( time: number, ): void { return originalDebounce.call( this, overrideTime, scheduler, ); }); } So the test of the following Observable was easy: @Effect() public filterUpdated$ =