forked from RubyLouvre/anu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex5.html
108 lines (102 loc) · 2.53 KB
/
index5.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>测试注释节点</title>
<meta name="viewport" content="width=device-width">
<style>
.aaa {
width: 200px;
height: 200px;
background: red;
}
.bbb {
width: 200px;
height: 200px;
background: lawngreen;
}
</style>
<script src="./dist/React.js"></script>
<!-- <script src="./test/react.js"></script>
<script src="./test/react-dom.js"></script>-->
<script src="./libs/babel.js"></script>
<script type='text/babel'>
var s
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
path: "111"
};
}
change(path) {
this.setState({
path: path || "333"
});
}
render() {
return <div><span>xx</span><Route path={this.state.path} /></div>;
}
}
var updateCount = 0;
var receiveCount = 0;
var destroyCount = 0;
class Route extends React.Component {
constructor(props) {
super(props);
this.state = {
path: props.path
};
}
componentWillReceiveProps(props) {
receiveCount++;
console.log('receiveCount',receiveCount)
this.setState(function(nextState, props) {
nextState.path = props.path;
return nextState;
});
}
componentWillUpdate() {
updateCount++;
console.log('updateCount',updateCount)
}
componentWillUnmount() {
destroyCount++;
console.log("destroyCount",destroyCount)
}
render() {
return this.state.path == "111" ? <p>{this.state.path}</p> : null;
}
}
function expect(a){
return {
toBe: function(b){
console.log(a, b, a === b)
}
}
}
window.onload = function(){
var div = document.getElementById('example')
s = React.render(<App />, div);
expect(updateCount).toBe(0);
expect(receiveCount).toBe(0);
setTimeout(function(){
s.change("111");
setTimeout(function(){
expect(updateCount).toBe(1);
expect(receiveCount).toBe(1);
console.log('---------------')
s.change("111x");
setTimeout(function(){
expect(updateCount).toBe(2);
expect(receiveCount).toBe(2);
},200)
},200)
},200)
}
</script>
</head>
<body>
<div id='example'>ddd</div>
</body>
</html>