Advertisement
Guest User

Untitled

a guest
Jun 26th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. export class ItemsFactory {
  2.   items: any[];
  3.  
  4.   constructor() {
  5.     this.items = [];
  6.   }
  7.  
  8.   public getCount() {
  9.     return this.items.length;
  10.   }
  11.  
  12.   public pushOrUpdate(
  13.     variant: number,
  14.     id: number,
  15.     order: number,
  16.     items: any[]
  17.   ): any {
  18.     const itemIdx = this.items.findIndex(x => x.variant.id === id);
  19.  
  20.     if (itemIdx) {
  21.       this.items[itemIdx].items = items;
  22.     } else {
  23.       this.items.push({
  24.         variant: {
  25.           id,
  26.           variant,
  27.           order,
  28.           items
  29.         }
  30.       });
  31.     }
  32.   }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement