File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 1+ import { createReducer , on } from "@ngrx/store" ;
12import { BookModel } from "src/app/shared/models/book.model" ;
3+ import { BooksPageActions } from "src/app/books/actions" ;
24
35const createBook = ( books : BookModel [ ] , book : BookModel ) => [ ...books , book ] ;
46const updateBook = ( books : BookModel [ ] , changes : BookModel ) =>
@@ -7,3 +9,29 @@ const updateBook = (books: BookModel[], changes: BookModel) =>
79 } ) ;
810const deleteBook = ( books : BookModel [ ] , bookId : string ) =>
911 books . filter ( book => bookId !== book . id ) ;
12+
13+ export interface State {
14+ collection : BookModel [ ] ;
15+ activeBookId : string | null ;
16+ }
17+
18+ export const initialState : State = {
19+ collection : [ ] ,
20+ activeBookId : null
21+ } ;
22+
23+ export const booksReducer = createReducer (
24+ initialState ,
25+ on ( BooksPageActions . clearSelectedBook , BooksPageActions . enter , state => {
26+ return {
27+ ...state ,
28+ activeBookId : null
29+ } ;
30+ } ) ,
31+ on ( BooksPageActions . selectBook , ( state , action ) => {
32+ return {
33+ ...state ,
34+ activeBookId : action . bookId
35+ } ;
36+ } )
37+ ) ;
You can’t perform that action at this time.
0 commit comments