Skip to content

Commit e8b57c8

Browse files
committed
refactor(range): remove stringify usage
1 parent 8ed08fc commit e8b57c8

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

core/src/components/range/range.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,9 @@ export class Range implements ComponentInterface {
213213
*/
214214
@Prop({ mutable: true }) value: RangeValue = 0;
215215
@Watch('value')
216-
protected valueChanged(newVlue: RangeValue, oldValue: RangeValue) {
217-
// The check is necessary because the value can be an object.
218-
if (JSON.stringify(newVlue) !== JSON.stringify(oldValue)) {
216+
protected valueChanged(newValue: RangeValue, oldValue: RangeValue) {
217+
const valuesChanged = this.areValuesDifferent(newValue, oldValue);
218+
if (valuesChanged) {
219219
this.ionInput.emit({ value: this.value });
220220
}
221221

@@ -224,6 +224,21 @@ export class Range implements ComponentInterface {
224224
}
225225
}
226226

227+
/**
228+
* Compares two RangeValue inputs to determine if they are different.
229+
*
230+
* @param newVal - The new value.
231+
* @param oldVal - The old value.
232+
* @returns `true` if the values are different, `false` otherwise.
233+
*/
234+
private areValuesDifferent = (newVal: RangeValue, oldVal: RangeValue) => {
235+
if (typeof newVal === 'object' && typeof oldVal === 'object') {
236+
return newVal.lower !== oldVal.lower || newVal.upper !== oldVal.upper;
237+
}
238+
239+
return newVal !== oldVal;
240+
};
241+
227242
private clampBounds = (value: any): number => {
228243
return clamp(this.min, value, this.max);
229244
};

0 commit comments

Comments
 (0)