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

1"""A module for working with JavaScript events""" 

2 

3import uuid 

4 

5 

6class EventHandler: 

7 """A class for representing an event handler.""" 

8 

9 def __init__(self, event: str, handler: str): 

10 """ 

11 EventHandler constructor. 

12 

13 It generates a uuid for the event handler, 

14 stores the event type and the body of the handler function. 

15 

16 Args: 

17 event: The type of the event. 

18 handler: The body of the handler function. 

19 """ 

20 

21 self._id = uuid.uuid4().hex[:7] 

22 self._event = event 

23 self._handler = " ".join(handler.split()) 

24 

25 @property 

26 def id(self) -> str: # pylint: disable=invalid-name 

27 """ 

28 A property for storing an id. 

29 

30 Returns: 

31 The uuid of the event handler. 

32 """ 

33 

34 return self._id 

35 

36 @property 

37 def event(self) -> str: 

38 """ 

39 A property for storing an event type. 

40 

41 Returns: 

42 The type of the event. 

43 """ 

44 

45 return self._event 

46 

47 @property 

48 def handler(self) -> str: 

49 """ 

50 A property for storing an event handler function. 

51 

52 Returns: 

53 The body of the handler function. 

54 """ 

55 

56 return self._handler