mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-24 00:54:03 +02:00
Extract Entity#created and Entity#modified
This commit is contained in:
@@ -64,7 +64,7 @@ iD.modes.AddRoad = {
|
||||
tags: {
|
||||
highway: 'residential'
|
||||
},
|
||||
modified: true,
|
||||
_updated: true,
|
||||
id: iD.Util.id('way')
|
||||
});
|
||||
},
|
||||
@@ -184,7 +184,7 @@ iD.modes.AddArea = {
|
||||
tags: {
|
||||
building: 'yes'
|
||||
},
|
||||
modified: true,
|
||||
_updated: true,
|
||||
id: iD.Util.id('way')
|
||||
});
|
||||
},
|
||||
|
||||
@@ -4,7 +4,7 @@ iD.Entity = function(a, b) {
|
||||
_.extend(this, {tags: {}}, a, b);
|
||||
|
||||
if (b) {
|
||||
this.modified = true;
|
||||
this._updated = true;
|
||||
}
|
||||
|
||||
if (iD.debug) {
|
||||
@@ -16,5 +16,13 @@ iD.Entity = function(a, b) {
|
||||
iD.Entity.prototype = {
|
||||
update: function(attrs) {
|
||||
return iD.Entity(this, attrs);
|
||||
},
|
||||
|
||||
created: function() {
|
||||
return this._updated && +this.id.slice(1) < 0;
|
||||
},
|
||||
|
||||
modified: function() {
|
||||
return this._updated && +this.id.slice(1) > 0;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -91,15 +91,10 @@ iD.Graph.prototype = {
|
||||
},
|
||||
|
||||
modifications: function() {
|
||||
return _.filter(this.entities, function(entity) {
|
||||
return ((+entity.id.slice(1) > 0)) && entity.modified;
|
||||
});
|
||||
return _.filter(this.entities, function(entity) { return entity.modified(); });
|
||||
},
|
||||
|
||||
creations: function() {
|
||||
return _.filter(this.entities, function(entity) {
|
||||
return ((+entity.id.slice(1)) < 0) && entity.modified;
|
||||
});
|
||||
return _.filter(this.entities, function(entity) { return entity.created(); });
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
+26
-2
@@ -12,9 +12,33 @@ describe('Entity', function () {
|
||||
e = iD.Entity().update({tags: tags});
|
||||
expect(e.tags).toBe(tags);
|
||||
});
|
||||
});
|
||||
|
||||
it("returns a modified Entity", function () {
|
||||
expect(iD.Entity().update({}).modified).toBeTruthy();
|
||||
describe("#created", function () {
|
||||
it("returns false for an unmodified Entity", function () {
|
||||
expect(iD.Entity().created()).toBeFalsy();
|
||||
});
|
||||
|
||||
it("returns false for a modified Entity with positive ID", function () {
|
||||
expect(iD.Entity({id: 'w1234'}).update({}).created()).toBeFalsy();
|
||||
});
|
||||
|
||||
it("returns true for a modified Entity with negative ID", function () {
|
||||
expect(iD.Entity({id: 'w-1234'}).update({}).created()).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe("#modified", function () {
|
||||
it("returns false for an unmodified Entity", function () {
|
||||
expect(iD.Entity().modified()).toBeFalsy();
|
||||
});
|
||||
|
||||
it("returns true for a modified Entity with positive ID", function () {
|
||||
expect(iD.Entity({id: 'w1234'}).update({}).modified()).toBeTruthy();
|
||||
});
|
||||
|
||||
it("returns false for a modified Entity with negative ID", function () {
|
||||
expect(iD.Entity({id: 'w-1234'}).update({}).modified()).toBeFalsy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -53,4 +53,22 @@ describe('Graph', function() {
|
||||
expect(g2.entity('n-1').lat).toEqual(40);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#modifications", function () {
|
||||
it("filters entities by modified", function () {
|
||||
var a = {modified: function () { return true; }},
|
||||
b = {modified: function () { return false; }},
|
||||
graph = iD.Graph([a, b]);
|
||||
expect(graph.modifications()).toEqual([a]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#creations", function () {
|
||||
it("filters entities by created", function () {
|
||||
var a = {created: function () { return true; }},
|
||||
b = {created: function () { return false; }},
|
||||
graph = iD.Graph([a, b]);
|
||||
expect(graph.creations()).toEqual([a]);
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user