code: def apply(self, event, document, *args, **kwargs):
          
          for fn in self._handler_dict.get(event, []):
              fn(document, *args, **kwargs)
docs: Applies all middleware functions registered against the given
          event in order to the given document.