Files
python-fun/domain/framework/entity.py

19 lines
475 B
Python

from abc import ABC
from dataclasses import replace
from typing import Self
from domain.marketplace.domain_event import DomainEvent
class Entity(ABC):
_events: tuple[DomainEvent, ...] = ()
def raise_event(self, event: DomainEvent) -> Self:
return replace(self, _events=(*self._events, event))
def get_changes(self) -> tuple[DomainEvent, ...]:
return self._events
def clear_changes(self) -> Self:
return replace(self, _events=())