def add_subscriber(self, obj, name, entity):
"""
:param object obj: Object to be called when the event fires
:param str|Enum name: Name of the event. May be a string-valued enum.
:param entity: If ``None``, receive all events regardless of their entity.
Otherwise, only receive events whose entity ``is`` this
object.
Store ``(obj, entity)`` as a subscriber for the event *name*. When
:py:meth:`fire` is called with a pattern that matches ``(obj, entity)``,
call ``obj.on_[name](Event(name, entity, data))``.
An event is said to "match" a subscription if the subscription has the same
event name, and either the subscriber's entity is ``None``, or the
subscriber's entity ``is`` the event's entity.
You may subscribe more than once to receive the event multiple times.
"""
if isinstance(name, Enum):
name = name.value
self.handlers[name].append((obj, entity))
评论列表
文章目录