-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (35 loc) · 936 Bytes
/
index.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
import { createStore } from "redux";
//const contador = document.getElementById("contador");
const decrementar = document.getElementById("decrementar");
const incrementar = document.getElementById("incrementar");
const INITIAL_STATE = {
counter: 0
};
function counterApp(state = INITIAL_STATE, action) {
console.log(state, action);
switch (action.type){
case 'INCREMENT':
return {
counter: state.counter + 1
}
case 'DECREMENT':
return {
counter: state.counter - 1
}
default:
return state
}
return state;
}
const store = createStore(counterApp);
store.subscribe(()=>{
const state = store.getState()
//console.log('state changed', state)
contador.innerText = state.counter
})
incrementar.addEventListener("click", () => {
store.dispatch({ type: "INCREMENT" });
});
decrementar.addEventListener("click", () => {
store.dispatch({ type: "DECREMENT" });
});