Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs better error display for live editor and JSX compiler #779

Merged
merged 1 commit into from
Jan 2, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 13 additions & 2 deletions docs/_css/react.scss
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,12 @@ section.black content {
@include code-typography;
}
}

.playgroundError {
// The compiler view kills padding in order to render the CodeMirror code
// more nicely. For the error view, put a padding back
padding: 15px 20px;
}
}

/* Button */
Expand Down Expand Up @@ -560,7 +566,7 @@ figure {
margin-top: 60px;
}

/* Code Mirror */
/* CodeMirror */

div.CodeMirror pre, div.CodeMirror-linenumber, code {
@include code-typography;
Expand Down Expand Up @@ -622,6 +628,11 @@ p code {
width: $columnWidth;
}

.playgroundError {
color: darken($primary, 5%);
font-size: 15px;
}

.MarkdownEditor textarea {
width: 100%;
height: 100px
Expand All @@ -636,7 +647,7 @@ p code {
padding-left: 9px;
}

/* Codemirror doesn't support <jsx> syntax. Instead of highlighting it
/* CodeMirror doesn't support <jsx> syntax. Instead of highlighting it
as error, just ignore it */
.highlight .javascript .err {
background-color: transparent;
Expand Down
24 changes: 19 additions & 5 deletions docs/_js/live_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,20 @@ var CodeMirrorEditor = React.createClass({
}
});

var selfCleaningTimeout = {
componentDidUpdate: function() {
clearTimeout(this.timeoutID);
},

setTimeout: function() {
clearTimeout(this.timeoutID);
this.timeoutID = setTimeout.apply(null, arguments);
}
};

var ReactPlayground = React.createClass({
mixins: [selfCleaningTimeout],

MODES: {XJS: 'XJS', JS: 'JS'}, //keyMirror({XJS: true, JS: true}),

propTypes: {
Expand Down Expand Up @@ -137,11 +150,12 @@ var ReactPlayground = React.createClass({
eval(compiledCode);
}
} catch (e) {
React.renderComponent(
<div content={e.toString()} className="playgroundError" />,
mountNode
);
this.setTimeout(function() {
React.renderComponent(
<div className="playgroundError">{e.toString()}</div>,
mountNode
);
}, 500);
}
}
});