コード例 #1
0
 def modify(self, entity: EntityWrapper) -> None:
     if entity.name not in self.entities_by_name:
         # Not yet in the system, register it with its own id
         return self.add(entity)
     # All the entities expect the one being modified
     self.entities = {e for e in self.entities if e.name != entity.name}
     # Replace always the id with the one registered in the system
     self.entities.add(
         entity.with_id(id=self.entities_by_name[entity.name].id))
コード例 #2
0
def entities_op(entity_set: EntitiesSet, entity: EntityWrapper,
                op: Literal['ADDED', 'DELETED', 'MODIFIED'],
                current_entities: EntitiesSet) -> None:
    # Current state should always contain the real id!!
    cached_entity = current_entities.entities_by_name.get(entity.name)
    if cached_entity:
        entity = entity.with_id(id=cached_entity.id)
    if op == 'ADDED':
        entity_set.add(entity)
    elif op == 'DELETED':
        entity_set.delete(entity)
    elif op == 'MODIFIED':
        entity_set.modify(entity)