mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-23 08:39:56 +02:00
generalize implementation to skip input value update
when contents are "equivalent" in a given context, e.g. for numeric values with potentially different formatting in number fields
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
// Like selection.property('value', ...), but avoids no-op value sets,
|
||||
// which can result in layout/repaint thrashing in some situations.
|
||||
/** @returns {string} */
|
||||
export function utilGetSetValue(selection, value) {
|
||||
function setValue(value) {
|
||||
export function utilGetSetValue(selection, value, shouldUpdate) {
|
||||
function setValue(value, shouldUpdate) {
|
||||
function valueNull() {
|
||||
delete this.value;
|
||||
}
|
||||
|
||||
function valueConstant() {
|
||||
if (this.value !== value) {
|
||||
if (shouldUpdate(this.value, value)) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ export function utilGetSetValue(selection, value) {
|
||||
var x = value.apply(this, arguments);
|
||||
if (x === null || x === undefined) {
|
||||
delete this.value;
|
||||
} else if (this.value !== x) {
|
||||
} else if (shouldUpdate(this.value, x)) {
|
||||
this.value = x;
|
||||
}
|
||||
}
|
||||
@@ -39,5 +39,9 @@ export function utilGetSetValue(selection, value) {
|
||||
return selection.property('value');
|
||||
}
|
||||
|
||||
return selection.each(stickyCursor(setValue(value)));
|
||||
if (shouldUpdate === undefined) {
|
||||
shouldUpdate = (a, b) => a !== b;
|
||||
}
|
||||
|
||||
return selection.each(stickyCursor(setValue(value, shouldUpdate)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user