Skip to content

Commit 3deb95a

Browse files
committed
Refactor console.js
1 parent 5dc93c0 commit 3deb95a

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,38 @@
1-
import React from 'react'
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
24

35
class Console extends React.Component {
4-
componentDidUpdate(prevProps, prevState) {
5-
console.log("Console did update", this.props.instanceId, this.props.logs.toArray());
6-
if (this.props.instanceId) {
7-
this.timer = setTimeout(this.props.queryBuildLogs.bind(this, this.props.instanceId), 3000);
8-
}
6+
static propTypes = {
7+
instanceId: PropTypes.string.isRequired,
8+
logs: PropTypes.arrayOf(PropTypes.any).isRequired,
9+
queryBuildLogs: PropTypes.func.isRequired,
910
}
10-
11-
shouldComponentUpdate(nextProps, nextState) {
11+
shouldComponentUpdate(nextProps) {
1212
if (this.props.instanceId === nextProps.instanceId && this.props.logs === nextProps.logs) {
1313
return false;
1414
}
1515
return true;
1616
}
17+
componentDidUpdate() {
18+
console.log('Console did update', this.props.instanceId, this.props.logs.toArray());
19+
if (this.props.instanceId) {
20+
this.timer = setTimeout(this.props.queryBuildLogs.bind(this, this.props.instanceId), 3000);
21+
}
22+
}
1723

1824
render() {
19-
var logs = this.props.logs.toArray().reverse().map((log, id) => {
25+
const logs = this.props.logs.toArray().reverse().map((log) => {
2026
log = {
21-
__html: log.replace(/\n/g, "<br>")
27+
__html: log.replace(/\n/g, '<br>'),
2228
};
23-
return (<div key={ id } dangerouslySetInnerHTML={ log }>
24-
</div>)
25-
})
29+
return <div key={log} dangerouslySetInnerHTML={log} />;
30+
});
2631
return (
2732
<div className="realworld-build-console">
2833
{ logs }
29-
</div>)
34+
</div>);
3035
}
3136
}
3237

33-
34-
export default Console
38+
export default Console;

0 commit comments

Comments
 (0)