mirror of
https://github.com/FoggedLens/iD.git
synced 2026-06-02 13:11:41 +02:00
No-op a null tag merge
Reduces unnecessary node churn in Connect action.
This commit is contained in:
@@ -68,17 +68,19 @@ iD.Entity.prototype = {
|
||||
},
|
||||
|
||||
mergeTags: function(tags) {
|
||||
var merged = _.clone(this.tags);
|
||||
var merged = _.clone(this.tags), changed = false;
|
||||
for (var k in tags) {
|
||||
var t1 = merged[k],
|
||||
t2 = tags[k];
|
||||
if (t1 && t1 !== t2) {
|
||||
merged[k] = _.union(t1.split(/;\s*/), t2.split(/;\s*/)).join(';');
|
||||
} else {
|
||||
if (!t1) {
|
||||
changed = true;
|
||||
merged[k] = t2;
|
||||
} else if (t1 !== t2) {
|
||||
changed = true;
|
||||
merged[k] = _.union(t1.split(/;\s*/), t2.split(/;\s*/)).join(';');
|
||||
}
|
||||
}
|
||||
return this.update({tags: merged});
|
||||
return changed ? this.update({tags: merged}) : this;
|
||||
},
|
||||
|
||||
intersects: function(extent, resolver) {
|
||||
|
||||
@@ -64,9 +64,15 @@ describe('iD.Entity', function () {
|
||||
});
|
||||
|
||||
describe("#mergeTags", function () {
|
||||
it("returns a new Entity", function () {
|
||||
var a = iD.Entity(),
|
||||
b = a.mergeTags({});
|
||||
it("returns self if unchanged", function () {
|
||||
var a = iD.Entity({tags: {a: 'a'}}),
|
||||
b = a.mergeTags({a: 'a'});
|
||||
expect(a).to.equal(b);
|
||||
});
|
||||
|
||||
it("returns a new Entity if changed", function () {
|
||||
var a = iD.Entity({tags: {a: 'a'}}),
|
||||
b = a.mergeTags({a: 'b'});
|
||||
expect(b instanceof iD.Entity).to.be.true;
|
||||
expect(a).not.to.equal(b);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user