Skip to content

Instantly share code, notes, and snippets.

@ngohungphuc
Created August 2, 2019 08:45
Show Gist options
  • Select an option

  • Save ngohungphuc/6d2ebdff08ef7eda42c2faa598c67039 to your computer and use it in GitHub Desktop.

Select an option

Save ngohungphuc/6d2ebdff08ef7eda42c2faa598c67039 to your computer and use it in GitHub Desktop.
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