From fe48b40ce7109689f2e2ed60d84bfcc06f54df5d Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Fri, 9 Sep 2016 19:51:24 -0700 Subject: [PATCH] Raw textarea now async --- app/components/viewers/ResponseRaw.js | 50 ++++++++++++++++++++++++ app/components/viewers/ResponseViewer.js | 9 +++-- 2 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 app/components/viewers/ResponseRaw.js diff --git a/app/components/viewers/ResponseRaw.js b/app/components/viewers/ResponseRaw.js new file mode 100644 index 0000000000..73ca43408a --- /dev/null +++ b/app/components/viewers/ResponseRaw.js @@ -0,0 +1,50 @@ +import React, {Component, PropTypes} from 'react'; + +class ResponseRaw extends Component { + _update (value) { + setTimeout(() => { + this._textarea.value = value; + }, 50) + } + + componentDidUpdate () { + this._update(this.props.value) + } + + componentDidMount () { + this._update(this.props.value) + } + + 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 ( + + ); + } +} + +ResponseRaw.propTypes = { + value: PropTypes.string.isRequired, + fontSize: PropTypes.number +}; + +export default ResponseRaw; diff --git a/app/components/viewers/ResponseViewer.js b/app/components/viewers/ResponseViewer.js index 15cb92732e..cf359a289d 100644 --- a/app/components/viewers/ResponseViewer.js +++ b/app/components/viewers/ResponseViewer.js @@ -1,6 +1,7 @@ import React, {Component, PropTypes} from 'react'; import Editor from '../base/Editor'; import ResponseWebview from './ResponseWebview'; +import ResponseRaw from './ResponseRaw'; import ResponseError from './ResponseError'; import { PREVIEW_MODE_FRIENDLY, @@ -62,10 +63,10 @@ class ResponseViewer extends Component { ); default: // Raw return ( - + ) } }