forked from p34709852/monkey
Common: Accept Union[str, Type[AbstractEvent]] in EventSerializerRegistry
This commit is contained in:
parent
23604009a0
commit
a32d9359b0
|
@ -1,17 +1,21 @@
|
|||
from typing import Type, Union
|
||||
|
||||
from common.event_serializers import IEventSerializer
|
||||
from common.events import AbstractEvent
|
||||
|
||||
|
||||
class EventSerializerRegistry:
|
||||
"""
|
||||
Registry for event serializers
|
||||
Registry for event serializers using event class.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self._registry = {}
|
||||
|
||||
def __setitem__(self, event_class_name: str, event_serializer: IEventSerializer):
|
||||
self._registry[event_class_name] = event_serializer
|
||||
def __setitem__(
|
||||
self, event_class: Union[str, Type[AbstractEvent]], event_serializer: IEventSerializer
|
||||
):
|
||||
self._registry[event_class] = event_serializer
|
||||
|
||||
def __getitem__(self, event_class_name: str):
|
||||
event_serializer = self._registry[event_class_name]
|
||||
return event_serializer
|
||||
def __getitem__(self, event_class: Union[str, Type[AbstractEvent]]):
|
||||
return self._registry[event_class]
|
||||
|
|
Loading…
Reference in New Issue