Metadata-Version: 2.4
Name: ondosense-eventhandling
Version: 0.1.2
Summary: Basic Event Handling System
Author-email: Ruben Rögels <rroegels@ondosense.com>
Maintainer-email: Ruben Rögels <rroegels@ondosense.com>
License-Expression: MIT
Project-URL: Homepage, https://www.ondosense.com
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Classifier: Natural Language :: English
Classifier: Typing :: Typed
Requires-Python: >=3.11
Description-Content-Type: text/markdown

# ondosense-eventhandling

`ondosense-eventhandling` provides a basic implementation for event handling.

# Example Usage

~~~python
from ondosense.eventhandling import Event, EventDispatcher, EventSubscriber
from typing import List, Tuple

class SendGreetingsEvent(Event):
    name = 'greeting'
    _message: str = 'Hello World!'

    @property
    def message(self) -> str:
        return self._message

class GreetingSubscriber(EventSubscriber):

    def get_subscribed_events(self) -> dict[str, List[Tuple[str, int]]]:
        return {
            SendGreetingsEvent.name: [
                ('send_simple_greetings', 10),
                ('send_important_greetings', 20),
            ],
        }

    def send_simple_greetings(self, event: SendGreetingsEvent) -> None:
        print(event.message)

    def send_important_greetings(self, event: SendGreetingsEvent) -> None:
        important_message = f"!!! {event.message} !!!"
        important_message_length = len(important_message)
        print("!" * important_message_length)
        print(important_message)
        print("!" * important_message_length)

(
    EventDispatcher()
    .add_subscriber(GreetingSubscriber())
    .dispatch(SendGreetingsEvent())
)
~~~
