var React = require('react'); var reactUtil = require('../util/reactUtil'); var keyMirror = require('react/lib/keyMirror'); var STATUSES = keyMirror({ inqueue: null, processing: null, finished: null }); var CommandView = React.createClass({ propTypes: { // the backbone command model command: React.PropTypes.object.isRequired }, componentDidMount: function() { this.props.command.on('change', this.updateStateFromModel, this); this.props.command.on('destroy', this.onModelDestroy, this); this.updateStateFromModel(); }, componentWillUnmount: function() { this.props.command.off('change', this.updateStateFromModel, this); this.props.command.off('destroy', this.onModelDestroy, this); }, onModelDestroy: function() { React.unmountComponentAtNode(this.getDOMNode().parentNode); }, updateStateFromModel: function() { var commandJSON = this.props.command.toJSON(); this.setState({ status: commandJSON.status, rawStr: commandJSON.rawStr, warnings: commandJSON.warnings, result: commandJSON.result }); }, getInitialState: function() { return { status: STATUSES.inqueue, rawStr: 'git commit', warnings: [], result: '' }; }, render: function() { var commandClass = reactUtil.joinClasses([ this.state.status, 'commandLine', 'transitionBackground' ]); return (

{'$'} {' ' + this.state.rawStr}

{this.renderResult()}
{this.renderFormattedWarnings()}
); }, renderResult: function() { if (!this.state.result) { return null; } // We are going to get a ton of raw markup here // so lets split into paragraphs ourselves var paragraphs = this.state.result.split("\n"); var result = []; for (var i = 0; i < paragraphs.length; i++) { result.push(

); } return (

{result}
); }, renderFormattedWarnings: function() { var warnings = this.state.warnings; var result = []; for (var i = 0; i < warnings.length; i++) { result.push(

{warnings[i]}

); } return result; } }); module.exports = CommandView;