function EntityTransformer() {
this.previousEntities = new Map();
this.currentEntities = new Map();
}
EntityTransformer.prototype.updateEntities = function(entities) {
this.currentEntities.clear();
entities.forEach(entity => this.currentEntities.set(entity.id, { ...entity }));
this.detectTransformations();
this.previousEntities = new Map(this.currentEntities);
};
EntityTransformer.prototype.detectTransformations = function() {
this.currentEntities.forEach((currentEntity, id) => {
const previousEntity = this.previousEntities.get(id);
if (previousEntity && previousEntity.type !== currentEntity.type) {
this.transferTags(previousEntity, currentEntity);
}
});
};
EntityTransformer.prototype.transferTags = function(previousEntity, currentEntity) {
const combinedTags = new Set([...previousEntity.tags, ...currentEntity.tags]);
currentEntity.tags = [...combinedTags];
};
EntityTransformer.prototype.getCurrentEntities = function() {
return this.currentEntities;
};
EntityTransformer.prototype.getPreviousEntities = function() {
return this.previousEntities;
};