Module jls.util.EventPublisher
Provide EventPublisher class.
Class EventPublisher
EventPublisher:new () | Creates a new EventPublisher. |
eventPublisher:unsubscribeAllEvents () | Unsubscribes all the events. |
eventPublisher:subscribeEvent (name, fn) | Subscribes to the specified event name with the specified function. |
eventPublisher:unsubscribeEvent (name, key) | Unsubscribes the specified event name. |
eventPublisher:publishEvent (name) | Publishes the specified event name. |
Class EventPublisher
The EventPublisher class.
The EventPublisher provides a way subsribe and publish events.
- EventPublisher:new ()
-
Creates a new EventPublisher.
Returns:
-
a new EventPublisher
- eventPublisher:unsubscribeAllEvents ()
- Unsubscribes all the events.
- eventPublisher:subscribeEvent (name, fn)
-
Subscribes to the specified event name with the specified function.
Registers an event handler/listener
Parameters:
- name string the event name
- fn function the function to call when the event is published
Returns:
-
an opaque key that could be used to unsubscribe
- eventPublisher:unsubscribeEvent (name, key)
-
Unsubscribes the specified event name.
Parameters:
- name string the event name
- key the subscribed key
- eventPublisher:publishEvent (name)
-
Publishes the specified event name.
Fires an event
Parameters:
- name string the event name
Returns:
-
boolean
true if the event had subscriptions, false otherwise