RegisteringEventEmitter

The RegisteringEventEmitter allows developers to constrain which events their Components are intended to listen for and emit. If a component attempts to emit or listen for an event that it hasn't explicitly listed, an exception will be thrown.

Registration occurs by creating a new instance of RegisteringEventEmitter, using a shared EventEmitter (typically EventEmitterImpl), and the class to be registered. The class in question MUST be decorated with two annotations: ListensFor and Emits. Each takes a String[], populated with EventType strings, attached to their 'events' property. Each annotation MUST be included, even if the component has no intention of listening or emitting any events.

For example, the following component class declartion:

@Emits(events = {EventType.PLAY, EventType.STOP})@ListensFor(events = {EventType.PLAY}) public class SampleComponent implements Component

See also

Constructors

Link copied to clipboard
constructor(emitter: EventEmitter, component: Class<out Component>)
Main constructor.

Functions

Link copied to clipboard
open fun build(incomingEmitter: EventEmitter, componentClass: Class<out Component>): RegisteringEventEmitter
Factory method to create a new RegisteringEventEmitter given an existing EventEmitter and a Component implementation.
Link copied to clipboard
open fun disable()
Disables listener registration and event emitting.
Link copied to clipboard
open fun emit(eventType: String)
Emits an Event of EventType.
open fun emit(eventType: String, properties: Map<String, Any>)
Emits and Event of EventType, provided the Component is allowed to do so.
Link copied to clipboard
open fun emitNow(eventType: String, properties: Map<String, Any>)
Emits an event immediately instead of waiting for the handler.
Link copied to clipboard
open fun enable()
Enables listener registration and event emitting.
Link copied to clipboard
Retrieves a list of all Events that are allowed to be emitted in this RegisteringEventEmitter.
Link copied to clipboard
Retrieves a list of all Events that are allowed to be listened in this RegisteringEventEmitter.
Link copied to clipboard
Retrieve the underlying EventEmitter provided when initializing this emitter.
Link copied to clipboard
open fun off()
Remove all listeners.
open fun off(eventType: String, token: Int)
Remove a listener from handling an event of EventType.
Link copied to clipboard
open fun on(eventType: String, listener: EventListener): Int
Add a listener for an EventType, filtered by what the component is allowed to listen for.
Link copied to clipboard
open fun once(eventType: String, listener: EventListener): Int
Add a listener for an EventType, filtered by what the component is allowed to listen for.
Link copied to clipboard
open fun request(eventType: String, listener: EventListener)
open fun request(eventType: String, properties: Map<String, Any>, listener: EventListener)
Requests a response from the first listener to respond.
Link copied to clipboard
open fun respond(event: Event)
open fun respond(properties: Map<String, Any>)
Respond to a request.