import React, { PropTypes } from 'react'; import InlineSVG from 'react-inlinesvg'; const upArrowUrl = require('../../../images/up-arrow.svg'); const downArrowUrl = require('../../../images/down-arrow.svg'); import classNames from 'classnames'; /** * How many console messages to store * @type {Number} */ const consoleMax = 200; class Console extends React.Component { constructor(props) { super(props); /** * An array of React Elements that include previous console messages * @type {Array} */ this.children = []; this.appendConsoleEvent = this.appendConsoleEvent.bind(this); } componentWillReceiveProps(nextProps) { if (nextProps.isPlaying && !this.props.isPlaying) { this.children = []; } else if (nextProps.consoleEvent !== this.props.consoleEvent && this.props.isPlaying) { nextProps.consoleEvent.forEach(consoleEvent => { if (consoleEvent.source === 'sketch') { const args = consoleEvent.arguments; Object.keys(args).forEach((key) => { if (args[key].includes('Exiting potential infinite loop')) { this.props.stopSketch(); this.props.expandConsole(); this.appendConsoleEvent(consoleEvent); } }); this.appendConsoleEvent(consoleEvent); } }); } } shouldComponentUpdate(nextProps) { return (nextProps.consoleEvent !== this.props.consoleEvent) || (nextProps.isPlaying && !this.props.isPlaying) || (this.props.isExpanded !== nextProps.isExpanded); } componentDidUpdate() { this.refs.console_messages.scrollTop = this.refs.console_messages.scrollHeight; } appendConsoleEvent(consoleEvent) { const args = consoleEvent.arguments; const method = consoleEvent.method; let nextChild; if (Object.keys(args).length === 0) { nextChild = (