Skip to content

Commit

Permalink
Merge pull request #2540 from palantir/hotfix-selectionBoxLayerDest
Browse files Browse the repository at this point in the history
[hotfix] check if scale exists before offUpdating it
  • Loading branch information
jtlan committed Aug 3, 2015
2 parents f55ecc5 + 038b831 commit af44c59
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
8 changes: 6 additions & 2 deletions plottable.js
Original file line number Diff line number Diff line change
Expand Up @@ -6114,8 +6114,12 @@ var Plottable;
};
SelectionBoxLayer.prototype.destroy = function () {
_super.prototype.destroy.call(this);
this.xScale().offUpdate(this._adjustBoundsCallback);
this.yScale().offUpdate(this._adjustBoundsCallback);
if (this.xScale() != null) {
this.xScale().offUpdate(this._adjustBoundsCallback);
}
if (this.yScale() != null) {
this.yScale().offUpdate(this._adjustBoundsCallback);
}
};
return SelectionBoxLayer;
})(Plottable.Component);
Expand Down
8 changes: 6 additions & 2 deletions src/components/selectionBoxLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,12 @@ export module Components {

public destroy() {
super.destroy();
this.xScale().offUpdate(this._adjustBoundsCallback);
this.yScale().offUpdate(this._adjustBoundsCallback);
if (this.xScale() != null) {
this.xScale().offUpdate(this._adjustBoundsCallback);
}
if (this.yScale() != null) {
this.yScale().offUpdate(this._adjustBoundsCallback);
}
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions test/components/selectionBoxLayerTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ describe("SelectionBoxLayer", () => {
svg.remove();
});

it("destroy() does not error if scales are not inputted", () => {
var svg = TestMethods.generateSVG();
var sbl = new Plottable.Components.SelectionBoxLayer();
sbl.renderTo(svg);
assert.doesNotThrow(() => sbl.destroy(), Error, "can destroy even with no scales");

svg.remove();
});

it("bounds()", () => {
var svg = TestMethods.generateSVG();
var sbl = new Plottable.Components.SelectionBoxLayer();
Expand Down

0 comments on commit af44c59

Please sign in to comment.