Skip to content

Instantly share code, notes, and snippets.

@brandonroberts
Created November 17, 2021 13:55
Show Gist options
  • Select an option

  • Save brandonroberts/b39093ceb792aa39ea5c9e89180b3676 to your computer and use it in GitHub Desktop.

Select an option

Save brandonroberts/b39093ceb792aa39ea5c9e89180b3676 to your computer and use it in GitHub Desktop.
Create Feature 1 - NgRx 13
// 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