Class Notifier |
Events is a class object that is capable of sending events to listeners that want to be informed when something of interest happens. Events informs its listeners of an event via one of the notification methods: notify() or notifyAll(). Listeners can be class instances, procedures, or co-expressions. If the listener is a class object then the name of the method to invoke can be provided or left to default to "callback" Each listener is passed the name of the Notifier subclass sending the event, the event type (an arbitrary string), and a message. If omitted, the event type defaults to "default.
Some of the internal code here is, uh, adapted from the
Connectable class. There are differences in the behavior
between Notifier and Connectable, however.
In particular:
-- Notifier enforces a default event type.
-- Connectable accepts a null event type whose listeners are always
notified on any event. Notifier doesn't.
-- listeners are passed the name of the source Notifier that invokes them.
-- Connectable only accepts class instance listeners at this time while
Notifier additionally accepts procedure and co-expression listeners.
Details |
Constructor |
Methods: |
addListener(listener, typ:"default", methodname:"callback")
listener | class, callback procedure, or co-expression |
typ | type (string) of event to respond to (defaults to "default") |
methodname | if listener is a class then name of method to invoke
(defaults to "callback") |
if listener cannot be added |
Adds a listener to this class, can be called with one, two, or three arguments.
Add a listener. Internal use only! <[/p>
connect(obj, meth_name:"callback", typ:"default")
Create and connect a Subscription to this object. Internal use only! <[/p>
Remove a Subscription object Internal use only! <[/p>
Generate all listeners regardless of their event type.
Generate all listeners of a given event type. <[ram typ -- event type of interest. (Defaults to "default").
notify(typ:"default", message:"")
typ | event type (defaults to "default") |
message | message to pass to callback (defaults to empty string) |
Notifies all callbacks with the given type.
Passes the name of the calling class (a subclass of Notifier)
If a callback is a procedure (or a string) it is called with
l | listener to notify |
message | message to pass to listener's callback |
Notify a specific listener. Internal use only!
message | message to pass to each callback |
Behaves like notify, but notifies all listeners, regardless of their type.
lRec | listener class to notify. |
message | message to pass to callback. |
Invoke a callback method from a Listener subclass.
Internal use only!
This method is intended for internal use, but can be
overridden by subclasses that want to invoke callback
Listener subclasses with different arguments.
Remove all listeners regardless of their typ
removeListener(listener, typ:"default", methodname:"callback")
listener | class, callback procedure, or co-expression |
typ | type (string) of event to respond to (defaults to "default") |
methodname | if listener is a class then name of method to invoke
(defaults to "callback") |
if typ/listener/methodname not present |
Remove a listener. Removes all occurences of typ/listener/methodname.
removeListeners(typ:"default")
typ | event type (defaults to "default") |
Removes all listeners with the specified event type
Fields: |