Advertisement
Guest User

Untitled

a guest
Jun 26th, 2018
80
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(item: any): any {
  13.         const { _id, _variant } = item
  14.         const index = this.items.findIndex(x => (x.variant.id === _id && x.variant._variant === _variant))
  15.  
  16.         if (index) {
  17.             this.items[index] = item
  18.         } else {
  19.             this.items.push(item)
  20.         }
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement