mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-14 09:42:56 +00:00
35 lines
975 B
JavaScript
35 lines
975 B
JavaScript
// Like selection.property('value', ...), but avoids no-op value sets,
|
|
// which can result in layout/repaint thrashing in some situations.
|
|
export function getSetValue(target, value) {
|
|
function d3_selection_value(value) {
|
|
function valueNull() {
|
|
delete target.value;
|
|
}
|
|
|
|
function valueConstant() {
|
|
if (target.value !== value) {
|
|
target.value = value;
|
|
}
|
|
}
|
|
|
|
function valueFunction() {
|
|
var x = value.apply(target, arguments);
|
|
if (x == null) {
|
|
delete target.value;
|
|
}
|
|
else if (target.value !== x) {
|
|
target.value = x;
|
|
}
|
|
}
|
|
|
|
return value == null
|
|
? valueNull : (typeof value === 'function'
|
|
? valueFunction : valueConstant);
|
|
}
|
|
|
|
if (!arguments.length) {
|
|
return target.property('value');
|
|
}
|
|
return target.each(d3_selection_value(value));
|
|
}
|