Skip to content

Commit

Permalink
delegat source data coalescing
Browse files Browse the repository at this point in the history
mapbox-gl-js handles it itself since mapbox/mapbox-gl-js#5902
  • Loading branch information
kturney committed Feb 2, 2018
1 parent 68365a5 commit 7b94f7c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 47 deletions.
34 changes: 2 additions & 32 deletions addon/components/mapbox-gl-source.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assign } from '@ember/polyfills';
import { bind, next } from '@ember/runloop';
import { next } from '@ember/runloop';
import { deprecate } from '@ember/application/deprecations';
import { getProperties, get, computed } from '@ember/object';
import { guidFor } from '@ember/object/internals';
Expand Down Expand Up @@ -65,14 +65,6 @@ export default Component.extend({
const combinedOpts = assign({}, computedOpts, options);

this.map.addSource(sourceId, combinedOpts);

if (combinedOpts.data) {
this._dataDone = bind(this, this._dataDone);
this.map.getSource(sourceId).on('data', this._dataDone);
}

this._dataAvailable = false;
this._dataInFlight = true;
},

didUpdateAttrs() {
Expand All @@ -84,39 +76,17 @@ export default Component.extend({

const sourceData = (options && options.data) || data;
if (sourceData) {
this._dataAvailable = true;
this._syncData(source, sourceData);
source.setData(sourceData);
} else if (options && options.coordinates) {
source.setCoordinates(options.coordinates);
}
},

_dataDone() {
this._dataInFlight = false;

const { sourceId, data, options } = getProperties(this, 'sourceId', 'data', 'options');

this._syncData(this.map.getSource(sourceId), (options && options.data) || data);
},

_syncData(source, data) {
if (this._dataInFlight === true || this._dataAvailable === false) {
return;
}

source.setData(data);

this._dataInFlight = true;
this._dataAvailable = false;
},

willDestroy() {
this._super(...arguments);

const sourceId = get(this, 'sourceId');

this.map.getSource(sourceId).off('data', this._dataDone);

// wait for any layers to be removed before removing the source
next(() => this.map.removeSource(sourceId));
}
Expand Down
15 changes: 0 additions & 15 deletions tests/integration/components/mapbox-gl-source-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { assign } from '@ember/polyfills';
import { moduleForComponent, test } from 'ember-qunit';
import createMap from '../../helpers/create-map';
import hbs from 'htmlbars-inline-precompile';
import RSVP from 'rsvp';
import Sinon from 'sinon';
import wait from 'ember-test-helpers/wait';

Expand Down Expand Up @@ -187,13 +186,6 @@ test('it passes updated data on to the source via the data property', async func

this.set('data', updatedData);

assert.notOk(setDataSpy.calledOnce, 'source#setData not called yet');

await new RSVP.Promise((resolve, reject) => {
source.once('data', resolve);
source.once('error', reject);
});

assert.ok(setDataSpy.calledOnce, 'source#setData called once');
assert.deepEqual(setDataSpy.firstCall.args[0], updatedData, 'correct data is updated');
});
Expand Down Expand Up @@ -255,13 +247,6 @@ test('it passes updated data on to the source via the options property', async f

this.set('data', updatedData);

assert.notOk(setDataSpy.calledOnce, 'source#setData not called yet');

await new RSVP.Promise((resolve, reject) => {
source.once('data', resolve);
source.once('error', reject);
});

assert.ok(setDataSpy.calledOnce, 'source#setData called once');
assert.deepEqual(setDataSpy.firstCall.args[0], updatedData, 'correct data is updated');
});
Expand Down

0 comments on commit 7b94f7c

Please sign in to comment.