File tree Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change 1- import { createReducer , on , Action } from "@ngrx/store" ;
2- import { BookModel } from "src/app/shared/models/book.model" ;
1+ import { createReducer , on , Action , createSelector } from "@ngrx/store" ;
2+ import {
3+ BookModel ,
4+ calculateBooksGrossEarnings
5+ } from "src/app/shared/models/book.model" ;
36import { BooksPageActions , BooksApiActions } from "src/app/books/actions" ;
47
58const createBook = ( books : BookModel [ ] , book : BookModel ) => [ ...books , book ] ;
@@ -63,3 +66,15 @@ export const booksReducer = createReducer(
6366export function reducer ( state : State | undefined , action : Action ) {
6467 return booksReducer ( state , action ) ;
6568}
69+
70+ export const selectAll = ( state : State ) => state . collection ;
71+ export const selectActiveBookId = ( state : State ) => state . activeBookId ;
72+ export const selectActiveBook = createSelector (
73+ selectAll ,
74+ selectActiveBookId ,
75+ ( books , activeBookId ) => books . find ( book => book . id === activeBookId ) || null
76+ ) ;
77+ export const selectEarningsTotals = createSelector (
78+ selectAll ,
79+ calculateBooksGrossEarnings
80+ ) ;
You can’t perform that action at this time.
0 commit comments