From ad9bdcda3672721670a878b10c3d7e9779f5bb7c Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 3 Mar 2021 18:10:41 -0500 Subject: [PATCH 1/5] skip fetch --- .../tiled_vector_layer/tiled_vector_layer.tsx | 21 ++++++++++++------- .../public/classes/util/can_skip_fetch.ts | 21 ++++++++++++------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/x-pack/plugins/maps/public/classes/layers/tiled_vector_layer/tiled_vector_layer.tsx b/x-pack/plugins/maps/public/classes/layers/tiled_vector_layer/tiled_vector_layer.tsx index 477b17ae03d7b..c6b345882f537 100644 --- a/x-pack/plugins/maps/public/classes/layers/tiled_vector_layer/tiled_vector_layer.tsx +++ b/x-pack/plugins/maps/public/classes/layers/tiled_vector_layer/tiled_vector_layer.tsx @@ -23,6 +23,7 @@ import { VectorSourceRequestMeta, } from '../../../../common/descriptor_types'; import { MVTSingleLayerVectorSourceConfig } from '../../sources/mvt_single_layer_vector_source/types'; +import { canSkipSourceUpdate } from '../../util/can_skip_fetch'; export class TiledVectorLayer extends VectorLayer { static type = LAYER_TYPE.TILED_VECTOR; @@ -68,18 +69,22 @@ export class TiledVectorLayer extends VectorLayer { this._style as IVectorStyle ); const prevDataRequest = this.getSourceDataRequest(); - - const templateWithMeta = await this._source.getUrlTemplateWithMeta(searchFilters); + const dataRequest = await this._source.getUrlTemplateWithMeta(searchFilters); if (prevDataRequest) { const data: MVTSingleLayerVectorSourceConfig = prevDataRequest.getData() as MVTSingleLayerVectorSourceConfig; if (data) { - const canSkipBecauseNoChanges = + const noChangesInSourceState: boolean = data.layerName === this._source.getLayerName() && data.minSourceZoom === this._source.getMinZoom() && - data.maxSourceZoom === this._source.getMaxZoom() && - data.urlTemplate === templateWithMeta.urlTemplate; - - if (canSkipBecauseNoChanges) { + data.maxSourceZoom === this._source.getMaxZoom(); + const noChangesInSearchState: boolean = await canSkipSourceUpdate({ + considerSpatialParameters: false, + source: this.getSource(), + prevDataRequest, + nextMeta: searchFilters, + }); + const canSkip = noChangesInSourceState && noChangesInSearchState; + if (canSkip) { return null; } } @@ -87,7 +92,7 @@ export class TiledVectorLayer extends VectorLayer { startLoading(SOURCE_DATA_REQUEST_ID, requestToken, searchFilters); try { - stopLoading(SOURCE_DATA_REQUEST_ID, requestToken, templateWithMeta, {}); + stopLoading(SOURCE_DATA_REQUEST_ID, requestToken, dataRequest, {}); } catch (error) { onLoadError(SOURCE_DATA_REQUEST_ID, requestToken, error.message); } diff --git a/x-pack/plugins/maps/public/classes/util/can_skip_fetch.ts b/x-pack/plugins/maps/public/classes/util/can_skip_fetch.ts index 1b2fae413d909..361fb442af7c9 100644 --- a/x-pack/plugins/maps/public/classes/util/can_skip_fetch.ts +++ b/x-pack/plugins/maps/public/classes/util/can_skip_fetch.ts @@ -55,10 +55,12 @@ export async function canSkipSourceUpdate({ source, prevDataRequest, nextMeta, + considerSpatialParameters = true, }: { source: ISource; prevDataRequest: DataRequest | undefined; nextMeta: DataMeta; + considerSpatialParameters: boolean; }): Promise { const timeAware = await source.isTimeAware(); const refreshTimerAware = await source.isRefreshTimerAware(); @@ -70,10 +72,10 @@ export async function canSkipSourceUpdate({ if ( !timeAware && !refreshTimerAware && - !extentAware && + !(extentAware && considerSpatialParameters) && !isFieldAware && !isQueryAware && - !isGeoGridPrecisionAware + !(isGeoGridPrecisionAware && considerSpatialParameters) ) { return !!prevDataRequest && prevDataRequest.hasDataOrRequestInProgress(); } @@ -132,13 +134,16 @@ export async function canSkipSourceUpdate({ } let updateDueToPrecisionChange = false; - if (isGeoGridPrecisionAware) { - updateDueToPrecisionChange = !_.isEqual(prevMeta.geogridPrecision, nextMeta.geogridPrecision); - } - let updateDueToExtentChange = false; - if (extentAware) { - updateDueToExtentChange = updateDueToExtent(prevMeta, nextMeta); + + if (considerSpatialParameters) { + if (isGeoGridPrecisionAware) { + updateDueToPrecisionChange = !_.isEqual(prevMeta.geogridPrecision, nextMeta.geogridPrecision); + } + + if (extentAware) { + updateDueToExtentChange = updateDueToExtent(prevMeta, nextMeta); + } } const updateDueToSourceMetaChange = !_.isEqual(prevMeta.sourceMeta, nextMeta.sourceMeta); From d789948ebb3e8960dab6acdd9de3583b5323d1b3 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Fri, 5 Mar 2021 15:33:52 -0500 Subject: [PATCH 2/5] make param required --- .../layers/blended_vector_layer/blended_vector_layer.ts | 1 + .../maps/public/classes/layers/vector_layer/utils.tsx | 1 + .../public/classes/layers/vector_layer/vector_layer.tsx | 1 + .../maps/public/classes/util/can_skip_fetch.test.js | 8 ++++++++ x-pack/plugins/maps/public/classes/util/can_skip_fetch.ts | 2 +- 5 files changed, 12 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/maps/public/classes/layers/blended_vector_layer/blended_vector_layer.ts b/x-pack/plugins/maps/public/classes/layers/blended_vector_layer/blended_vector_layer.ts index d3a4fa4101ac9..f77fff6ec0e89 100644 --- a/x-pack/plugins/maps/public/classes/layers/blended_vector_layer/blended_vector_layer.ts +++ b/x-pack/plugins/maps/public/classes/layers/blended_vector_layer/blended_vector_layer.ts @@ -302,6 +302,7 @@ export class BlendedVectorLayer extends VectorLayer implements IVectorLayer { source: this.getSource(), prevDataRequest: this.getDataRequest(dataRequestId), nextMeta: searchFilters, + considerSpatialParameters: true, }); let activeSource; diff --git a/x-pack/plugins/maps/public/classes/layers/vector_layer/utils.tsx b/x-pack/plugins/maps/public/classes/layers/vector_layer/utils.tsx index 91bdd74c158f9..79a4a587c180f 100644 --- a/x-pack/plugins/maps/public/classes/layers/vector_layer/utils.tsx +++ b/x-pack/plugins/maps/public/classes/layers/vector_layer/utils.tsx @@ -73,6 +73,7 @@ export async function syncVectorSource({ source, prevDataRequest, nextMeta: requestMeta, + considerSpatialParameters: true, }); if (canSkipFetch) { return { diff --git a/x-pack/plugins/maps/public/classes/layers/vector_layer/vector_layer.tsx b/x-pack/plugins/maps/public/classes/layers/vector_layer/vector_layer.tsx index b21bff9922671..917e5ea187fd3 100644 --- a/x-pack/plugins/maps/public/classes/layers/vector_layer/vector_layer.tsx +++ b/x-pack/plugins/maps/public/classes/layers/vector_layer/vector_layer.tsx @@ -332,6 +332,7 @@ export class VectorLayer extends AbstractLayer implements IVectorLayer { source: joinSource, prevDataRequest, nextMeta: searchFilters, + considerSpatialParameters: true, }); if (canSkipFetch) { return { diff --git a/x-pack/plugins/maps/public/classes/util/can_skip_fetch.test.js b/x-pack/plugins/maps/public/classes/util/can_skip_fetch.test.js index ce58cb7d019ed..eaead2c8267ca 100644 --- a/x-pack/plugins/maps/public/classes/util/can_skip_fetch.test.js +++ b/x-pack/plugins/maps/public/classes/util/can_skip_fetch.test.js @@ -135,6 +135,7 @@ describe('canSkipSourceUpdate', () => { source: queryAwareSourceMock, prevDataRequest, nextMeta, + considerSpatialParameters: true, }); expect(canSkipUpdate).toBe(true); @@ -154,6 +155,7 @@ describe('canSkipSourceUpdate', () => { source: queryAwareSourceMock, prevDataRequest, nextMeta, + considerSpatialParameters: true, }); expect(canSkipUpdate).toBe(true); @@ -173,6 +175,7 @@ describe('canSkipSourceUpdate', () => { source: queryAwareSourceMock, prevDataRequest, nextMeta, + considerSpatialParameters: true, }); expect(canSkipUpdate).toBe(false); @@ -189,6 +192,7 @@ describe('canSkipSourceUpdate', () => { source: queryAwareSourceMock, prevDataRequest, nextMeta, + considerSpatialParameters: true, }); expect(canSkipUpdate).toBe(false); @@ -219,6 +223,7 @@ describe('canSkipSourceUpdate', () => { source: queryAwareSourceMock, prevDataRequest, nextMeta, + considerSpatialParameters: true, }); expect(canSkipUpdate).toBe(false); @@ -238,6 +243,7 @@ describe('canSkipSourceUpdate', () => { source: queryAwareSourceMock, prevDataRequest, nextMeta, + considerSpatialParameters: true, }); expect(canSkipUpdate).toBe(false); @@ -257,6 +263,7 @@ describe('canSkipSourceUpdate', () => { source: queryAwareSourceMock, prevDataRequest, nextMeta, + considerSpatialParameters: true, }); expect(canSkipUpdate).toBe(false); @@ -273,6 +280,7 @@ describe('canSkipSourceUpdate', () => { source: queryAwareSourceMock, prevDataRequest, nextMeta, + considerSpatialParameters: true, }); expect(canSkipUpdate).toBe(false); diff --git a/x-pack/plugins/maps/public/classes/util/can_skip_fetch.ts b/x-pack/plugins/maps/public/classes/util/can_skip_fetch.ts index 361fb442af7c9..f696d59eb186b 100644 --- a/x-pack/plugins/maps/public/classes/util/can_skip_fetch.ts +++ b/x-pack/plugins/maps/public/classes/util/can_skip_fetch.ts @@ -55,7 +55,7 @@ export async function canSkipSourceUpdate({ source, prevDataRequest, nextMeta, - considerSpatialParameters = true, + considerSpatialParameters, }: { source: ISource; prevDataRequest: DataRequest | undefined; From 62743ff59b5e616c028bffafabe1d63ef212857d Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 9 Mar 2021 13:36:54 -0500 Subject: [PATCH 3/5] add unit test --- .../tiled_vector_layer.test.tsx | 59 ++++++++++++++++--- 1 file changed, 52 insertions(+), 7 deletions(-) diff --git a/x-pack/plugins/maps/public/classes/layers/tiled_vector_layer/tiled_vector_layer.test.tsx b/x-pack/plugins/maps/public/classes/layers/tiled_vector_layer/tiled_vector_layer.test.tsx index b2bb6a94197f0..39d24f3559a84 100644 --- a/x-pack/plugins/maps/public/classes/layers/tiled_vector_layer/tiled_vector_layer.test.tsx +++ b/x-pack/plugins/maps/public/classes/layers/tiled_vector_layer/tiled_vector_layer.test.tsx @@ -37,7 +37,8 @@ const defaultConfig = { function createLayer( layerOptions: Partial = {}, - sourceOptions: Partial = {} + sourceOptions: Partial = {}, + isTimeAware: boolean = false ): TiledVectorLayer { const sourceDescriptor: TiledSingleLayerVectorSourceDescriptor = { type: SOURCE_TYPES.MVT_SINGLE_LAYER, @@ -47,6 +48,14 @@ function createLayer( ...sourceOptions, }; const mvtSource = new MVTSingleLayerVectorSource(sourceDescriptor); + if (isTimeAware) { + mvtSource.isTimeAware = async () => { + return true; + }; + mvtSource.getApplyGlobalTime = () => { + return true; + }; + } const defaultLayerOptions = { ...layerOptions, @@ -130,13 +139,49 @@ describe('syncData', () => { sinon.assert.notCalled(syncContext2.stopLoading); }); + it('Should resync when changes to syncContext', async () => { + const layer1: TiledVectorLayer = createLayer({}, {}, true); + const syncContext1 = new MockSyncContext({ + dataFilters: { + timeFilters: { + from: 'now', + to: '15m', + mode: 'relative', + }, + }, + }); + + await layer1.syncData(syncContext1); + + const dataRequestDescriptor: DataRequestDescriptor = { + data: { ...defaultConfig }, + dataId: 'source', + }; + const layer2: TiledVectorLayer = createLayer( + { + __dataRequests: [dataRequestDescriptor], + }, + {}, + true + ); + const syncContext2 = new MockSyncContext({ + dataFilters: { + timeFilters: { + from: 'now', + to: '30m', + mode: 'relative', + }, + }, + }); + await layer2.syncData(syncContext2); + // @ts-expect-error + sinon.assert.calledOnce(syncContext2.startLoading); + // @ts-expect-error + sinon.assert.calledOnce(syncContext2.stopLoading); + }); + describe('Should resync when changes to source params: ', () => { - [ - { layerName: 'barfoo' }, - { urlTemplate: 'https://sub.example.com/{z}/{x}/{y}.pbf' }, - { minSourceZoom: 1 }, - { maxSourceZoom: 12 }, - ].forEach((changes) => { + [{ layerName: 'barfoo' }, { minSourceZoom: 1 }, { maxSourceZoom: 12 }].forEach((changes) => { it(`change in ${Object.keys(changes).join(',')}`, async () => { const layer1: TiledVectorLayer = createLayer({}, {}); const syncContext1 = new MockSyncContext({ dataFilters: {} }); From 26cb81bdad6976204a6ea08051b43e890598369c Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 10 Mar 2021 10:51:26 -0500 Subject: [PATCH 4/5] introduce extentAware --- .../blended_vector_layer.ts | 5 +++-- .../tiled_vector_layer/tiled_vector_layer.tsx | 2 +- .../classes/layers/vector_layer/utils.tsx | 2 +- .../layers/vector_layer/vector_layer.tsx | 2 +- .../classes/util/can_skip_fetch.test.js | 16 +++++++------- .../public/classes/util/can_skip_fetch.ts | 21 ++++++++----------- 6 files changed, 23 insertions(+), 25 deletions(-) diff --git a/x-pack/plugins/maps/public/classes/layers/blended_vector_layer/blended_vector_layer.ts b/x-pack/plugins/maps/public/classes/layers/blended_vector_layer/blended_vector_layer.ts index f77fff6ec0e89..d795315acbf50 100644 --- a/x-pack/plugins/maps/public/classes/layers/blended_vector_layer/blended_vector_layer.ts +++ b/x-pack/plugins/maps/public/classes/layers/blended_vector_layer/blended_vector_layer.ts @@ -298,11 +298,12 @@ export class BlendedVectorLayer extends VectorLayer implements IVectorLayer { this.getSource(), this.getCurrentStyle() ); + const source = this.getSource(); const canSkipFetch = await canSkipSourceUpdate({ - source: this.getSource(), + source, prevDataRequest: this.getDataRequest(dataRequestId), nextMeta: searchFilters, - considerSpatialParameters: true, + extentAware: source.isFilterByMapBounds(), }); let activeSource; diff --git a/x-pack/plugins/maps/public/classes/layers/tiled_vector_layer/tiled_vector_layer.tsx b/x-pack/plugins/maps/public/classes/layers/tiled_vector_layer/tiled_vector_layer.tsx index c6b345882f537..f2fe916953801 100644 --- a/x-pack/plugins/maps/public/classes/layers/tiled_vector_layer/tiled_vector_layer.tsx +++ b/x-pack/plugins/maps/public/classes/layers/tiled_vector_layer/tiled_vector_layer.tsx @@ -78,7 +78,7 @@ export class TiledVectorLayer extends VectorLayer { data.minSourceZoom === this._source.getMinZoom() && data.maxSourceZoom === this._source.getMaxZoom(); const noChangesInSearchState: boolean = await canSkipSourceUpdate({ - considerSpatialParameters: false, + extentAware: false, // spatial extent knowledge is already fully automated by tile-loading based on pan-zooming source: this.getSource(), prevDataRequest, nextMeta: searchFilters, diff --git a/x-pack/plugins/maps/public/classes/layers/vector_layer/utils.tsx b/x-pack/plugins/maps/public/classes/layers/vector_layer/utils.tsx index 79a4a587c180f..e49339b6250b4 100644 --- a/x-pack/plugins/maps/public/classes/layers/vector_layer/utils.tsx +++ b/x-pack/plugins/maps/public/classes/layers/vector_layer/utils.tsx @@ -73,7 +73,7 @@ export async function syncVectorSource({ source, prevDataRequest, nextMeta: requestMeta, - considerSpatialParameters: true, + extentAware: source.isFilterByMapBounds(), }); if (canSkipFetch) { return { diff --git a/x-pack/plugins/maps/public/classes/layers/vector_layer/vector_layer.tsx b/x-pack/plugins/maps/public/classes/layers/vector_layer/vector_layer.tsx index 917e5ea187fd3..104d0b56578d1 100644 --- a/x-pack/plugins/maps/public/classes/layers/vector_layer/vector_layer.tsx +++ b/x-pack/plugins/maps/public/classes/layers/vector_layer/vector_layer.tsx @@ -332,7 +332,7 @@ export class VectorLayer extends AbstractLayer implements IVectorLayer { source: joinSource, prevDataRequest, nextMeta: searchFilters, - considerSpatialParameters: true, + extentAware: false, // join-sources are term-aggs that are spatially unaware (e.g. ESTermSource/TableSource). }); if (canSkipFetch) { return { diff --git a/x-pack/plugins/maps/public/classes/util/can_skip_fetch.test.js b/x-pack/plugins/maps/public/classes/util/can_skip_fetch.test.js index eaead2c8267ca..1901b15e8f350 100644 --- a/x-pack/plugins/maps/public/classes/util/can_skip_fetch.test.js +++ b/x-pack/plugins/maps/public/classes/util/can_skip_fetch.test.js @@ -135,7 +135,7 @@ describe('canSkipSourceUpdate', () => { source: queryAwareSourceMock, prevDataRequest, nextMeta, - considerSpatialParameters: true, + extentAware: queryAwareSourceMock.isFilterByMapBounds(), }); expect(canSkipUpdate).toBe(true); @@ -155,7 +155,7 @@ describe('canSkipSourceUpdate', () => { source: queryAwareSourceMock, prevDataRequest, nextMeta, - considerSpatialParameters: true, + extentAware: queryAwareSourceMock.isFilterByMapBounds(), }); expect(canSkipUpdate).toBe(true); @@ -175,7 +175,7 @@ describe('canSkipSourceUpdate', () => { source: queryAwareSourceMock, prevDataRequest, nextMeta, - considerSpatialParameters: true, + extentAware: queryAwareSourceMock.isFilterByMapBounds(), }); expect(canSkipUpdate).toBe(false); @@ -192,7 +192,7 @@ describe('canSkipSourceUpdate', () => { source: queryAwareSourceMock, prevDataRequest, nextMeta, - considerSpatialParameters: true, + extentAware: queryAwareSourceMock.isFilterByMapBounds(), }); expect(canSkipUpdate).toBe(false); @@ -223,7 +223,7 @@ describe('canSkipSourceUpdate', () => { source: queryAwareSourceMock, prevDataRequest, nextMeta, - considerSpatialParameters: true, + extentAware: queryAwareSourceMock.isFilterByMapBounds(), }); expect(canSkipUpdate).toBe(false); @@ -243,7 +243,7 @@ describe('canSkipSourceUpdate', () => { source: queryAwareSourceMock, prevDataRequest, nextMeta, - considerSpatialParameters: true, + extentAware: queryAwareSourceMock.isFilterByMapBounds(), }); expect(canSkipUpdate).toBe(false); @@ -263,7 +263,7 @@ describe('canSkipSourceUpdate', () => { source: queryAwareSourceMock, prevDataRequest, nextMeta, - considerSpatialParameters: true, + extentAware: queryAwareSourceMock.isFilterByMapBounds(), }); expect(canSkipUpdate).toBe(false); @@ -280,7 +280,7 @@ describe('canSkipSourceUpdate', () => { source: queryAwareSourceMock, prevDataRequest, nextMeta, - considerSpatialParameters: true, + extentAware: queryAwareSourceMock.isFilterByMapBounds(), }); expect(canSkipUpdate).toBe(false); diff --git a/x-pack/plugins/maps/public/classes/util/can_skip_fetch.ts b/x-pack/plugins/maps/public/classes/util/can_skip_fetch.ts index f696d59eb186b..575c99432f508 100644 --- a/x-pack/plugins/maps/public/classes/util/can_skip_fetch.ts +++ b/x-pack/plugins/maps/public/classes/util/can_skip_fetch.ts @@ -55,16 +55,15 @@ export async function canSkipSourceUpdate({ source, prevDataRequest, nextMeta, - considerSpatialParameters, + extentAware, }: { source: ISource; prevDataRequest: DataRequest | undefined; nextMeta: DataMeta; - considerSpatialParameters: boolean; + extentAware: boolean; }): Promise { const timeAware = await source.isTimeAware(); const refreshTimerAware = await source.isRefreshTimerAware(); - const extentAware = source.isFilterByMapBounds(); const isFieldAware = source.isFieldAware(); const isQueryAware = source.isQueryAware(); const isGeoGridPrecisionAware = source.isGeoGridPrecisionAware(); @@ -72,10 +71,10 @@ export async function canSkipSourceUpdate({ if ( !timeAware && !refreshTimerAware && - !(extentAware && considerSpatialParameters) && + !extentAware && !isFieldAware && !isQueryAware && - !(isGeoGridPrecisionAware && considerSpatialParameters) + !isGeoGridPrecisionAware ) { return !!prevDataRequest && prevDataRequest.hasDataOrRequestInProgress(); } @@ -136,14 +135,12 @@ export async function canSkipSourceUpdate({ let updateDueToPrecisionChange = false; let updateDueToExtentChange = false; - if (considerSpatialParameters) { - if (isGeoGridPrecisionAware) { - updateDueToPrecisionChange = !_.isEqual(prevMeta.geogridPrecision, nextMeta.geogridPrecision); - } + if (isGeoGridPrecisionAware) { + updateDueToPrecisionChange = !_.isEqual(prevMeta.geogridPrecision, nextMeta.geogridPrecision); + } - if (extentAware) { - updateDueToExtentChange = updateDueToExtent(prevMeta, nextMeta); - } + if (extentAware) { + updateDueToExtentChange = updateDueToExtent(prevMeta, nextMeta); } const updateDueToSourceMetaChange = !_.isEqual(prevMeta.sourceMeta, nextMeta.sourceMeta); From 7d2195f5d16733eeb6c362c3c66f920828e23e43 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 11 Mar 2021 11:08:18 -0500 Subject: [PATCH 5/5] remove crufty stub --- .../tiled_vector_layer.test.tsx | 55 ++++++------------- 1 file changed, 16 insertions(+), 39 deletions(-) diff --git a/x-pack/plugins/maps/public/classes/layers/tiled_vector_layer/tiled_vector_layer.test.tsx b/x-pack/plugins/maps/public/classes/layers/tiled_vector_layer/tiled_vector_layer.test.tsx index 39d24f3559a84..01902d1fec89d 100644 --- a/x-pack/plugins/maps/public/classes/layers/tiled_vector_layer/tiled_vector_layer.test.tsx +++ b/x-pack/plugins/maps/public/classes/layers/tiled_vector_layer/tiled_vector_layer.test.tsx @@ -116,55 +116,37 @@ describe('syncData', () => { }); it('Should not resync when no changes to source params', async () => { - const layer1: TiledVectorLayer = createLayer({}, {}); - const syncContext1 = new MockSyncContext({ dataFilters: {} }); - - await layer1.syncData(syncContext1); - const dataRequestDescriptor: DataRequestDescriptor = { data: { ...defaultConfig }, dataId: 'source', }; - const layer2: TiledVectorLayer = createLayer( + const layer: TiledVectorLayer = createLayer( { __dataRequests: [dataRequestDescriptor], }, {} ); - const syncContext2 = new MockSyncContext({ dataFilters: {} }); - await layer2.syncData(syncContext2); + const syncContext = new MockSyncContext({ dataFilters: {} }); + await layer.syncData(syncContext); // @ts-expect-error - sinon.assert.notCalled(syncContext2.startLoading); + sinon.assert.notCalled(syncContext.startLoading); // @ts-expect-error - sinon.assert.notCalled(syncContext2.stopLoading); + sinon.assert.notCalled(syncContext.stopLoading); }); it('Should resync when changes to syncContext', async () => { - const layer1: TiledVectorLayer = createLayer({}, {}, true); - const syncContext1 = new MockSyncContext({ - dataFilters: { - timeFilters: { - from: 'now', - to: '15m', - mode: 'relative', - }, - }, - }); - - await layer1.syncData(syncContext1); - const dataRequestDescriptor: DataRequestDescriptor = { data: { ...defaultConfig }, dataId: 'source', }; - const layer2: TiledVectorLayer = createLayer( + const layer: TiledVectorLayer = createLayer( { __dataRequests: [dataRequestDescriptor], }, {}, true ); - const syncContext2 = new MockSyncContext({ + const syncContext = new MockSyncContext({ dataFilters: { timeFilters: { from: 'now', @@ -173,41 +155,36 @@ describe('syncData', () => { }, }, }); - await layer2.syncData(syncContext2); + await layer.syncData(syncContext); // @ts-expect-error - sinon.assert.calledOnce(syncContext2.startLoading); + sinon.assert.calledOnce(syncContext.startLoading); // @ts-expect-error - sinon.assert.calledOnce(syncContext2.stopLoading); + sinon.assert.calledOnce(syncContext.stopLoading); }); describe('Should resync when changes to source params: ', () => { [{ layerName: 'barfoo' }, { minSourceZoom: 1 }, { maxSourceZoom: 12 }].forEach((changes) => { it(`change in ${Object.keys(changes).join(',')}`, async () => { - const layer1: TiledVectorLayer = createLayer({}, {}); - const syncContext1 = new MockSyncContext({ dataFilters: {} }); - - await layer1.syncData(syncContext1); - const dataRequestDescriptor: DataRequestDescriptor = { data: defaultConfig, dataId: 'source', }; - const layer2: TiledVectorLayer = createLayer( + const layer: TiledVectorLayer = createLayer( { __dataRequests: [dataRequestDescriptor], }, changes ); - const syncContext2 = new MockSyncContext({ dataFilters: {} }); - await layer2.syncData(syncContext2); + const syncContext = new MockSyncContext({ dataFilters: {} }); + await layer.syncData(syncContext); // @ts-expect-error - sinon.assert.calledOnce(syncContext2.startLoading); + sinon.assert.calledOnce(syncContext.startLoading); // @ts-expect-error - sinon.assert.calledOnce(syncContext2.stopLoading); + sinon.assert.calledOnce(syncContext.stopLoading); // @ts-expect-error - const call = syncContext2.stopLoading.getCall(0); + const call = syncContext.stopLoading.getCall(0); expect(call.args[2]).toEqual({ ...defaultConfig, ...changes }); }); });