Skip to content

Commit 00bc0a1

Browse files
committed
implemented observers and watchers, removed need for recursive call on setState
1 parent cd14951 commit 00bc0a1

File tree

8 files changed

+563
-95
lines changed

8 files changed

+563
-95
lines changed

demo/index.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,23 @@ import ReactV from "../src/ReactV";
22
import React from "react";
33
import ReactDOM from "react-dom"
44

5+
class SubApp extends ReactV.Component {
6+
state = {
7+
times: 2
8+
}
9+
mounted() {
10+
setTimeout(() => {
11+
this.times = 4;
12+
}, 2000)
13+
}
14+
render() {
15+
const {link} = this.props
16+
const { times } = this;
17+
return (
18+
<a>{link} + {times}</a>
19+
)
20+
}
21+
}
522
class App extends ReactV.Component {
623
state = {
724
illuminate: 2,
@@ -12,6 +29,9 @@ class App extends ReactV.Component {
1229
setTimeout(() => {
1330
this.status = "mounted!";
1431
}, 1000);
32+
setTimeout(() => {
33+
this.times = 10;
34+
}, 2000);
1535
}
1636
watch = {
1737
status(val, old){
@@ -22,9 +42,6 @@ class App extends ReactV.Component {
2242
this.status = "troix";
2343
}
2444
},
25-
times() {
26-
console.log("times updated...")
27-
}
2845
}
2946
methods = {
3047
change() {
@@ -43,6 +60,7 @@ class App extends ReactV.Component {
4360
<div>
4461
<h3>{status}</h3>
4562
<p>{illuminate} + {times}</p>
63+
<SubApp link={status} />
4664
<a onClick={() => this.change()}>Click</a>
4765
</div>
4866
)

0 commit comments

Comments
 (0)