Created
August 2, 2019 08:45
-
-
Save ngohungphuc/6d2ebdff08ef7eda42c2faa598c67039 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment