-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c26fbe5
commit 377b291
Showing
5 changed files
with
45 additions
and
5 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,15 @@ | ||
import { Book } from "src/app/shared/models/book.model"; | ||
import { Action } from "@ngrx/store"; | ||
|
||
export enum BooksApiActionTypes { | ||
BooksLoaded = '[Books API] Books Loaded Success', | ||
} | ||
|
||
export class BooksLoaded implements Action { | ||
readonly type = BooksApiActionTypes.BooksLoaded; | ||
|
||
constructor(public books: Book[]) {} | ||
} | ||
|
||
export type BooksApiActions = | ||
| BooksLoaded; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Effect, Actions, ofType } from '@ngrx/effects'; | ||
import { BooksPageActions, BooksApiActions } from './actions'; | ||
import { BooksService } from '../shared/services/book.service'; | ||
import { mergeMap, map, catchError } from 'rxjs/operators'; | ||
import { EMPTY } from 'rxjs'; | ||
|
||
@Injectable() | ||
export class BooksEffects { | ||
|
||
@Effect() | ||
loadBooks$ = this.actions$.pipe( | ||
ofType(BooksPageActions.BooksActionTypes.Enter), | ||
mergeMap(() => | ||
this.booksService.all() | ||
.pipe( | ||
map(books => new BooksApiActions.BooksLoaded(books)), | ||
catchError(() => EMPTY) | ||
) | ||
) | ||
); | ||
|
||
constructor(private booksService: BooksService, private actions$: Actions) {} | ||
} |
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
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
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