( featureSelector: MemoizedSelector<Record<string, any>, FeatureState>, reducer: ActionReducer<FeatureState> )
| 236 | } |
| 237 | |
| 238 | function 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 | |
| 259 | function getInitialState<FeatureState>( |
| 260 | reducer: ActionReducer<FeatureState> |
no test coverage detected