shimi
Version:
A JS framework for building complex MIDI applications
57 lines (56 loc) • 2.42 kB
TypeScript
/** The base event data class in shimi. */
export declare class ShimiEventData<TSource> {
/** The object that triggered the event. */
source: TSource;
/** If set to true, the event will stop processing. */
cancel: boolean;
constructor(source: TSource);
}
/** The base event class in shimi. */
export default class ShimiEvent<TData extends ShimiEventData<TSource>, TSource> {
/** A collection of handlers which get called in order when the event is triggered. */
get handlers(): Array<ShimiHandler<TData, TSource>>;
private _handlers;
/**
* Add a new handler to the event.
* @param handler The new handler, either as a function, or a ShimiHandler object.
* @returns Returns the added ShimiHandler object.
*/
add(handler: ShimiHandler<TData, TSource> | ((data: TData) => void)): ShimiHandler<TData, TSource>;
/** Remove the specified handlers from the event. */
remove(where: (handler: ShimiHandler<TData, TSource>) => boolean): void;
/** Runs the collection of handlers that have been added to the event. */
trigger(data: TData): void;
}
/**
* The ShimiHandler is designed to be added to ShimiEvents, containing some action to be called whenever the event is triggered.
*/
export declare class ShimiHandler<TData extends ShimiEventData<TSource>, TSource> {
/** The logic to be executed whenever the event that the handler is attached to gets triggered. */
get logic(): (data: TData) => void;
private _logic;
/** Provides a way of identifying handlers so they can be easily retrieved later. */
get ref(): string;
set ref(value: string);
private _ref;
/** If false, then the handler should be skipped. */
get on(): boolean;
set on(value: boolean);
private _on;
/**
* @param logic The logic to be executed whenever the event that the handler is attached to gets triggered.
* @param ref Provides a way of identifying handlers so they can be easily retrieved later.
*/
constructor(logic: (data: TData) => void, ref?: string);
/**
* Provides a way for setting the ref through a chained function call. For example:
*
* ```
* keyboard.a.pressed.add(data => console.log(data)).withRef('key log');
* ```
*
* @param ref The ref to set on the object.
* @returns The calling object.
*/
withRef(ref: string): ShimiHandler<TData, TSource>;
}