on method
- String event,
- Object context,
- EventCallback callback
API to register for notification.
It is mandatory to pass event name and callback parameters.
event
- Event name used for the subscription. A valid event name is mandatory.
context
- Context information, which need to be sent in all emitted events.
callback
- EventCallback function registered to receive events emitted from the publisher. A valid callback function is mandatory.
Implementation
Listener on(String event, Object context, EventCallback callback) {
if (null == event || event.trim().isEmpty) {
throw ArgumentError.notNull("event");
}
if (null == callback) {
throw ArgumentError.notNull("callback");
}
// Check if the particular listener is there in the listeners collection
// Return the listener instance, if already registered.
Set<Listener> subs =
this._listeners.putIfAbsent(event, () => Set<Listener>());
// Create new element.
Listener listener = Listener.Default(event, context, callback);
listener._cancelCallback = () {
this._removeListener(listener);
};
subs.add(listener);
return listener;
}