I have looked at the 2 other posts regarding this, the one with the wrapping around the larger state does not apply whilst the other one with registering multiple forFeature -- I have done some testing around that and even if I import it before or after the forRoot(reducers) in my app.module, it makes no difference.
I'm sure I'm missing something obvious around the configuration.
My configuration:
export const orderAdapter: EntityAdapter<IOrder> = createEntityAdapter<IOrder>({
selectId: (order: IOrder) => order._id
});
export interface AllOrdersState extends EntityState<IOrder> {}
export const initialState: AllOrdersState = orderAdapter.getInitialState({
ids: [],
entities: {}
});
export const OrdersState = createFeatureSelector<AllOrdersState>('orders');
export const {
selectIds,
selectEntities,
selectAll,
selectTotal
} = orderAdapter.getSelectors(OrdersState);
My actual reducer:
export function ordersReducer(
state: AllOrdersState = initialState,
action: actions.OrdersActions
) {
case actions.CREATE_MANY: {
console.log(action.orders);
return orderAdapter.addMany(action.orders, state);
}
}
I register in my Order.Module as:
StoreModule.forFeature('orders', ordersReducer),
My main reducer map:
const reducers: ActionReducerMap<AppState> = {
order: orderReducer,
admin: adminReducer,
tlabs: tlabsReducer,
reports: reportsReducer,
settings: settingsReducer,
orders: ordersReducer
};
Then the main import in app.module:
StoreModule.forRoot(reducers),
Trying to read the entities:
Constructor:
private store: Store<AppState>
Actual function:
this.store
.select(ordersReducer.selectAll)
Where that import is taken from:
import * as ordersReducer from '../../../../../store/reducers/orders.reducer';
I had this error because I was setting up my selector with the wrong feature key:
export const selectIocState = createFeatureSelector<fromIoc.IocState>('this_key_was_wrong');
it should match what you have loaded in the feature module:
StoreModule.forFeature('feature_key', iocReducer),
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With