Add braces and simplify/improve oldLength handling

This commit is contained in:
Josh Soref 2018-08-07 23:12:50 -04:00 committed by Vivek Pandey
parent f28a06b600
commit b02273dc2a
1 changed files with 4 additions and 3 deletions

View File

@ -75,14 +75,15 @@ export class LogConsole extends Component {
componentWillReceiveProps(nextProps) {
// eslint-disable-line
logger.debug('newProps isArray', Array.isArray(nextProps.logArray));
if (nextProps.logArray === undefined)
if (nextProps.logArray === undefined) {
return;
}
// We need a shallow copy of the ObservableArray to "cast" it down to normal array
const newArray = nextProps.logArray.slice();
const oldArray = this.props.logArray !== undefined && this.props.logArray.slice();
const oldLength = this.props.logArray && this.props.logArray.length || 0;
// if have a new logArray, simply add it to the queue and wait for next tick
this.queuedLines = this.queuedLines.concat(newArray.slice(oldArray.length));
this.queuedLines = this.queuedLines.concat(newArray.slice(oldLength));
clearTimeout(this.timeouts.render);
this.timeouts.render = setTimeout(() => {
this._processNextLines();