This repository has been archived by the owner on Apr 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
/
script.js
57 lines (52 loc) · 1.76 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// start with an IIFE to keep the global namespace clean
(function(){
class ShopController {
constructor(productList) {
this.productList = productList;
this.UITemplate = document.querySelector(".js-product");
this.ProductListElement = document.querySelector(".js-product-list");
// we stored the template in a variable
// so now we can remove it from the live DOM
this.UITemplate.remove();
// initialize products
for (let product of this.productList) {
this._initProduct(product);
}
// initialize cart
this.cartContainer = document.querySelector(".js-cart");
this.cartUI = new CartView(this.cartContainer);
this.cart = new CartModel();
}
_initProduct(productData) {
const newProduct = new ProductModel(productData);
const productInfo = newProduct.getInfo();
const newProductUI = new ProductView(
this.UITemplate,
this.ProductListElement
);
newProductUI.setUp(productInfo);
}
}
// this would most likely come from some database through an API of sorts,
// but for now, we have all our products in this list:
const productList = [
{
name: "DisCatcher Target",
category: " Discgolf",
description:
"a chain grid that catches fast and slow putts, heavy and light discs like no other target",
imageSrc: "images/discatcher.jpg",
price: 399,
},
{
name: "Hero SuperAero",
category: " Discgolf",
description:
"a disc that floats like a butterfly, holds up like a SuperHero",
imageSrc: "images/dog.jpg",
price: 14,
},
];
// launch shop initialization by creating a new ShopController instance
const berryShop = new ShopController(productList);
})();