ngrx-normalizr
ngrx-normalizr copied to clipboard
How do you link the feature selector with the schema selector?
I cannot understand how I can create a selector to get the feature entities.
Trying to get them using the schemaSelectors.getEntities selector throws an error:
ERROR TypeError: Cannot read property 'entities' of undefined
at normalize.js:99
at store.js:577
at memoized (store.js:519)
at defaultStateFn (store.js:546)
at store.js:585
at memoized (store.js:519)
at store.js:545
at Array.map (
import {
ActionReducerMap,
createFeatureSelector
} from '@ngrx/store';
import {
NormalizedState,
normalized,
createSchemaSelectors
} from 'ngrx-normalizr';
import { Section } from '../../models/section.model';
import { sectionSchema } from '../../schemas/section.schema';
export interface ReportingState extends NormalizedState {
}
export const reducers: ActionReducerMap<NormalizedState> = {
normalized
};
export const getReportingState = createFeatureSelector<ReportingState>(
'reporting'
);
export const getReportingSchemaSelectors = createSchemaSelectors<Section>(sectionSchema);
export const getSectionEntities = createSelector(
fromFeature.getReportingState,
fromFeature.getReportingSchemaSelectors.getEntities
);
I don't understand this either. Have you found a solution yet?
I was able to do it. In my application when we started we had the state without the normalizr and now we are adding features that use the normalizr.
To make the selector work I did the following.
const myFeatureSchemaSelector = createSchemaSelector<Model>(Schema);
export const featureState = createFeatureSelector(State)('yourFeatureStateName');
export const getMyFeatureStateDenormalized = createSelector( featureState, myFeatureSchemaSelector.getEntities );
I hope it helps @irinelpascu @parallactic-zurich