There are four reducers used in the @ngrx effects example namely (1) books (2) collection (3) layout and (4) search. I don't understand why a collection
reducer is necessary here because the books
reducer already reflects the state of the collection after an add
or remove
operation. I see the use of the collection
reducer as to track the loading
and loaded
status only.
Look at the final state of the books being create with getBookCollection
. The getBookEntities
reflect the state of the collection after any add or remove, so does not have to compose with the collection
reducer.
Am I missing any logic here?
export const getCollectionState = (state: State) => state.collection;
export const getCollectionLoaded = createSelector(getCollectionState, fromCollection.getLoaded);
export const getCollectionLoading = createSelector(getCollectionState, fromCollection.getLoading);
export const getCollectionBookIds = createSelector(getCollectionState, fromCollection.getIds);
export const getBookCollection = createSelector(getBookEntities, getCollectionBookIds, (entities, ids) => {
return ids.map(id => entities[id]);
});