From cc8eceefe0e984d131bf6b3c4d6282806f6e3500 Mon Sep 17 00:00:00 2001 From: Mike Ryan Date: Sat, 28 Mar 2020 19:58:06 -0500 Subject: [PATCH] 06-selectors --- src/app/shared/state/books.reducer.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/app/shared/state/books.reducer.ts b/src/app/shared/state/books.reducer.ts index c01615f..bfd4e56 100644 --- a/src/app/shared/state/books.reducer.ts +++ b/src/app/shared/state/books.reducer.ts @@ -63,3 +63,15 @@ export const booksReducer = createReducer( export function reducer(state: State | undefined, action: Action) { return booksReducer(state, action); } + +export const selectAll = (state: State) => state.collection; +export const selectActiveBookId = (state: State) => state.activeBookId; +export const selectActiveBook = createSelector( + selectAll, + selectActiveBookId, + (books, activeBookId) => books.find(book => book.id === activeBookId) || null +); +export const selectEarningsTotals = createSelector( + selectAll, + calculateBooksGrossEarnings +);