Skip to content

Commit 798171a

Browse files
committed
code updates work like a charm
1 parent b4aefb7 commit 798171a

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

docs/client/components/PlaygroundPage/PlaygroundWithPreview/Playground.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,25 @@ class Playground extends React.Component {
2323
theme: 'custom',
2424
readOnly: false,
2525
});
26+
this.editor.on('change', this.handleChange);
2627
}
28+
29+
componentDidUpdate(prevProps) {
30+
if (this.props.code !== prevProps.code) {
31+
this.editor.setValue(this.props.code);
32+
}
33+
}
34+
35+
setCode = (code) => {
36+
this.editor.getDoc().setValue(code);
37+
this.handleChange();
38+
}
39+
40+
handleChange = () => {
41+
console.log('changed ', this.editor.getValue());
42+
this.props.onChange(this.editor.getValue());
43+
};
44+
2745

2846
render() {
2947
return (

docs/client/components/PlaygroundPage/PlaygroundWithPreview/Preview.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,6 @@ class Preview extends React.Component {
8080
</div>
8181
);
8282
}
83-
84-
// render() {
85-
// return (
86-
// <div className={styles.preview}>
87-
// <div className="header">
88-
// Preview
89-
// </div>
90-
// {code}
91-
// </div>
92-
// );
93-
// }
9483
}
9584

9685
Preview.propTypes = {

docs/client/components/PlaygroundPage/PlaygroundWithPreview/index.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,15 @@ const defaultCode = `
1919
class PlaygroundWithPreview extends React.Component {
2020
constructor(props) {
2121
super(props);
22-
this.state = {};
22+
this.state = {
23+
code: defaultCode,
24+
};
25+
}
26+
27+
handleOnChangeCode = (code) => {
28+
this.setState({
29+
code,
30+
});
2331
}
2432

2533
render() {
@@ -32,13 +40,13 @@ class PlaygroundWithPreview extends React.Component {
3240
<div className="header">
3341
PlaygroundWithPreview
3442
</div>
35-
3643
<div>
3744
<Playground
3845
code={defaultCode}
46+
onChange={this.handleOnChangeCode}
3947
/>
4048
<Preview
41-
code={defaultCode}
49+
code={this.state.code}
4250
/>
4351
</div>
4452
{activeComponent}

0 commit comments

Comments
 (0)