Skip to content

Commit

Permalink
Further cleanup using async/await
Browse files Browse the repository at this point in the history
  • Loading branch information
bnmnetp committed Jan 10, 2021
1 parent 88fea9a commit 7d8db11
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 27 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ module.exports = {
rules: {},
globals: {
eBookConfig: "readonly",
require: "readonly",
},
};
13 changes: 2 additions & 11 deletions runestone/activecode/js/activecode_html.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class HTMLActiveCode extends ActiveCode {
async runProg() {
var prog = await this.buildProg(true);
let saveCode = "True";
saveCode = await this.manage_scrubber(saveCode);
this.saveCode = await this.manage_scrubber(saveCode);
$(this.output).text("");
if (!this.alignVertical) {
$(this.codeDiv).switchClass("col-md-12", "col-md-6", {
Expand All @@ -25,17 +25,8 @@ export default class HTMLActiveCode extends ActiveCode {
"<script type=text/javascript>window.onerror = function(msg,url,line) {alert(msg+' on line: '+line);};</script>" +
prog;
this.output.srcdoc = prog;
this.logRunEvent({
div_id: this.divid,
code: this.editor.getValue(),
errinfo: "success",
to_save: saveCode,
prefix: this.pretext,
suffix: this.suffix,
lang: this.language,
partner: this.partner,
}); // Log the run event
}

createOutput() {
this.alignVertical = true;
var outDiv = document.createElement("div");
Expand Down
20 changes: 4 additions & 16 deletions runestone/activecode/js/activecode_js.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ export default class JSActiveCode extends ActiveCode {
}
async runProg() {
var _this = this;
var prog = this.buildProg(true);
var einfo;
var prog = await this.buildProg(true);
var saveCode = "True";
var write = function (str) {
_this.output.innerHTML += _this.outputfun(str);
Expand All @@ -41,27 +40,16 @@ export default class JSActiveCode extends ActiveCode {
if (!str) str = "";
_this.output.innerHTML += _this.outputfun(str) + "<br />";
};
saveCode = await this.manage_scrubber(saveCode);
this.saveCode = await this.manage_scrubber(saveCode);
$(this.eContainer).remove();
$(this.output).text("");
$(this.outDiv).show({ duration: 700, queue: false });
try {
eval(prog);
einfo = "success";
this.errinfo = "success";
} catch (e) {
this.addErrorMessage(e);
einfo = e;
this.errinfo = e;
}
// Note that, since this isn't awaited, the request may not be complete when this function returns.
this.logRunEvent({
div_id: this.divid,
code: this.editor.getValue(),
errinfo: einfo,
lang: this.language,
to_save: saveCode,
prefix: this.pretext,
suffix: this.suffix,
partner: this.partner,
});
}
}

0 comments on commit 7d8db11

Please sign in to comment.