EventAware
Event-Aware
Describes a host-side object which behaves as an EventTarget, with all the internal machinery necessary to receive, dispatch, and manage events and event listeners.
This interface and the accompanying default implementation are designed to be used as JVM proxies. For example:
public class MyObject constructor (private val proxy: EventAware = EventAware.create()) : EventAware by proxy {
// your object here
}
See the Usage section for more information.
Usage
The EventAware
interface is designed to be used as a JVM proxy for host-side objects which need to behave as event-aware types.
Listeners are managed internally on behalf of the proxied object, and can be added and removed using the methods provided by the EventTarget interface.
Once implemented, events can be dispatched to a custom implementation, or to the proxied implementation. Objects are encouraged to dispatch their own events, originating internally, via dispatchEvent.
Interaction with Node Events
Node events can be dispatched through this interface on arbitrary objects; note as well that guest-side objects can implement EventTarget.
Types
Functions
Alias for emitter.on(eventName, listener)
.
Dispatches the event to the list of handlers for Event.type.
Returns an array listing the events for which the emitter has registered listeners. The values in the array are strings or Symbol
s.
Returns the current max listener value for the emitter.
Returns the number of listeners listening to the event named eventName.
Returns an array listing the listeners for the specified event.
Adds the listener function to the beginning of the listeners array for the event named eventName. No checks are made to see if the listener has already been added.
Adds a one-time listener function for the event named eventName to the beginning of the listener array. The next time eventName is triggered, this listener is removed, and then invoked.
Returns a copy of the array of listeners for the event named eventName, including any wrappers (such as those created by .once()
).
Removes all listeners, or those of the specified eventName
.
Removes all listeners, or those of the specified eventName.
Removes the listener
from the list of handlers for event type
.
Sets the maximum number of listeners for the emitter.