Skip to content

Commit

Permalink
Refactored to get event when value is changed directly
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeTschudi committed Dec 29, 2023
1 parent ec212e2 commit cd6cd7a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
17 changes: 13 additions & 4 deletions src/components/spatial-ref/spatial-ref.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

//--------------------------------------------------------------------------
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit cd6cd7a

Please sign in to comment.