Building Your Entity States
Initialization Simplified
Just "buildState()!"
import { IEntityState } from '@briebug/ngrx-auto-entity';
import { Model } from 'models';
const { initialState } = buildState(Model);
export function entityReducer(state = initialState): IEntityState<Model> {
return state;
}Rich Functionality
import { IEntityState } from '@briebug/ngrx-auto-entity';
import { Model } from 'models';
export const {
initialState,
selectors: {
selectAll: allModels,
selectEntities: modelEntities,
selectIds: modelIds,
selectTotal: countOfModels,
// Additional selectors...
},
entityState,
facade: ModelBaseFacade,
reducer: modelReducer // Sadly, this does not work with AOT! :'(
} = buildState(Model);
// Extracted projection for easier unit testing
export const findFirstModel = (state: IEntityState<Model>) =>
(entityState.ids?.length && entityState.entities)
? entityState.entities[entityState.ids[0]]
: null;
// Selectors are simply compositions of other selectors and a projection
export const firstModel = createSelector(
entityState,
findFirstModel
);Last updated