From ec212e2efd04456f4b45d8defe0324a8c79ea4b6 Mon Sep 17 00:00:00 2001 From: Mike Tschudi Date: Fri, 29 Dec 2023 09:22:34 -0800 Subject: [PATCH 1/2] Fix values sent via spatialReferenceChange event --- src/components/spatial-ref/spatial-ref.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/spatial-ref/spatial-ref.tsx b/src/components/spatial-ref/spatial-ref.tsx index cb1cd7ea5..2df19369d 100644 --- a/src/components/spatial-ref/spatial-ref.tsx +++ b/src/components/spatial-ref/spatial-ref.tsx @@ -61,10 +61,6 @@ export class SpatialRef { @Watch("value") valueChanged(newValue: string): void { - this.spatialReferenceChange.emit({ - oldValue: this.value, - newValue: newValue - }); this._spatialRef = this._createSpatialRefDisplay(newValue); const searchBox = document.getElementById("calcite-sr-search") as HTMLCalciteInputElement; if (searchBox) { @@ -233,6 +229,10 @@ export class SpatialRef { */ protected _setSpatialRef(wkid: string): void { if (this.value !== wkid) { + this.spatialReferenceChange.emit({ + oldValue: this.value, + newValue: wkid + }); this.value = wkid; } } From cd6cd7a6bc8bd9ff034ed6437954fe6ee853fc31 Mon Sep 17 00:00:00 2001 From: Mike Tschudi Date: Fri, 29 Dec 2023 09:49:52 -0800 Subject: [PATCH 2/2] Refactored to get event when value is changed directly --- .../test/solution-spatial-ref.e2e.ts | 3 --- src/components/spatial-ref/spatial-ref.tsx | 17 +++++++++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/components/solution-spatial-ref/test/solution-spatial-ref.e2e.ts b/src/components/solution-spatial-ref/test/solution-spatial-ref.e2e.ts index 10ff721e8..2504985a0 100644 --- a/src/components/solution-spatial-ref/test/solution-spatial-ref.e2e.ts +++ b/src/components/solution-spatial-ref/test/solution-spatial-ref.e2e.ts @@ -41,9 +41,6 @@ describe('solution-spatial-ref', () => { await page.waitForChanges(); await spatial_ref.setProperty('value', newSpatialRef); await page.waitForChanges(); - /* - expect(await spatial_ref.getProperty('value')).toBe(newSpatialRef); - */ const solution_spatial_ref = await page.find('solution-spatial-ref'); expect(await solution_spatial_ref.getProperty('value')).toBe(newSpatialRef); diff --git a/src/components/spatial-ref/spatial-ref.tsx b/src/components/spatial-ref/spatial-ref.tsx index 2df19369d..e8e692549 100644 --- a/src/components/spatial-ref/spatial-ref.tsx +++ b/src/components/spatial-ref/spatial-ref.tsx @@ -67,6 +67,14 @@ export class SpatialRef { searchBox.value = this._srSearchText = ""; } this._clearSelection(); + + if (this._cachedValue !== this.value) { + this.spatialReferenceChange.emit({ + oldValue: this._cachedValue, + newValue: this.value + }); + this._cachedValue = this.value; + } } //-------------------------------------------------------------------------- @@ -113,6 +121,11 @@ export class SpatialRef { // //-------------------------------------------------------------------------- + /** + * Holds a pre-change value of the wkid so that an event can be posted with the cached and new values. + */ + @State() protected _cachedValue = this.defaultWkid.toString(); + /** * Internal representation of component's value for display purposes. */ @@ -229,10 +242,6 @@ export class SpatialRef { */ protected _setSpatialRef(wkid: string): void { if (this.value !== wkid) { - this.spatialReferenceChange.emit({ - oldValue: this.value, - newValue: wkid - }); this.value = wkid; } }