MapObjectUpdates<T extends MapObject>.from constructor
MapObjectUpdates<T extends MapObject>.from(
- Set<T> previous,
- Set<T> current
)
Implementation
MapObjectUpdates.from(this.previous, this.current) {
final previousObjects = Map<MapObjectId, T>.fromEntries(
previous.map((T object) => MapEntry(object.mapId, object))
);
final currentObjects = Map<MapObjectId, T>.fromEntries(
current.map((T object) => MapEntry(object.mapId, object))
);
final previousObjectIds = previousObjects.keys.toSet();
final currentObjectIds = currentObjects.keys.toSet();
_objectsToRemove = previousObjectIds
.difference(currentObjectIds)
.map((MapObjectId id) => previousObjects[id]!).
toSet();
_objectsToAdd = currentObjectIds
.difference(previousObjectIds)
.map((MapObjectId id) => currentObjects[id]!)
.toSet();
_objectsToChange = currentObjectIds
.intersection(previousObjectIds)
.map((MapObjectId id) => currentObjects[id]!)
.where((T current) => current != previousObjects[current.mapId])
.toSet();
}