import { createEntityAdapter , EntityAdapter , EntityState } from '@ngrx/entity' ; import { Action } from '@ngrx/store' ; import { UpdateUser , UpsertUser , UserActionTypes } from './user.actions' ; import { User } from './user.model' ; export interface State extends EntityState < User > { selectedIds : Array < string > ; } export const adapter = createEntityAdapter < User > ( ) ; export const initialState = adapter . getInitialState ( { selectedIds : [ 'user1' , 'user3' , 'user6' ] , } ) ; export function reducer ( state = initialState , action ) { switch ( action . type ) { case UserActionTypes . UPSERT : return adapter . upsertOne ( ( < UpsertUser > action ) . payload . user , state ) ; case UserActionTypes . UPDATE : return adapter . updateOne ( ( < UpdateUser > action ) . payload . user , state ) ; } return state ; }