Event

open class Event<T : Tuple>(source)

A generic utility class for managing subscribers for a particular event. This class is usually instantiated inside of a container class and exposed as a property for others to subscribe to.

MyObject.prototype.myListener = function(arg1, arg2) {
this.myArg1Copy = arg1;
this.myArg2Copy = arg2;
}

const myObjectInstance = new MyObject();
const evt = new Event();
evt.addEventListener(MyObject.prototype.myListener, myObjectInstance);
evt.raiseEvent('1', '2');
evt.removeEventListener(MyObject.prototype.myListener);

See also

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
typealias RemoveCallback = () -> Unit

A function that removes a listener.

Properties

Link copied to clipboard
external val numberOfListeners: Int

The number of listeners currently subscribed to the event.

Link copied to clipboard
external val raiseEvent: JsFunction<T, Void>

Raises the event by calling each registered listener with all supplied arguments.

Functions

Link copied to clipboard
fun Event<*>.addHandler(handler: () -> Unit): Event.RemoveCallback
fun <T : Tuple> Event<T>.addHandler(handler: (T) -> Unit): Event.RemoveCallback
Link copied to clipboard
operator fun <T : Tuple> Event<T>.invoke(): Flow<T>