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 );
The createSelector can be used to select some data from the state based on several slices of the same state. The createSelector function can take up to 8 selector functions for more complete state selections. For example, imagine you have a selectedUser object in the state.
Reducerslink. Reducers in NgRx are responsible for handling transitions from one state to the next state in your application. Reducer functions handle these transitions by determining which actions to handle based on the type.
Key concepts To build and operate on our state, we will need the following basic building blocks: Store is where state of the application will be stored. It's both an Observable of a state and an Observer of action. Actions describe all the possible and unique events that can occur within the application.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With