NetanelBasal
6/10/2018 - 2:48 PM

cart.model.ts

export type CartItem = {
  productId: Product['id'];
  quantity: number;
  total: number;
};

export function createCartItem(params: Partial<CartItem>) {
  return {
    total: 0,
    quantity: 1,
    ...params
  } as CartItem;
}
@Injectable({
  providedIn: 'root'
})
export class CartQuery extends QueryEntity<State, CartItem> {
  constructor(protected store: CartStore) {
    super(store);
  }
}
export interface State extends EntityState<CartItem> {}

@Injectable({
  providedIn: 'root'
})
export class CartStore extends EntityStore<State, CartItem> {
  constructor() {
    super({}, { idKey: 'productId' });
  }
}