import React, { PropTypes } from 'react'; const consoleMax = 5; class Console extends React.Component { constructor(props) { super(props); this.children = []; } shouldComponentUpdate(nextProps) { // clear children if paused, but only update when new consoleEvent happens if (!nextProps.isPlaying) { this.children = []; } return nextProps.consoleEvent !== this.props.consoleEvent; } render() { const args = this.props.consoleEvent.arguments; const method = this.props.consoleEvent.method; const nextChild = (
{Object.keys(args).map((key) => {args[key]})}
); this.children.push(nextChild); if (this.children.length > consoleMax) { this.children = this.children.slice(0, 1); } return (
{this.children}
); } } Console.propTypes = { consoleEvent: PropTypes.object, isPlaying: PropTypes.bool.isRequired }; export default Console;