insomnia/app/ui/components/viewers/response-raw.js

65 lines
1.3 KiB
JavaScript
Raw Normal View History

import React, {PureComponent, PropTypes} from 'react';
import autobind from 'autobind-decorator';
2016-09-10 02:51:24 +00:00
@autobind
class ResponseRaw extends PureComponent {
constructor (props) {
super(props);
this._timeout = null;
}
_setTextAreaRef (n) {
this._textarea = n;
}
_update (value) {
clearTimeout(this._timeout);
this._timeout = setTimeout(() => {
if (this._textarea) {
this._textarea.value = value;
}
}, 200);
2016-09-10 02:51:24 +00:00
}
componentDidUpdate () {
this._update(this.props.value);
2016-09-10 02:51:24 +00:00
}
componentDidMount () {
this._update(this.props.value);
2016-09-10 02:51:24 +00:00
}
shouldComponentUpdate (nextProps) {
for (let key in nextProps) {
if (nextProps.hasOwnProperty(key)) {
if (nextProps[key] !== this.props[key]) {
return true;
}
}
}
return false;
}
render () {
const {fontSize} = this.props;
return (
<textarea
ref={this._setTextAreaRef}
2016-09-10 02:51:24 +00:00
placeholder="..."
className="force-wrap scrollable wide tall selectable monospace pad no-resize"
readOnly
2016-09-10 02:51:24 +00:00
defaultValue=""
style={{fontSize}}>
</textarea>
);
}
}
ResponseRaw.propTypes = {
value: PropTypes.string.isRequired,
fontSize: PropTypes.number
};
export default ResponseRaw;