forked from preactjs/preact
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathold.js.bak
103 lines (88 loc) · 2.16 KB
/
old.js.bak
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
// function createRoot(title) {
// let div = document.createElement('div');
// let h2 = document.createElement('h2');
// h2.textContent = title;
// div.appendChild(h2);
// document.body.appendChild(div);
// return div;
// }
/*
function logCall(obj, method, name) {
let old = obj[method];
obj[method] = function(...args) {
console.log(`<${this.localName}>.`+(name || `${method}(${args})`));
return old.apply(this, args);
};
}
logCall(HTMLElement.prototype, 'appendChild');
logCall(HTMLElement.prototype, 'removeChild');
logCall(HTMLElement.prototype, 'insertBefore');
logCall(HTMLElement.prototype, 'replaceChild');
logCall(HTMLElement.prototype, 'setAttribute');
logCall(HTMLElement.prototype, 'removeAttribute');
let d = Object.getOwnPropertyDescriptor(Node.prototype, 'nodeValue');
Object.defineProperty(Text.prototype, 'nodeValue', {
get() {
let value = d.get.call(this);
console.log('get Text#nodeValue: ', value);
return value;
},
set(v) {
console.log('set Text#nodeValue', v);
return d.set.call(this, v);
}
});
render((
<div>
<h4>This is a test.</h4>
<Foo />
<time>...</time>
</div>
), createRoot('Stateful component update demo:'));
class Foo extends Component {
componentDidMount() {
console.log('mounted');
this.timer = setInterval( () => {
this.setState({ time: Date.now() });
}, 5000);
}
componentWillUnmount() {
clearInterval(this.timer);
}
render(props, state, context) {
// console.log('rendering', props, state, context);
return <time>test: {state.time}</time>
}
}
render((
<div>
<h4>This is a test.</h4>
<Foo />
<time>...</time>
</div>
), createRoot('Stateful component update demo:'));
let items = [];
let count = 0;
let three = createRoot('Top-level render demo:');
setInterval( () => {
if (count++ %20 < 10 ) {
items.push(<li key={count} style={{
position: 'relative',
transition: 'all 200ms ease',
paddingLeft: items.length*20 +'px'
}}>item #{items.length}</li>);
}
else {
items.shift();
}
render((
<div>
<h4>This is a test.</h4>
<time>{Date.now()}</time>
<ul>{items}</ul>
</div>
), three);
}, 5000);
// Mount the top-level component to the DOM:
render(<Main />, document.body);
*/