Common: Improve readability in PyPubSubEventQueue

This commit is contained in:
Mike Salvatore 2022-08-10 08:55:09 -04:00
parent 7bbecc4d3f
commit 1d7b498290
1 changed files with 4 additions and 8 deletions

View File

@ -21,8 +21,7 @@ class PyPubSubEventQueue(IEventQueue):
self, event_type: AbstractEvent, subscriber: Callable[[AbstractEvent], None] self, event_type: AbstractEvent, subscriber: Callable[[AbstractEvent], None]
): ):
# pypubsub.pub.subscribe needs a string as the topic/event name # pypubsub.pub.subscribe needs a string as the topic/event name
event_type_name = event_type.__name__ self._pypubsub_publisher.subscribe(listener=subscriber, topicName=event_type.__name__)
self._pypubsub_publisher.subscribe(listener=subscriber, topicName=event_type_name)
def subscribe_all_event_types(self, subscriber: Callable[[AbstractEvent], None]): def subscribe_all_event_types(self, subscriber: Callable[[AbstractEvent], None]):
self._pypubsub_publisher.subscribe( self._pypubsub_publisher.subscribe(
@ -33,15 +32,12 @@ class PyPubSubEventQueue(IEventQueue):
self._pypubsub_publisher.subscribe(listener=subscriber, topicName=tag) self._pypubsub_publisher.subscribe(listener=subscriber, topicName=tag)
def publish(self, event: AbstractEvent): def publish(self, event: AbstractEvent):
event_data = {"event": event}
# publish to event type's topic # publish to event type's topic
event_type_name = event.__name__ self._pypubsub_publisher.sendMessage(event.__name__, event=event)
self._pypubsub_publisher.sendMessage(event_type_name, **event_data)
# publish to all events' topic # publish to all events' topic
self._pypubsub_publisher.sendMessage(INTERNAL_ALL_EVENT_TYPES_TOPIC, **event_data) self._pypubsub_publisher.sendMessage(INTERNAL_ALL_EVENT_TYPES_TOPIC, event=event)
# publish to tags' topics # publish to tags' topics
for tag in event.tags: for tag in event.tags:
self._pypubsub_publisher.sendMessage(tag, **event_data) self._pypubsub_publisher.sendMessage(tag, event=event)