shop.js 546 B

123456789101112131415161718192021
  1. /**
  2. * Mocking client-server processing
  3. */
  4. const _products = [
  5. {"id": 1, "title": "iPad 4 Mini", "price": 500.01, "inventory": 2},
  6. {"id": 2, "title": "H&M T-Shirt White", "price": 10.99, "inventory": 10},
  7. {"id": 3, "title": "Charli XCX - Sucker CD", "price": 19.99, "inventory": 5}
  8. ]
  9. export default {
  10. getProducts (cb) {
  11. setTimeout(() => cb(_products), 100)
  12. },
  13. buyProducts (products, cb, errorCb) {
  14. setTimeout(() => {
  15. // simulate random checkout failure.
  16. Math.random() > 0.5 ? cb() : errorCb()
  17. }, 100)
  18. }
  19. }