Skip to content

Commit

Permalink
Plots.resize: reject old promises
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinerg committed Nov 29, 2019
1 parent 5ef8a61 commit deb32ff
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ plots.resize = function(gd) {
reject(new Error('Resize must be passed a displayed plot div element.'));
}

if(gd._rejectResize) gd._rejectResize();
gd._rejectResize = reject;

if(gd._redrawTimer) clearTimeout(gd._redrawTimer);

gd._redrawTimer = setTimeout(function() {
Expand Down
21 changes: 21 additions & 0 deletions test/jasmine/tests/plots_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,27 @@ describe('Test Plots', function() {
.then(done);
});
});

describe('returns Promises', function() {
afterEach(destroyGraphDiv);

it('should reject or resolve them all', function(done) {
gd = createGraphDiv();
var p = [];
Plotly.newPlot(gd, [{y: [5, 2, 5]}])
.then(function() {
// First call should get rejected
p.push(Plotly.Plots.resize(gd).catch(function() {
return Promise.resolve(true);
}));
// because we call the function again within 100ms
p.push(Plotly.Plots.resize(gd));
return Promise.all(p);
})
.catch(failTest)
.then(done);
});
});
});

describe('Plots.purge', function() {
Expand Down

0 comments on commit deb32ff

Please sign in to comment.