Skip to content

Commit

Permalink
Only call update if cluster setting is the same
Browse files Browse the repository at this point in the history
  • Loading branch information
bartvde committed Nov 23, 2017
1 parent 8f6e334 commit 7aedd2e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/style-spec/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function diffSources(before, after, commands, sourcesRemoved) {
if (!before.hasOwnProperty(sourceId)) {
commands.push({ command: operations.addSource, args: [sourceId, after[sourceId]] });
} else if (!isEqual(before[sourceId], after[sourceId])) {
if (before[sourceId].type === 'geojson' && after[sourceId].type === 'geojson') {
if (before[sourceId].type === 'geojson' && after[sourceId].type === 'geojson' && before[sourceId].cluster === after[sourceId].cluster) {
// geojson sources use setGeoJSONSourceData command to update
commands.push({ command: operations.setGeoJSONSourceData, args: [sourceId, after[sourceId].data] });
} else {
Expand Down
24 changes: 24 additions & 0 deletions test/unit/style-spec/diff.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,30 @@ t('diff', (t) => {
}]}
], 'update a geojson source');

t.deepEqual(diffStyles({
sources: {
foo: {
type: 'geojson',
data: { type: 'FeatureCollection', features: [] }
}
}
}, {
sources: {
foo: {
type: 'geojson',
data: { type: 'FeatureCollection', features: [] },
cluster: true
}
}
}), [
{ command: 'removeSource', args: ['foo'] },
{ command: 'addSource', args: ['foo', {
type: 'geojson',
cluster: true,
data: { type: 'FeatureCollection', features: [] }
}]}
], 'remove and re-add a source if cluster change');

t.deepEqual(diffStyles({}, {
metadata: { 'mapbox:author': 'nobody' }
}), [], 'ignore style metadata');
Expand Down

0 comments on commit 7aedd2e

Please sign in to comment.