Li.Publisher Class
Base class for Publishers.
This class helps you to achieve the Observer (also known as publisher-subscriber) design pattern.
Your class prototype may have a property named 'eventTypes' which is a list (i.e array) of eventTypes that the class as a publisher would/can trigger.
Item Index
Methods
Methods
relayEvents
-
publisher
-
eventTypes
This function listens to a given publisher on the given event types, and refires the events from itself (scope of the event fired would be this object). This useful for chaining events.
Parameters:
-
publisher
Li.PublisherA publisher instance.
-
eventTypes
Array | NullEvent types to listen on. If eventType is null, it listens to all events of the publisher.
subscribe
-
object
-
handler
-
scope
Adds a listener. If no parameters are specified, then this would re-enable events that were switched off by publisher.unsubscribe();
Parameters:
-
object
String | ObjectThe event type that you want to listen to as string. Or an object with event types and handlers as key-value pairs (with event type as the keys). You can also subscribe for an event that has not yet been registered as an event. Hence the order of registeration is not a concern.
-
handler
FunctionFunction that gets notfied when a event of 'eventType' gets fired. This param is used only when eventType is a string.
-
scope
ObjectThe context in which the function should be called.
Returns:
trigger
-
eventType
-
...
Call all events listeners for the given event name.
Parameters:
-
eventType
String -
...
Anyn number of arguments. These shall be directly passed onto the event listeners.
unsubscribe
-
uuidORfunc
Remove an event listener. If no parameters are specified, then all events are switched off till you call publisher.subscribe().
Parameters:
-
uuidORfunc
String | FunctionCan be the event listener as a Function object, OR the UUID returned by 'subscribe' function can also be used.