Skip to content

Commit

Permalink
Using regionStack
Browse files Browse the repository at this point in the history
  • Loading branch information
afska committed Feb 22, 2018
1 parent bdcc098 commit 604e76d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions app/elements/gobstones-blockly/gobstones-blockly.html
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,13 @@
this.runner.run(
{ initialState, code },
(error, code) => {
const region = error.on.region;
const { region } = error.on;
if (region) this._showError(region, error);
window.BUS.fire("compilation-error");
},
(state, fullState = {}) => {
const { region } = fullState;
const { regionStack } = fullState;
const region = this._getLastRegion(regionStack);
if (region) this._highlight(region)
this._notify(state);
}
Expand All @@ -189,7 +190,8 @@

_notify: function(state) {
if (state.error) {
const region = state.error.on.region;
const { regionStack } = state.error.on;
const region = this._getLastRegion(regionStack);
if (region) this._showError(region, state.error);
window.BUS.fire("execution-error", state.error.message);
} else
Expand Down Expand Up @@ -263,6 +265,10 @@
toolbox.mouseup(showMessageIfNeeded);
},

_getLastRegion(regionStack) {
return _(regionStack).compact().last();
},

_showError(region, error) {
const { message, reason: { code, detail } } = error;

Expand Down

0 comments on commit 604e76d

Please sign in to comment.