Class Event
The Event class, with the EventConnection class, is used to mimic the structure of ROBLOX's Events.
It follows the observer pattern and can be used to send a variable number of arguments to observing functions. For an example of using an Event Property in a class, see event.moon.
Info:
- License: MIT
- Author: Richard Voelker
Methods
Event.new (self) | Create a new Event. |
Event.connect (self, observer) | Add an observer to wait for a notification. |
Event.notifyObservers (self, ...) | Notifies all connected observers and calls their callback functions. |
Event.removeObserver (self, id) | Remove an observer from this Event so it's callback won't be called anymore. |
Methods
- Event.new (self)
-
Create a new Event.
Parameters:
- self Event
- Event.connect (self, observer)
-
Add an observer to wait for a notification. An
EventConnection is returned so that the observer can be
removed later if desired.
Parameters:
- self Event
- observer
function
A function which will be called
when all observers are notified of an event.
Returns:
-
EventConnection
An EventConnection class with
the callback function.
- Event.notifyObservers (self, ...)
-
Notifies all connected observers and calls their callback
functions.
Parameters:
- self Event
- ... The arguments to pass to the observer.
- Event.removeObserver (self, id)
-
Remove an observer from this Event so it's callback won't be
called anymore.
Parameters:
- self Event
- id int The Id for the observer.