Coverage for src/ipyvizzu/event.py: 100%
15 statements
« prev ^ index » next coverage.py v7.4.3, created at 2024-02-26 10:12 +0000
« prev ^ index » next coverage.py v7.4.3, created at 2024-02-26 10:12 +0000
1"""A module for working with JavaScript events"""
3import uuid
6class EventHandler:
7 """A class for representing an event handler."""
9 def __init__(self, event: str, handler: str):
10 """
11 EventHandler constructor.
13 It generates a uuid for the event handler,
14 stores the event type and the body of the handler function.
16 Args:
17 event: The type of the event.
18 handler: The body of the handler function.
19 """
21 self._id = uuid.uuid4().hex[:7]
22 self._event = event
23 self._handler = " ".join(handler.split())
25 @property
26 def id(self) -> str: # pylint: disable=invalid-name
27 """
28 A property for storing an id.
30 Returns:
31 The uuid of the event handler.
32 """
34 return self._id
36 @property
37 def event(self) -> str:
38 """
39 A property for storing an event type.
41 Returns:
42 The type of the event.
43 """
45 return self._event
47 @property
48 def handler(self) -> str:
49 """
50 A property for storing an event handler function.
52 Returns:
53 The body of the handler function.
54 """
56 return self._handler