Created
December 24, 2019 14:09
-
-
Save lydemann/152c4cecf930da109c9cff90e8295e50 to your computer and use it in GitHub Desktop.
todo-list.effects.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Injectable() | |
export class TodoListEffects { | |
public getTodoListRequest$ = createEffect(() => | |
this.actions$.pipe( | |
ofType(TodoListActions.getTodoListRequest), | |
withLatestFrom(this.store.select(getRole())), | |
exhaustMap((role) => { | |
if(role !== Roles.Admin) { | |
return of(TodoListActions.getTodoListUnauthorized()); | |
} | |
this.todoListResourcesService.getTodos().pipe( | |
map(todoList => TodoListActions.getTodoListResponse({ todoList })), | |
catchError((error: Error) => | |
of(TodoListActions.getTodoListFailed({ error })), | |
), | |
), | |
} | |
), | |
), | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment