mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-14 13:18:15 +02:00
Graph#difference
This commit is contained in:
@@ -81,6 +81,24 @@ iD.Graph.prototype = {
|
||||
return iD.Entity(entity, {nodes: nodes});
|
||||
},
|
||||
|
||||
difference: function (graph) {
|
||||
var result = [];
|
||||
|
||||
_.each(this.entities, function(entity, id) {
|
||||
if (entity !== graph.entities[id]) {
|
||||
result.push(id);
|
||||
}
|
||||
});
|
||||
|
||||
_.each(graph.entities, function(entity, id) {
|
||||
if (entity && !this.entities.hasOwnProperty(id)) {
|
||||
result.push(id);
|
||||
}
|
||||
}, this);
|
||||
|
||||
return result.sort();
|
||||
},
|
||||
|
||||
modified: function() {
|
||||
var result = [];
|
||||
_.each(this.entities, function(entity, id) {
|
||||
|
||||
@@ -93,6 +93,25 @@ describe('iD.Graph', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe("#difference", function () {
|
||||
it("returns an Array of ids of changed entities", function () {
|
||||
var initial = iD.Node({id: "n1"}),
|
||||
updated = initial.update({}),
|
||||
created = iD.Node(),
|
||||
deleted = iD.Node({id: 'n2'}),
|
||||
graph1 = iD.Graph([initial, deleted]),
|
||||
graph2 = graph1.replace(updated).replace(created).remove(deleted);
|
||||
expect(graph2.difference(graph1)).to.eql([created.id, updated.id, deleted.id]);
|
||||
});
|
||||
|
||||
it("includes created entities that were subsequently deleted", function () {
|
||||
var node = iD.Node(),
|
||||
graph1 = iD.Graph([node]),
|
||||
graph2 = graph1.remove(node);
|
||||
expect(graph2.difference(graph1)).to.eql([node.id]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#modified", function () {
|
||||
it("returns an Array of ids of modified entities", function () {
|
||||
var node1 = iD.Node({id: 'n1', _updated: true}),
|
||||
|
||||
Reference in New Issue
Block a user