Fix error logic and output display
This commit is contained in:
@ -7,6 +7,7 @@ $(document).ready(function() {
|
|||||||
init($);
|
init($);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// only run if editor present
|
||||||
if (common.editor.getValue) {
|
if (common.editor.getValue) {
|
||||||
const code$ = common.editorKeyUp$
|
const code$ = common.editorKeyUp$
|
||||||
.debounce(750)
|
.debounce(750)
|
||||||
@ -24,8 +25,12 @@ $(document).ready(function() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
code$
|
code$
|
||||||
|
// only run for HTML
|
||||||
|
.filter(() => common.challengeType === challengeTypes.HTML)
|
||||||
.flatMap(code => {
|
.flatMap(code => {
|
||||||
if (common.hasJs(code)) {
|
if (
|
||||||
|
common.hasJs(code)
|
||||||
|
) {
|
||||||
return common.detectUnsafeCode$(code)
|
return common.detectUnsafeCode$(code)
|
||||||
.flatMap(code => common.detectLoops$(code))
|
.flatMap(code => common.detectLoops$(code))
|
||||||
.flatMap(
|
.flatMap(
|
||||||
@ -44,6 +49,7 @@ $(document).ready(function() {
|
|||||||
},
|
},
|
||||||
err => console.error(err)
|
err => console.error(err)
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
common.resetBtn$
|
common.resetBtn$
|
||||||
@ -129,21 +135,24 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
challengeType === challengeTypes.BONFIRE &&
|
challengeType === challengeTypes.BONFIRE ||
|
||||||
challengeType === challengeTypes.JS
|
challengeType === challengeTypes.JS
|
||||||
) {
|
) {
|
||||||
Observable.just({})
|
Observable.just({})
|
||||||
.delay(500)
|
.delay(500)
|
||||||
.flatMap(() => common.executeChallenge$())
|
.flatMap(() => common.executeChallenge$())
|
||||||
|
.catch(err => Observable.just({ err }))
|
||||||
.subscribe(
|
.subscribe(
|
||||||
({ original, tests }) => {
|
({ err, original, tests }) => {
|
||||||
|
if (err) {
|
||||||
|
console.error(err);
|
||||||
|
return common.updateOutputDisplay('' + err);
|
||||||
|
}
|
||||||
common.codeStorage.updateStorage(challengeName, original);
|
common.codeStorage.updateStorage(challengeName, original);
|
||||||
common.displayTestResults(tests);
|
common.displayTestResults(tests);
|
||||||
},
|
},
|
||||||
({ err }) => {
|
(err) => {
|
||||||
if (err.stack) {
|
console.error(err);
|
||||||
console.error(err);
|
|
||||||
}
|
|
||||||
common.updateOutputDisplay('' + err);
|
common.updateOutputDisplay('' + err);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -57,12 +57,12 @@ window.common = (function(global) {
|
|||||||
|
|
||||||
// js challenge
|
// js challenge
|
||||||
// remove comments and add tests to string
|
// remove comments and add tests to string
|
||||||
return common.addTestsToString(Object.assign(
|
return Observable.just(common.addTestsToString(Object.assign(
|
||||||
{
|
{
|
||||||
code: common.removeComments(code),
|
code: common.removeComments(code),
|
||||||
tests: common.tests.slice()
|
tests: common.tests.slice()
|
||||||
}
|
}
|
||||||
))
|
)))
|
||||||
.flatMap(common.detectLoops$)
|
.flatMap(common.detectLoops$)
|
||||||
.flatMap(({ err, code, data, userTests }) => {
|
.flatMap(({ err, code, data, userTests }) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
Reference in New Issue
Block a user