No-op a null tag merge

Reduces unnecessary node churn in Connect action.
This commit is contained in:
John Firebaugh
2013-03-12 16:22:10 -07:00
parent 4fa88acc85
commit 4720a84d38
2 changed files with 16 additions and 8 deletions
+7 -5
View File
@@ -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) {
+9 -3
View File
@@ -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);
});