Skip to content

Commit 040d6ac

Browse files
committed
Plots.resize: resolve old promises
1 parent deb32ff commit 040d6ac

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/plots/plots.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ plots.redrawText = function(gd) {
7676
plots.resize = function(gd) {
7777
gd = Lib.getGraphDiv(gd);
7878

79-
return new Promise(function(resolve, reject) {
79+
var resolveLastResize;
80+
var p = new Promise(function(resolve, reject) {
8081
if(!gd || Lib.isHidden(gd)) {
8182
reject(new Error('Resize must be passed a displayed plot div element.'));
8283
}
8384

84-
if(gd._rejectResize) gd._rejectResize();
85-
gd._rejectResize = reject;
86-
8785
if(gd._redrawTimer) clearTimeout(gd._redrawTimer);
86+
if(gd._resolveResize) resolveLastResize = gd._resolveResize;
87+
gd._resolveResize = resolve;
8888

8989
gd._redrawTimer = setTimeout(function() {
9090
// return if there is nothing to resize or is hidden
@@ -108,6 +108,9 @@ plots.resize = function(gd) {
108108
});
109109
}, 100);
110110
});
111+
112+
if(resolveLastResize) resolveLastResize(p);
113+
return p;
111114
};
112115

113116

test/jasmine/tests/plots_test.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -416,16 +416,13 @@ describe('Test Plots', function() {
416416
describe('returns Promises', function() {
417417
afterEach(destroyGraphDiv);
418418

419-
it('should reject or resolve them all', function(done) {
419+
it('should resolve them all', function(done) {
420420
gd = createGraphDiv();
421421
var p = [];
422422
Plotly.newPlot(gd, [{y: [5, 2, 5]}])
423423
.then(function() {
424-
// First call should get rejected
425-
p.push(Plotly.Plots.resize(gd).catch(function() {
426-
return Promise.resolve(true);
427-
}));
428-
// because we call the function again within 100ms
424+
p.push(Plotly.Plots.resize(gd));
425+
p.push(Plotly.Plots.resize(gd));
429426
p.push(Plotly.Plots.resize(gd));
430427
return Promise.all(p);
431428
})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy