IEventSource
pentaho.lang.IEventSource
The IEventSource
interface represents objects that emit events.
The structure of events
Events are identified by their type and can be "structured" or not.
Structured events go through multiple phases, while unstructured events have no phases (or can be seen to have a single phase).
The following are examples of the phases of hypothetical structured events:
- "before" and "after"
- "capture" and "bubble"
- "init", "success" and "failure"
The order and logic of occurrence of each of the phases is specific to each event and should be documented along with it. The occurrence of event phases can be conditional, and event phases can be synchronous or asynchronous.
Listening to events
Event observers
are maps of event listener functions, one for each relevant phase of an event, and is used to register for the emissions of a structured event.
Event listener functions, which can be synchronous
or asynchronous
, are used to register for the emissions of an unstructured event.
The listener functions are called with a single object
argument, that represents the specific event emission. The specific type of this argument is not mandated, however, the provided Event
class is a reasonable choice for unstructured events, and is used for events of many of the Pentaho Platform JavaScript APIs' classes.
This interface exposes methods for the registration and unregistration of event observers (or listeners), on
and off
, respectively.
Source: doc-js/pentaho/lang/IEventSource.jsdoc, line 17
See also: pentaho.lang.IEventObserver , pentaho.lang.EventListener , pentaho.lang.EventListenerAsync , pentaho.lang.IEventRegistrationHandle , pentaho.lang.Event , pentaho.lang.EventSource
Example
// An hypothetical event source. var car = new MyCar(); // Register for an unstructured event car.on("validate", function(ev) { // Do validation of this car instance. }); // Register for a structured event car.on("start", { will: function(ev) { // About to start the engine. }, did: function(ev) { // The engine has started! }, });
Methods
Name | Description |
---|---|
off(typeOrHandle, observer) | Removes one registration given its handle, or all registrations of a given event type (or types) and observer (or listener function). |
on(type, observer, keyArgs) : pentaho.lang.IEventRegistrationHandle | Registers an observer (or listener function) for an event(s) of a given type(s). |
Methods Details
off(typeOrHandle, observer) | |||||||||
---|---|---|---|---|---|---|---|---|---|
Removes one registration given its handle, or all registrations of a given event type (or types) and observer (or listener function). To remove an event registration, it is sufficient to call the It is safe to unregister from an event type while it is being emitted. However, any registrations removed during the current emission will still execute. Specifying an event registration handle that has already been disposed of has no effect. Specifying an event type and observer (or listener function) that have no registrations has no effect. Source: doc-js/pentaho/lang/IEventSource.jsdoc, line 131
See also: pentaho.lang.IEventSource#on |
on(type, observer, keyArgs) : pentaho.lang.IEventRegistrationHandle | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Registers an observer (or listener function) for an event(s) of a given type(s). Optionally, a listening priority may be specified to adjust the order by which an observer is notified, relative to other listeners. Note that if an observer is registered more than once to the same event type, a new registration is created each time and its listeners will be called once per registration. It is safe to register for an event type while it is being emitted. However, new registrations are only taken into account in subsequent emissions. When This method is compatible with the dojo/on API. Source: doc-js/pentaho/lang/IEventSource.jsdoc, line 90
See also: pentaho.lang.IEventSource#off |