forked from p15670423/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.event_serializers import IEventSerializer
|
||||||
|
from common.events import AbstractEvent
|
||||||
|
|
||||||
|
|
||||||
class EventSerializerRegistry:
|
class EventSerializerRegistry:
|
||||||
"""
|
"""
|
||||||
Registry for event serializers
|
Registry for event serializers using event class.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._registry = {}
|
self._registry = {}
|
||||||
|
|
||||||
def __setitem__(self, event_class_name: str, event_serializer: IEventSerializer):
|
def __setitem__(
|
||||||
self._registry[event_class_name] = event_serializer
|
self, event_class: Union[str, Type[AbstractEvent]], event_serializer: IEventSerializer
|
||||||
|
):
|
||||||
|
self._registry[event_class] = event_serializer
|
||||||
|
|
||||||
def __getitem__(self, event_class_name: str):
|
def __getitem__(self, event_class: Union[str, Type[AbstractEvent]]):
|
||||||
event_serializer = self._registry[event_class_name]
|
return self._registry[event_class]
|
||||||
return event_serializer
|
|
||||||
|
|
Loading…
Reference in New Issue