Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

06-selectors #9

Open
wants to merge 1 commit into
base: 05-reduce-api-actions
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/app/shared/state/books.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);