Fix error logic and output display

This commit is contained in:
Berkeley Martinez
2015-11-24 15:12:54 -08:00
parent 04db6744b9
commit da67e77fad
2 changed files with 18 additions and 9 deletions

View File

@ -7,6 +7,7 @@ $(document).ready(function() {
init($);
});
// only run if editor present
if (common.editor.getValue) {
const code$ = common.editorKeyUp$
.debounce(750)
@ -24,8 +25,12 @@ $(document).ready(function() {
);
code$
// only run for HTML
.filter(() => common.challengeType === challengeTypes.HTML)
.flatMap(code => {
if (common.hasJs(code)) {
if (
common.hasJs(code)
) {
return common.detectUnsafeCode$(code)
.flatMap(code => common.detectLoops$(code))
.flatMap(
@ -44,6 +49,7 @@ $(document).ready(function() {
},
err => console.error(err)
);
}
common.resetBtn$
@ -129,21 +135,24 @@ $(document).ready(function() {
}
if (
challengeType === challengeTypes.BONFIRE &&
challengeType === challengeTypes.BONFIRE ||
challengeType === challengeTypes.JS
) {
Observable.just({})
.delay(500)
.flatMap(() => common.executeChallenge$())
.catch(err => Observable.just({ err }))
.subscribe(
({ original, tests }) => {
({ err, original, tests }) => {
if (err) {
console.error(err);
return common.updateOutputDisplay('' + err);
}
common.codeStorage.updateStorage(challengeName, original);
common.displayTestResults(tests);
},
({ err }) => {
if (err.stack) {
console.error(err);
}
(err) => {
console.error(err);
common.updateOutputDisplay('' + err);
}
);

View File

@ -57,12 +57,12 @@ window.common = (function(global) {
// js challenge
// remove comments and add tests to string
return common.addTestsToString(Object.assign(
return Observable.just(common.addTestsToString(Object.assign(
{
code: common.removeComments(code),
tests: common.tests.slice()
}
))
)))
.flatMap(common.detectLoops$)
.flatMap(({ err, code, data, userTests }) => {
if (err) {