Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do you link the feature selector with the schema selector? #38

Open
irinelpascu opened this issue Aug 22, 2018 · 2 comments
Open

How do you link the feature selector with the schema selector? #38

irinelpascu opened this issue Aug 22, 2018 · 2 comments

Comments

@irinelpascu
Copy link

irinelpascu commented Aug 22, 2018

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 ()
at defaultStateFn (store.js:545)
at store.js:585

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
);
@herrpatrickmueller
Copy link

I don't understand this either. Have you found a solution yet?

@zahnrodolfo
Copy link

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(Schema);

export const featureState = createFeatureSelector(State)('yourFeatureStateName');

export const getMyFeatureStateDenormalized = createSelector(
featureState,
myFeatureSchemaSelector.getEntities
);

I hope it helps @irinelpascu @parallactic-zurich

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants