According to the example application comments:
For example, in the /collection.ts reducers of the selector at the bottom of the file, they only refer to a collection slice:
export const getLoaded = (state: State) => state.loaded; export const getLoading = (state: State) => state.loading; export const getIds = (state: State) => state.ids;
These collection selectors cannot be used with state.select () because state.select expects to work with the entire AppState. Therefore, in /index.ts reducers, the selector is then wrapped with another selector so that it works with the entire AppState:
export const getCollectionLoading = createSelector(getCollectionState, fromCollection.getLoading);
Let's get back to your question: why should this be used for re-selection. Repeated selection in this case does not provide any optimizations. Thus, the main purpose of reselection is that it provides the ability to arrange selectors.
Using this composition function, we can make collection.ts only selectors for cutting collections. Then in index.ts we can have a selector at the AppState level. In addition, we can have selectors that work on different sections of the store, such as this one:
export const getSearchResults = createSelector(getBookEntities, getSearchBookIds, (books, searchIds) => { return searchIds.map(id => books[id]); });
source share