28 lines
798 B
Python
28 lines
798 B
Python
# app/src/core/event_bus.py
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
|
|
class EventBus:
|
|
_version: int = 0
|
|
_last_event_type: str | None = None
|
|
_last_payload: dict[str, Any] = {}
|
|
|
|
# зафиксировать важное событие системы
|
|
@classmethod
|
|
def emit(cls, event_type: str, payload: dict[str, Any] | None = None) -> None:
|
|
cls._version += 1
|
|
cls._last_event_type = event_type
|
|
cls._last_payload = payload or {}
|
|
|
|
# текущая версия событий
|
|
@classmethod
|
|
def version(cls) -> int:
|
|
return cls._version
|
|
|
|
# последнее событие
|
|
@classmethod
|
|
def last_event(cls) -> tuple[str | None, dict[str, Any]]:
|
|
return cls._last_event_type, dict(cls._last_payload) |