Skip to content

Commit 5ac123b

Browse files
committed
Merge remote-tracking branch 'itenium/master'
2 parents 8d93d75 + 376033c commit 5ac123b

File tree

2 files changed

+74
-59
lines changed

2 files changed

+74
-59
lines changed

Diff for: cli-socks/src/components/Product.vue

+15-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
<i v-for="i in averageReviewScore" class="fa fa-star" :key="i"></i>
1212
</h1>
1313

14+
<div v-if="product.reviews.length">All reviews:</div>
15+
<div v-for="j in product.reviews" :key="j.name+j.rating">
16+
<label>{{ j.name}}: </label>
17+
<i v-for="k in j.rating" class="fa fa-star" :key="k"></i>
18+
</div>
19+
1420
<div>
1521
<p v-if="selectedVariant.inventory > 10">In Stock</p>
1622
<p v-else-if="selectedVariant.inventory">Almost sold out</p>
@@ -58,9 +64,10 @@ import ProductReview from './ProductReview.vue';
5864
ProductReview
5965
}
6066
})
67+
6168
export default class Product extends Vue {
6269
@Prop({default: false}) private premium!: boolean;
63-
@Prop() private cartLength: number;
70+
@Prop() private cartLength!: number;
6471
6572
product = {
6673
name: "Vue Socks",
@@ -84,7 +91,12 @@ export default class Product extends Vue {
8491
if (!this.product.reviews.length) {
8592
return null;
8693
}
87-
return Math.round(this.product.reviews.reduce((a, c) => a + c, 0) / this.product.reviews.length);
94+
const reviews = this.product.reviews as any;
95+
const totalStars = reviews
96+
.map((x: any) => x.rating)
97+
.reduce((a: any, c: any) => a + c, 0);
98+
99+
return Math.round(totalStars / this.product.reviews.length);
88100
}
89101
90102
get title() {
@@ -104,7 +116,7 @@ export default class Product extends Vue {
104116
105117
addReview(review: any) {
106118
const reviews = this.product.reviews as any;
107-
reviews.push(review.rating);
119+
reviews.push(review);
108120
}
109121
}
110122
</script>

Diff for: cli-socks/src/store.ts

+59-56
Original file line numberDiff line numberDiff line change
@@ -3,84 +3,87 @@ import Vuex from "vuex";
33

44
Vue.use(Vuex);
55

6-
// Exercise 5? Kill the counter store and use the products store below!
6+
7+
const productList = [{
8+
name: "Vue Socks",
9+
brand: "Vue",
10+
price: 5,
11+
variants: [
12+
{id: 1, color: "green"},
13+
{id: 2, color: "blue"}
14+
],
15+
inventory: 3,
16+
reviews: []
17+
},
18+
{
19+
name: "Angular Socks",
20+
brand: "angular",
21+
price: 15,
22+
variants: [
23+
{id: 1, color: "red"},
24+
{id: 2, color: "blue"}
25+
],
26+
inventory: 3,
27+
reviews: []
28+
},
29+
{
30+
name: "npm Socks",
31+
brand: "npm",
32+
price: 3,
33+
variants: [
34+
{id: 1, color: "red"},
35+
],
36+
inventory: 3,
37+
reviews: []
38+
}];
39+
740

841
export default new Vuex.Store({
9-
// ~ component.data
1042
state: {
11-
count: 0
43+
premium: true,
44+
cart: [],
45+
products: productList
1246
},
1347

14-
// ~ component.methods
15-
actions: {},
48+
actions: {
1649

17-
// ~ component.computed
50+
},
1851
getters: {
19-
countAlias(state) {
20-
return state.count;
21-
}
52+
2253
},
2354

24-
// ~ redux.reducers
2555
mutations: {
26-
increment(state) {
27-
state.count++;
28-
},
29-
decrement(state) {
30-
state.count--;
56+
addToCart(state, product) {
57+
const cart = state.cart as any;
58+
cart.push(product);
3159
}
3260
},
3361
});
3462

3563

36-
// const productList = [{
37-
// name: "Vue Socks",
38-
// brand: "Vue",
39-
// price: 5,
40-
// variants: [
41-
// {id: 1, color: "green"},
42-
// {id: 2, color: "blue"}
43-
// ],
44-
// inventory: 3,
45-
// reviews: []
46-
// },
47-
// {
48-
// name: "Angular Socks",
49-
// brand: "angular",
50-
// price: 15,
51-
// variants: [
52-
// {id: 1, color: "red"},
53-
// {id: 2, color: "blue"}
54-
// ],
55-
// inventory: 3,
56-
// reviews: []
57-
// },
58-
// {
59-
// name: "npm Socks",
60-
// brand: "npm",
61-
// price: 3,
62-
// variants: [
63-
// {id: 1, color: "red"},
64-
// ],
65-
// inventory: 3,
66-
// reviews: []
67-
// }];
68-
69-
7064
// export default new Vuex.Store({
65+
// // ~ component.data
7166
// state: {
72-
// premium: true,
73-
// cart: [],
74-
// products: productList
67+
// count: 0
7568
// },
7669

70+
// // ~ component.methods
7771
// actions: {},
78-
// getters: {},
7972

73+
// // ~ component.computed
74+
// getters: {
75+
// countAlias(state) {
76+
// return state.count;
77+
// }
78+
// },
79+
80+
// // ~ redux.reducers
8081
// mutations: {
81-
// addToCart(state, product) {
82-
// const cart = state.cart as any;
83-
// cart.push(product);
82+
// increment(state) {
83+
// state.count++;
84+
// },
85+
// decrement(state) {
86+
// state.count--;
8487
// }
8588
// },
8689
// });

0 commit comments

Comments
 (0)