-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreactMixin.js
58 lines (33 loc) · 1.04 KB
/
reactMixin.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
48
49
50
51
52
53
54
55
56
57
58
// 2020.7/10, am 10:50 - 11:15
// mixin can make Component cobined with role or behavior using object not class.
// reuse code without create component | class
var React = require("react");
var KatesPou = {
// setInterval(() => {}, interval);
setInterval: function(cb, interval){
var token = setInterval(cb, interval);
this._interval.push(token); // cant be accessible by user
return token; // token: number
},
componentDidMount: function(){
this._interval = [];
},
componentWillUnmount: function(){
this._interval.map(clearInterval);
}
}
var PoupousTimer = React.createClass({
mixin:[KatesPou],
componentDidMount: function(){
// handler: TimerHandler, timeout, arg
this.setInterval(this.forceUpdate.bind(this), 1000);
},
render: function(){
var from = Number(new Date(2018, 12, 22));
var to = Date.now();
return (
<div> {(Math.round(to - from))} </div>
);
}
});
export default PoupousTimer;