-
Notifications
You must be signed in to change notification settings - Fork 2
/
Likes.js
50 lines (39 loc) · 1.24 KB
/
Likes.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
export default class Likes {
constructor() {
/** Array Version */
// this.likes = [];
/** Map Version */
this.likes = new Map();
}
addLikedItem(id, title, author, img) {
/** Array Version */
// const likedItem = { id, title, author, img };
// this.likes.push(likedItem);
// return likedItem;
/** Map Version */
this.likes.set(id, { title, author, img });
return { id, value: this.likes.get(id) };
}
deleteLikedItem(id) {
/** Array Version */
// const index = this.likes.findIndex(el => el.id === id);
// this.likes.splice(index, 1);
/** Map Version */
if (this.likes.has(id))
this.likes.delete(id);
}
// When we load a particular recipe, we have to know whether that recipe has been liked previously
// or not, so we can style the recipe accordingly on to the front-end view.
isLikedItem(id) {
/** Array Version */
// return this.likes.findIndex(el => el.id === id) !== -1;
/** Map Version */
return this.likes.has(id);
}
getNumberOfLikedItems() {
/**Array Version */
// return this.likes.length;
/** Map Version */
return this.likes.size;
}
}