Skip to content

Commit

Permalink
fix(api): Cancel transitions on destroy.
Browse files Browse the repository at this point in the history
- Interrupt possible transition pending on .destroy()
- Add condition to check unexpected async .load() call after is already
destroyed

Fix #766
Close #765
  • Loading branch information
pakerhoi authored and netil committed Feb 22, 2019
1 parent cd9d7f5 commit 7dd287d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions AUTHORS.txt
Expand Up @@ -24,3 +24,4 @@ Rex <rexebin@gmail.com>
Alexandre Araujo <https://github.com/oliveiraaraujo>
Jinwoo Oh <arkist@gmail.com>
Nirmal Guna <gunaseelann@jfrog.com>
Michael Yungerman <myungerman@lightricks.com>
18 changes: 18 additions & 0 deletions spec/api/api.chart-spec.js
Expand Up @@ -133,6 +133,24 @@ describe("API chart", () => {
expect(Object.keys(chart).length).to.be.equal(0);
expect(bb.instance.indexOf(chart) === -1).to.be.true;
});

it("should be destroyed without throwing error", done => {
chart = util.generate({
data: {
columns: [["data1", 50, 20]]
}
});

setTimeout(() => {
chart.load({
columns: [["data1", 100, 150]],
unload: ["data1"]
});

chart.destroy();
setTimeout(done, 500);
}, 500);
});
});

describe("config()", () => {
Expand Down
3 changes: 2 additions & 1 deletion src/api/api.chart.js
Expand Up @@ -73,7 +73,8 @@ extend(Chart.prototype, {
if (notEmpty($$)) {
$$.charts.splice($$.charts.indexOf(this), 1);

// clear timers
// clear timers && pending transition
$$.svg.select("*").interrupt();
isDefined($$.resizeTimeout) && window.clearTimeout($$.resizeTimeout);

window.removeEventListener("resize", $$.resizeFunction);
Expand Down
5 changes: 5 additions & 0 deletions src/data/data.load.js
Expand Up @@ -57,6 +57,11 @@ extend(ChartInternal.prototype, {
const $$ = this;
let data;

// prevent load when chart is already destroyed
if (!$$.config) {
return;
}

// reset internally cached data
$$.resetCache();

Expand Down

0 comments on commit 7dd287d

Please sign in to comment.