mirror of
https://github.com/zebrajr/react.git
synced 2026-01-15 12:15:22 +00:00
Add --harmony option to live JSX compiler page
This commit is contained in:
@@ -455,6 +455,11 @@ section.black content {
|
||||
padding-top: 20px;
|
||||
width: 1220px;
|
||||
|
||||
label.compiler-option {
|
||||
display: block;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
#jsxCompiler {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
@@ -13,15 +13,38 @@ var HelloMessage = React.createClass({\n\
|
||||
React.renderComponent(<HelloMessage name=\"John\" />, mountNode);\
|
||||
";
|
||||
|
||||
var transformer = function(code) {
|
||||
return JSXTransformer.transform(code).code;
|
||||
function transformer(harmony, code) {
|
||||
return JSXTransformer.transform(code, {harmony: harmony}).code;
|
||||
}
|
||||
|
||||
var CompilerPlayground = React.createClass({
|
||||
getInitialState: function() {
|
||||
return {harmony: false};
|
||||
},
|
||||
handleHarmonyChange: function(e) {
|
||||
this.setState({harmony: e.target.checked});
|
||||
},
|
||||
render: function() {
|
||||
return (
|
||||
<div>
|
||||
<ReactPlayground
|
||||
codeText={HELLO_COMPONENT}
|
||||
renderCode={true}
|
||||
transformer={transformer.bind(null, this.state.harmony)}
|
||||
showCompiledJSTab={false}
|
||||
/>
|
||||
<label className="compiler-option">
|
||||
<input
|
||||
type="checkbox"
|
||||
onChange={this.handleHarmonyChange}
|
||||
checked={this.state.harmony} />{' '}
|
||||
Enable ES6 transforms (<code>--harmony</code>)
|
||||
</label>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
});
|
||||
React.renderComponent(
|
||||
<ReactPlayground
|
||||
codeText={HELLO_COMPONENT}
|
||||
renderCode={true}
|
||||
transformer={transformer}
|
||||
showCompiledJSTab={false}
|
||||
/>,
|
||||
<CompilerPlayground />,
|
||||
document.getElementById('jsxCompiler')
|
||||
);
|
||||
|
||||
@@ -173,10 +173,11 @@ var ReactPlayground = React.createClass({
|
||||
this.executeCode();
|
||||
},
|
||||
|
||||
componentWillUpdate: function(nextProps, nextState) {
|
||||
componentDidUpdate: function(prevProps, prevState) {
|
||||
// execute code only when the state's not being updated by switching tab
|
||||
// this avoids re-displaying the error, which comes after a certain delay
|
||||
if (this.state.code !== nextState.code) {
|
||||
if (this.props.transformer !== prevProps.transformer ||
|
||||
this.state.code !== prevState.code) {
|
||||
this.executeCode();
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user