Prevent unnecessary reloading of raw tag editor (close #7248)

This commit is contained in:
Quincy Morgan
2020-01-18 12:30:35 -05:00
parent 73e64b2d7e
commit 721ee0e95f
4 changed files with 17 additions and 5 deletions
+3 -2
View File
@@ -7,7 +7,8 @@ import { svgIcon } from '../svg/icon';
import { uiCombobox } from './combobox';
import { uiDisclosure } from './disclosure';
import { uiTagReference } from './tag_reference';
import { utilArrayDifference, utilGetSetValue, utilNoAuto, utilRebind, utilTagDiff } from '../util';
import { utilArrayDifference, utilArrayIdentical } from '../util/array';
import { utilGetSetValue, utilNoAuto, utilRebind, utilTagDiff } from '../util';
export function uiRawTagEditor(context) {
@@ -609,7 +610,7 @@ export function uiRawTagEditor(context) {
rawTagEditor.entityIDs = function(val) {
if (!arguments.length) return _entityIDs;
if (_entityIDs !== val) {
if (!_entityIDs || !val || !utilArrayIdentical(_entityIDs, val)) {
_entityIDs = val;
_orderedKeys = [];
}
+3 -3
View File
@@ -8,7 +8,7 @@ import {
event as d3_event,
selectAll as d3_selectAll
} from 'd3-selection';
import { utilArrayIdentical } from '../util/array';
import { osmEntity, osmNote, qaError } from '../osm';
import { services } from '../services';
import { uiDataEditor } from './data_editor';
@@ -167,7 +167,7 @@ export function uiSidebar(context) {
.classed('inspector-hidden', false)
.classed('inspector-hover', true);
if (inspector.entityIDs() !== [datum.id] || inspector.state() !== 'hover') {
if (!inspector.entityIDs() || !utilArrayIdentical(inspector.entityIDs(), [datum.id]) || inspector.state() !== 'hover') {
inspector
.state('hover')
.entityIDs([datum.id]);
@@ -225,7 +225,7 @@ export function uiSidebar(context) {
.classed('inspector-hidden', false)
.classed('inspector-hover', false);
if (inspector.entityIDs() !== ids || inspector.state() !== 'select') {
if (!inspector.entityIDs() || !utilArrayIdentical(inspector.entityIDs(), ids) || inspector.state() !== 'select') {
inspector
.state('select')
.entityIDs(ids)
+10
View File
@@ -1,4 +1,14 @@
// Returns true if a and b have the same elements at the same indices.
export function utilArrayIdentical(a, b) {
var i = a.length;
if (i !== b.length) return false;
while (i--) {
if (a[i] !== b[i]) return false;
}
return true;
}
// http://2ality.com/2015/01/es6-set-operations.html
// Difference (a \ b): create a set that contains those elements of set a that are not in set b.
+1
View File
@@ -2,6 +2,7 @@ export { utilArrayChunk } from './array';
export { utilArrayDifference } from './array';
export { utilArrayFlatten } from './array';
export { utilArrayGroupBy } from './array';
export { utilArrayIdentical } from './array';
export { utilArrayIntersection } from './array';
export { utilArrayUnion } from './array';
export { utilArrayUniq } from './array';