Created
November 17, 2021 13:55
-
-
Save brandonroberts/b39093ceb792aa39ea5c9e89180b3676 to your computer and use it in GitHub Desktop.
Create Feature 1 - NgRx 13
This file contains hidden or 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
| // books.reducer.ts | |
| import { createReducer } from "@ngrx/store"; | |
| import * as BookListPageActions from "./book-list-page.actions"; | |
| import * as BooksApiActions from "./books-api.actions"; | |
| export const featureName = "books"; | |
| export interface State { | |
| books: Book[]; | |
| loading: boolean; | |
| } | |
| const initialState: State = { | |
| books: [], | |
| loading: false, | |
| }; | |
| export const reducer = createReducer( | |
| initialState, | |
| on(BookListPageActions.enter, (state) => ({ | |
| ...state, | |
| loading: true, | |
| })), | |
| on(BooksApiActions.loadBooksSuccess, (state, { books }) => ({ | |
| ...state, | |
| books, | |
| loading: false, | |
| })) | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment