NetanelBasal
3/2/2017 - 10:17 PM

todos1.effects.ts

export class TodosEffects {
  constructor( private actions$ : Actions, private todosService : TodosService, private store : Store<any> ) {
  }
 
@Effect() getTodos$ = this.actions$
    .ofType(GET_TODOS)
    .withLatestFrom(this.store.select("visibilityFilter"), ( action, filter ) => filter)
    .switchMap(filter =>
      this.todosService.getTodos(filter)
        .map(todos => ({type: GET_TODOS_SUCCESS, payload: todos}))
        .catch(() => Observable.of({type: GET_TODOS_ERROR})));
}