-
Notifications
You must be signed in to change notification settings - Fork 0
/
Store.js
84 lines (75 loc) · 1.55 KB
/
Store.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import React from "react";
const State = {
info: "Hello.Welcome to eshop ",
id: 0
};
const listeners = new Set();
function updateComponents() {
for (const cb of listeners.values()) {
cb();
}
}
export function infoProduct(id) {
let infos = [
{ info: "Milwakee Bucks", id: 1 },
{
info: "Cleveland Cavaliers",
id: 2
},
{ info: "Philadelphia Sixers", id: 3 },
{ info: "Toronto Raptors", id: 4 },
{ info: "Huston Rockets", id: 5 }
];
if (id === 1) {
console.log(id);
State.info = infos[0].info;
State.id = infos[0].id;
updateComponents();
}
if (id === 2) {
console.log(id);
State.info = infos[1].info;
State.id = infos[1].id;
updateComponents();
}
if (id === 3) {
console.log(id);
State.info = infos[2].info;
State.id = infos[2].id;
updateComponents();
}
if (id === 4) {
console.log(id);
State.info = infos[3].info;
State.id = infos[3].id;
updateComponents();
}
if (id === 5) {
console.log(id);
State.info = infos[4].info;
State.id = infos[4].id;
updateComponents();
}
}
export function connect(Component) {
return class Wrapper extends React.Component {
state = {
info: State.info,
id: State.id
};
_listener = () => {
this.setState({
info: State.info,
id: State.id
});
};
componentDidMount() {
listeners.add(this._listener);
}
render() {
return (
<Component {...this.props} info={this.state.info} id={this.state.id} />
);
}
};
}