+
+ if (h.version === 2) {
+ var allEntities = {};
+
+ h.entities.forEach(function(entity) {
+ allEntities[iD.Entity.key(entity)] = iD.Entity(entity);
+ });
+
+ stack = h.stack.map(function(d) {
+ var entities = {}, entity;
+
+ d.modified && d.modified.forEach(function(key) {
+ entity = allEntities[key];
+ entities[entity.id] = entity;
+ });
+
+ d.deleted && d.deleted.forEach(function(id) {
+ entities[id] = undefined;
+ });
+
+ return {
+ graph: iD.Graph(stack[0].graph).load(entities),
+ annotation: d.annotation,
+ imageryUsed: d.imageryUsed
+ };
+ });
+ } else { // original version
+ stack = h.stack.map(function(d) {
+ var entities = {};
+
+ for (var i in d.entities) {
+ var entity = d.entities[i];
+ entities[i] = entity === 'undefined' ? undefined : iD.Entity(entity);
+ }
+
+ d.graph = iD.Graph(stack[0].graph).load(entities);
+ return d;
+ });
+ }
+