I have been reading the code of ngrx example app and find two function calls
createFeatureSelector<AuthState>('auth');
and
createSelector(selectAuthState,(state: AuthState) => state.status);
What does this do?
export const selectAuthState = createFeatureSelector<AuthState>('auth');
export const selectAuthStatusState = createSelector(
selectAuthState,
(state: AuthState) => state.status
);
Its used as an optimization step for store slices selection. For example, if you return some heavy computation result for some store slice, then using createSelector
will do memoization which means it will keep track of last input params to selector and if they are the same as current ones, it will return last result immediately instead of repeating computation.
ref: https://github.com/ngrx/platform/blob/master/docs/store/selectors.md