Class Notifier

Summary

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.

Superclasses:
Object

Package:
util
File:
notifier.icn
Methods:
addListener, addToListeners, connect, disconnect, genAllListeners, genListeners, notify, notify1, notifyAll, notifyClass, removeAllListeners, removeListener, removeListeners

Methods inherited from Object:
Type, className, clone, equals, fieldNames, genMethods, getField, get_class, get_class_name, get_id, hasField, hasMethod, hash_code, instanceOf, invoke, is_instance, setField, to_string

Fields:
listeners

Source code.

Details
Constructor

Notifier(listeners)

Methods:

addListener(listener, typ:"default", methodname:"callback")

Parameters:
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")
Fails:
if listener cannot be added

Adds a listener to this class, can be called with one, two, or three arguments.


addToListeners(l)

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>


disconnect(l)

Remove a Subscription object Internal use only! <[/p>


genAllListeners()

Generate all listeners regardless of their event type.


genListeners(typ:"default")

Generate all listeners of a given event type. <[ram typ -- event type of interest. (Defaults to "default").


notify(typ:"default", message:"")

Parameters:
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 (self_name, type, message). If a callback is a co-expression it is called with [self_name, type, message] @ , If a callback is a class, then an attempt is made to invoke the callback method as .(self_name, type, message).


notify1(l, message)

Parameters:
l
listener to notify
message
message to pass to listener's callback

Notify a specific listener. Internal use only!


notifyAll(message)

Parameter:
message
message to pass to each callback

Behaves like notify, but notifies all listeners, regardless of their type.


notifyClass(lRec, message)

Parameters:
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.


removeAllListeners()

Remove all listeners regardless of their typ


removeListener(listener, typ:"default", methodname:"callback")

Parameters:
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")
Fails:
if typ/listener/methodname not present

Remove a listener. Removes all occurences of typ/listener/methodname.


removeListeners(typ:"default")

Parameter:
typ
event type (defaults to "default")

Removes all listeners with the specified event type


Fields:
listeners


This page produced by UniDoc on 2021/04/15 @ 23:59:53.