shop.js 593 B

1234567891011121314151617181920212223
  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 || navigator.webdriver)
  17. ? cb()
  18. : errorCb()
  19. }, 100)
  20. }
  21. }