-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfavoriteColors.html
More file actions
60 lines (51 loc) · 1.23 KB
/
favoriteColors.html
File metadata and controls
60 lines (51 loc) · 1.23 KB
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="https://unpkg.com/redux@latest/dist/redux.js"></script>
<title>Вибрані кольори</title>
</head>
<body>
<script>
function addColor(value) {
return {
type: "ADD",
color: value
}
}
function removeColor(value) {
return {
type: "REMOVE",
color: value
};
}
function favoriteColors(state, action) {
if (state === undefined) {
state = [];
}
if (action.type == "ADD") {
return state.concat(action.color);
} else if (action.type == "REMOVE") {
return state.filter(function(item) {
return item !== action.color;
});
} else {
return state;
}
}
var store = Redux.createStore(favoriteColors);
store.subscribe(render);
function render() {
console.log(store.getState());
}
store.dispatch(addColor("blue"));
store.dispatch(addColor("yellow"));
store.dispatch(addColor("green"));
store.dispatch(addColor("red"));
store.dispatch(addColor("gray"));
store.dispatch(addColor("orange"));
store.dispatch(removeColor("gray"));
console.log(store.getState);
</script>
</body>
</html>