Advertisement
Guest User

Untitled

a guest
Aug 14th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. checkItem(state, item) {
  2.       if (state.cart.length === 0) {
  3.         state.cart.push(item)
  4.         return
  5.       }
  6.  
  7.       // Check if in the array the item exist
  8.       // If it exist, foundItem === Object
  9.       // Else, foundItem === undefined
  10.       const foundItem = state.cart.find(c => c.id == item.id)
  11.      
  12.       // So if it found something
  13.       // Print in the console
  14.       // And return
  15.       if(foundItem) {
  16.         console.error('Item already found')
  17.         return
  18.       }
  19.       // If it found nothing
  20.       // Add it to the array
  21.       state.cart.push(item)
  22.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement