-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
47 lines (41 loc) · 886 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
42
43
44
45
46
47
const redux=require('redux');
// console.log(redux)
//state
const initialState = {
num:0
}
//reducer
const rootReducer=(state=initialState, action)=>{
if(action.type=='INCREMENT'){
return{
...state,
num:state.num+10
}
}
if(action.type=='ADD'){
return{
...state,
num:state.num+action.value
}
}
return state
}
//store
const store=redux.createStore(rootReducer);
//Before dispatch output |manaullay get the state update infromation
console.log(store.getState());
console.log(store)
//subscription
store.subscribe(()=>{
console.log("[subscribe]",store.getState());
})
//dispatch action
store.dispatch({
type:'INCREMENT'
})
store.dispatch({
type:'ADD',
value:34
})
//After dispatch output||manaullay get the state update infromation
// console.log(store.getState());