Repository navigation
[Typescript SimpleEvents] Base Event
Face of Cat edited this page Apr 30, 2017
·
1 revision
This is the base interface that all the others provided event types use.
One could also use this to create one's own event type.
export class BaseEvent<D, R> {
protected add(callback: (data: D) => R): number;
protected remove(handle: number): void;
protected removeAll(): void;
protected getCallbacks(): ((data: D) => R)[];
protected getResult(data: D, defaultValueOfCallback: R | undefined = undefined): R | undefined;
}-
<D>: data type of the event data;
-
<R>: data type of the event result;
-
add: adds a callback to the invoke list and returns its handle;
-
remove: removes a callback from the invoke list based on its handle;
-
removeAll: clears the invoke list;
-
getCallbacks: returns the current invoke list;
-
getResult: calls the invoke list in order returning the first valid (as in not null, not undefined, not 0 and not false) result; if the invoke list is empty this method returns undefined; if the invoke list is not empty but no callback returns a valid value it will return defaultValueOfCallback.