-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
60 lines (53 loc) · 1.37 KB
/
index.html
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 lang="en">
<head>
<meta charset="UTF-8" />
<title>Title</title>
</head>
<body>
<script type="module">
import { createStore, combineReducers } from "./redux/index.js";
import counterReducer from "./reducers/counter.js";
import infoReducer from "./reducers/info.js";
const reducer = combineReducers({
counter: counterReducer,
info: infoReducer,
});
let initState = {
counter:{
count: 0,
},
info: {
name: "初始名字",
description: "",
},
};
//创建store,传入reducer
const store = createStore(reducer, initState);
//订阅,状态改变通知订阅者,把订阅者的方法存入到监听队列中
store.subscribe(() => {
const state = store.getState();
console.log(state.counter.count);
});
store.subscribe(() => {
const state = store.getState();
console.log(state.info.name + state.info.description);
});
//通过派发改变状态
store.dispatch({
type: "INCREMENT",
});
store.dispatch({
type: "SET_NAME",
name:'前端爱我'
});
/*输出
1
初始名字
1
前端爱我
*/
//下一步:使用reducer里的初始状态
</script>
</body>
</html>