Skip to content

Commit 48eec0c

Browse files
authored
Merge pull request #776 from plotly/mapbox-access-token-catches
Mapbox access token catches
2 parents 11dba5f + 30a3fbe commit 48eec0c

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

src/plot_api/plot_api.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,6 @@ Plotly.plot = function(gd, data, layout, config) {
326326
// so that the caller doesn't care which route we took
327327
return Promise.all(gd._promises).then(function() {
328328
return gd;
329-
}, function() {
330-
// clear the promise queue if one of them got rejected
331-
Lib.log('Clearing previous rejected promises from queue.');
332-
gd._promises = [];
333329
});
334330
};
335331

@@ -355,6 +351,12 @@ function getGraphDiv(gd) {
355351
return gd; // otherwise assume that gd is a DOM element
356352
}
357353

354+
// clear the promise queue if one of them got rejected
355+
function clearPromiseQueue(gd) {
356+
Lib.log('Clearing previous rejected promises from queue.');
357+
gd._promises = [];
358+
}
359+
358360
function opaqueSetBackground(gd, bgColor) {
359361
gd._fullLayout._paperdiv.style('background', 'white');
360362
Plotly.defaultConfig.setBackground(gd, bgColor);
@@ -1536,6 +1538,7 @@ Plotly.moveTraces = function moveTraces(gd, currentIndices, newIndices) {
15361538
// style files that want to specify cyclical default values).
15371539
Plotly.restyle = function restyle(gd, astr, val, traces) {
15381540
gd = getGraphDiv(gd);
1541+
clearPromiseQueue(gd);
15391542

15401543
var i, fullLayout = gd._fullLayout,
15411544
aobj = {};
@@ -2076,6 +2079,7 @@ function swapXYData(trace) {
20762079
// allows setting multiple attributes simultaneously
20772080
Plotly.relayout = function relayout(gd, astr, val) {
20782081
gd = getGraphDiv(gd);
2082+
clearPromiseQueue(gd);
20792083

20802084
if(gd.framework && gd.framework.isPolar) {
20812085
return Promise.resolve(gd);

test/jasmine/tests/mapbox_test.js

+17-8
Original file line numberDiff line numberDiff line change
@@ -180,18 +180,26 @@ describe('mapbox credentials', function() {
180180
});
181181

182182
it('should throw error if token is invalid', function(done) {
183+
var cnt = 0;
184+
183185
Plotly.plot(gd, [{
184186
type: 'scattermapbox',
185187
lon: [10, 20, 30],
186188
lat: [10, 20, 30]
187189
}], {}, {
188190
mapboxAccessToken: dummyToken
189191
}).catch(function(err) {
192+
cnt++;
190193
expect(err).toEqual(new Error(constants.mapOnErrorMsg));
191-
}).then(done);
194+
}).then(function() {
195+
expect(cnt).toEqual(1);
196+
done();
197+
});
192198
});
193199

194200
it('should use access token in mapbox layout options if present', function(done) {
201+
var cnt = 0;
202+
195203
Plotly.plot(gd, [{
196204
type: 'scattermapbox',
197205
lon: [10, 20, 30],
@@ -202,7 +210,10 @@ describe('mapbox credentials', function() {
202210
}
203211
}, {
204212
mapboxAccessToken: dummyToken
213+
}).catch(function() {
214+
cnt++;
205215
}).then(function() {
216+
expect(cnt).toEqual(0);
206217
expect(gd._fullLayout.mapbox.accesstoken).toEqual(MAPBOX_ACCESS_TOKEN);
207218
done();
208219
});
@@ -493,21 +504,19 @@ describe('mapbox plots', function() {
493504
});
494505

495506
it('should be able to update the access token', function(done) {
496-
var promise = Plotly.relayout(gd, 'mapbox.accesstoken', 'wont-work');
497-
498-
promise.catch(function(err) {
507+
Plotly.relayout(gd, 'mapbox.accesstoken', 'wont-work').catch(function(err) {
499508
expect(gd._fullLayout.mapbox.accesstoken).toEqual('wont-work');
500509
expect(err).toEqual(new Error(constants.mapOnErrorMsg));
501-
});
510+
expect(gd._promises.length).toEqual(1);
502511

503-
promise.then(function() {
504512
return Plotly.relayout(gd, 'mapbox.accesstoken', MAPBOX_ACCESS_TOKEN);
505513
}).then(function() {
506514
expect(gd._fullLayout.mapbox.accesstoken).toEqual(MAPBOX_ACCESS_TOKEN);
507-
}).then(done);
515+
expect(gd._promises.length).toEqual(0);
516+
done();
517+
});
508518
});
509519

510-
511520
it('should be able to update traces', function(done) {
512521
function assertDataPts(lengths) {
513522
var lines = getGeoJsonData(gd, 'lines'),

0 commit comments

Comments
 (0)