code: def apply_delta(self, delta):
          
          history = (
              self.state
              .setdefault(delta.entity, {})
              .setdefault(delta.get_id(), collections.deque())
          )
  
          history.append(delta.data)
          if delta.type == 'remove':
              history.append(None)
  
          entity = self.get_entity(delta.entity, delta.get_id())
          return entity.previous(), entity
docs: Apply delta to our state and return a copy of the
          affected object as it was before and after the update, e.g.:
  
              old_obj, new_obj = self.apply_delta(delta)
  
          old_obj may be None if the delta is for the creation of a new object,
          e.g. a new application or unit is deployed.
  
          new_obj will never be None, but may be dead (new_obj.dead == True)
          if the object was deleted as a result of the delta being applied.