Skip to content

Commit

Permalink
Use a named option rather than a boolean flag
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Nov 22, 2016
1 parent 92956de commit 8f0475e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions js/ui/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -652,12 +652,14 @@ class Map extends Camera {
*
* @param {Object|string} style A JSON object conforming to the schema described in the
* [Mapbox Style Specification](https://mapbox.com/mapbox-gl-style-spec/), or a URL to such JSON.
* @param {boolean} forceNoDiff Force a 'full' update, removing the current style and adding building the given one instead of attempting a diff-based update.
* @param {Object} [options]
* @param {boolean} [options.diff=true] If false, force a 'full' update, removing the current style
* and adding building the given one instead of attempting a diff-based update.
* @returns {Map} `this`
* @see [Change a map's style](https://www.mapbox.com/mapbox-gl-js/example/setstyle/)
*/
setStyle(style, forceNoDiff) {
const shouldTryDiff = !forceNoDiff && this.style && style &&
setStyle(style, options) {
const shouldTryDiff = (!options || options.diff !== false) && this.style && style &&
!(style instanceof Style) && typeof style !== 'string';
if (shouldTryDiff) {
try {
Expand Down
4 changes: 2 additions & 2 deletions test/js/ui/map.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,15 +300,15 @@ test('Map', (t) => {
t.end();
});

t.test('creates a new Style if forceNoDiff parameter is set', (t) => {
t.test('creates a new Style if diff option is false', (t) => {
const style = createStyle();
const map = createMap({ style: style });
t.stub(map.style, 'setState', () => {
t.fail();
});

const previousStyle = map.style;
map.setStyle(style, true);
map.setStyle(style, {diff: false});
t.ok(map.style && map.style !== previousStyle);
t.end();
});
Expand Down

0 comments on commit 8f0475e

Please sign in to comment.