Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 661bafb

Browse files
sophiebitschenglou
authored andcommitted
Add --harmony option to live JSX compiler page
(cherry picked from commit ba67bf1)
1 parent 8f0c1ce commit 661bafb

File tree

3 files changed

+39
-10
lines changed

3 files changed

+39
-10
lines changed

docs/_css/react.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,11 @@ section.black content {
454454
padding-top: 20px;
455455
width: 1220px;
456456

457+
label.compiler-option {
458+
display: block;
459+
margin-top: 5px;
460+
}
461+
457462
#jsxCompiler {
458463
margin-top: 20px;
459464
}

docs/_js/jsx-compiler.js

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,38 @@ var HelloMessage = React.createClass({\n\
1313
React.renderComponent(<HelloMessage name=\"John\" />, mountNode);\
1414
";
1515

16-
var transformer = function(code) {
17-
return JSXTransformer.transform(code).code;
16+
function transformer(harmony, code) {
17+
return JSXTransformer.transform(code, {harmony: harmony}).code;
1818
}
19+
20+
var CompilerPlayground = React.createClass({
21+
getInitialState: function() {
22+
return {harmony: false};
23+
},
24+
handleHarmonyChange: function(e) {
25+
this.setState({harmony: e.target.checked});
26+
},
27+
render: function() {
28+
return (
29+
<div>
30+
<ReactPlayground
31+
codeText={HELLO_COMPONENT}
32+
renderCode={true}
33+
transformer={transformer.bind(null, this.state.harmony)}
34+
showCompiledJSTab={false}
35+
/>
36+
<label className="compiler-option">
37+
<input
38+
type="checkbox"
39+
onChange={this.handleHarmonyChange}
40+
checked={this.state.harmony} />{' '}
41+
Enable ES6 transforms (<code>--harmony</code>)
42+
</label>
43+
</div>
44+
);
45+
},
46+
});
1947
React.renderComponent(
20-
<ReactPlayground
21-
codeText={HELLO_COMPONENT}
22-
renderCode={true}
23-
transformer={transformer}
24-
showCompiledJSTab={false}
25-
/>,
48+
<CompilerPlayground />,
2649
document.getElementById('jsxCompiler')
2750
);

docs/_js/live_editor.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,11 @@ var ReactPlayground = React.createClass({
173173
this.executeCode();
174174
},
175175

176-
componentWillUpdate: function(nextProps, nextState) {
176+
componentDidUpdate: function(prevProps, prevState) {
177177
// execute code only when the state's not being updated by switching tab
178178
// this avoids re-displaying the error, which comes after a certain delay
179-
if (this.state.code !== nextState.code) {
179+
if (this.props.transformer !== prevProps.transformer ||
180+
this.state.code !== prevState.code) {
180181
this.executeCode();
181182
}
182183
},

0 commit comments

Comments
 (0)