@eclipse-scout/core
Version:
Eclipse Scout runtime
50 lines • 2.93 kB
TypeScript
/// <reference types="jquery" />
import { Event, EventListener, EventMap, EventSupport } from '../index';
export declare class EventEmitter {
events: EventSupport;
eventMap: EventMap;
self: EventEmitter;
constructor();
protected _createEventSupport(): EventSupport;
trigger<K extends string & keyof EventMapOf<EventEmitter>>(type: K, eventOrModel?: Event | EventModel<EventMapOf<EventEmitter>[K]>): EventMapOf<EventEmitter>[K];
/**
* Registers the given event handler for the event specified by the type param.
* The function will only be called once. After that it is automatically de-registered using {@link off}.
*
* @param type One or more event names separated by space.
* @param handler Event handler executed when the event is triggered. An event object is passed to the function as first parameter
*/
one<K extends string & keyof EventMapOf<this['self']>>(type: K, handler: EventHandler<EventMapOf<this>[K] & Event<this>>): void;
/**
* Registers the given event handler for the event specified by the type param.
*
* @param type One or more event names separated by space.
* @param handler Event handler executed when the event is triggered. An event object is passed to the function as first parameter.
**/
on<K extends string & keyof EventMapOf<this['self']>>(type: K, handler: EventHandler<EventMapOf<this>[K] & Event<this>>): EventListener;
/**
* De-registers the given event handler for the event specified by the type param.
*
* @param type One or more event names separated by space.<br/>
* Important: the string must be equal to the one used for {@link on} or {@link one}. This also applies if a string containing multiple types separated by space was used.
* @param handler The exact same event handler that was used for registration using {@link on} or {@link one}.
* If no handler is specified, all handlers are de-registered for the given type.
*/
off<K extends string & keyof EventMapOf<this['self']>>(type: K, handler?: EventHandler<EventMapOf<this>[K] & Event<this>>): void;
/**
* Adds an event handler using {@link one} and returns a promise.
* The promise is resolved as soon as the event is triggered.
*/
when<K extends string & keyof EventMapOf<this['self']>>(type: K): JQuery.Promise<EventMapOf<this>[K] & Event<this>>;
addListener(listener: EventListener): void;
removeListener(listener: EventListener): void;
}
export interface EventHandler<K extends Event = Event> {
(event: K): void;
}
export type EventMapOf<T> = T extends {
eventMap: infer TMap;
} ? TMap : object;
/** Omits all properties that cannot be passed as part of the event model when the event is triggered. */
export type EventModel<T> = Omit<T, 'source' | 'defaultPrevented' | 'type' | 'preventDefault'>;
//# sourceMappingURL=EventEmitter.d.ts.map