Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. import {
  2. createEntityAdapter,
  3. EntityAdapter,
  4. EntityState
  5. } from "@ngrx/entity";
  6.  
  7. export interface IUser {
  8. id: string;
  9. name: string;
  10. email: string;
  11. }
  12.  
  13. export interface IUserState extends EntityState<IUser>{
  14. // additional entities state properties
  15. users: [];
  16. }
  17.  
  18. export const adapter: EntityAdapter<IUser> = createEntityAdapter<IUser>();
  19.  
  20. export const initialState: IUserState = adapter.getInitialState({
  21. users: []
  22. });
  23.  
  24. export function userReducer(
  25. state: IUserState = initialState,
  26. action: UserActions
  27. ): IUserState {
  28. switch (action.type) {
  29. case UpdateUser: {
  30. const updatedUser = {
  31. id: action.payload.id,
  32. changes: { email: action.payload.id }
  33. };
  34. return adapter.updateOne(updatedUser, state);
  35. }
  36. }
  37.  
  38. //export common use selector for your selector
  39. export const {
  40. selectAll,
  41. selectEntities,
  42. selectIds,
  43. selectTotal
  44. } = adapter.getSelectors();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement