Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {
- createEntityAdapter,
- EntityAdapter,
- EntityState
- } from "@ngrx/entity";
- export interface IUser {
- id: string;
- name: string;
- email: string;
- }
- export interface IUserState extends EntityState<IUser>{
- // additional entities state properties
- users: [];
- }
- export const adapter: EntityAdapter<IUser> = createEntityAdapter<IUser>();
- export const initialState: IUserState = adapter.getInitialState({
- users: []
- });
- export function userReducer(
- state: IUserState = initialState,
- action: UserActions
- ): IUserState {
- switch (action.type) {
- case UpdateUser: {
- const updatedUser = {
- id: action.payload.id,
- changes: { email: action.payload.id }
- };
- return adapter.updateOne(updatedUser, state);
- }
- }
- //export common use selector for your selector
- export const {
- selectAll,
- selectEntities,
- selectIds,
- selectTotal
- } = adapter.getSelectors();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement