/* @flow */ import React, { Component } from 'react'; import {observable} from 'mobx'; import {observer} from 'mobx-react'; import CodeMirror from './CodeMirror'; import FakeConsole from './FakeConsole'; import Compiler from '../Compiler'; type Props = { inline?: boolean; inputTitle?: *; outputTitle?: *; hideOutput?: boolean; code: string; }; @observer export default class Example extends Component { @observable compiler: Compiler; handleChange = (code: string) => { this.compiler.updateCode(code); }; runCode = () => { this.compiler.run(); }; constructor (props: Props) { super(props); this.compiler = new Compiler(props.code); } render () { const compiler = this.compiler; const {inputTitle, outputTitle, inline, hideOutput} = this.props; const className = compiler.error ? 'syntax-error' : 'no-error'; const input = (
{inputTitle}
); const output = (
{outputTitle}
); if (inline) { return (
{input}
{!hideOutput && output} {hideOutput && ( )} {hideOutput &&
}
); } return (
{input}
{output}

); } }