Skip to content

Instantly share code, notes, and snippets.

@lydemann
Created December 24, 2019 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lydemann/152c4cecf930da109c9cff90e8295e50 to your computer and use it in GitHub Desktop.
Save lydemann/152c4cecf930da109c9cff90e8295e50 to your computer and use it in GitHub Desktop.
todo-list.effects.ts
@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