MCPcopy Create free account
hub / github.com/ngrx/platform / createNestedSelectors

Function createNestedSelectors

modules/store/src/feature_creator.ts:238–257  ·  view source on GitHub ↗
(
  featureSelector: MemoizedSelector<Record<string, any>, FeatureState>,
  reducer: ActionReducer<FeatureState>
)

Source from the content-addressed store, hash-verified

236}
237
238function createNestedSelectors<FeatureState>(
239 featureSelector: MemoizedSelector<Record<string, any>, FeatureState>,
240 reducer: ActionReducer<FeatureState>
241): NestedSelectors<FeatureState> {
242 const initialState = getInitialState(reducer);
243 const nestedKeys = (
244 isPlainObject(initialState) ? Object.keys(initialState) : []
245 ) as Array<keyof FeatureState & string>;
246
247 return nestedKeys.reduce(
248 (nestedSelectors, nestedKey) => ({
249 ...nestedSelectors,
250 [`select${capitalize(nestedKey)}`]: createSelector(
251 featureSelector,
252 (parentState) => parentState?.[nestedKey]
253 ),
254 }),
255 {} as NestedSelectors<FeatureState>
256 );
257}
258
259function getInitialState<FeatureState>(
260 reducer: ActionReducer<FeatureState>

Callers 1

createFeatureFunction · 0.85

Calls 4

isPlainObjectFunction · 0.90
capitalizeFunction · 0.90
createSelectorFunction · 0.90
getInitialStateFunction · 0.70

Tested by

no test coverage detected