@highcharts/dashboards
Version:
Highcharts Dashboards framework
80 lines (79 loc) • 2.1 kB
TypeScript
/**
* The event object to pass to a callback.
*/
export interface DataEvent {
/**
* Additional event detail
*/
detail?: DataEventDetail;
/**
* The event type
*/
type: string;
}
/**
* Additional types for the event object and the event callback.
*/
/**
* Describes the callbacks expected types. This generic interface can be
* extended by implementing classes.
*/
export interface DataEventCallback<T, E extends DataEvent> {
/**
*
* @param this
* Event scope pointing to the class instance, where the event happens.
*
* @param e
* Event object with additional event information.
*/
(this: T, e: E): void;
}
/**
* Additional detail of the event object.
*/
export type DataEventDetail = Record<string, (boolean | number | string | null | undefined)>;
/**
* Describes methods to attach callbacks to events of a class instance.
*/
export interface DataEventEmitter<E extends DataEvent> {
/**
* Registered events managed by Highcharts utility functions.
*/
hcEvents?: DataEventHCEventsCollection;
/**
* Emits an event on the class instance to all registered callbacks of
* this event.
*
* @param e
* Event object containing additional event information.
*/
emit(e: E): void;
/**
* Registers a callback for a specific event.
*
* @param {string} type
* Event type as a string.
*
* @param {DataEventCallback} callback
* Function to register for an event callback.
*
* @return {Function}
* Function to unregister callback from the event.
*/
on<T extends E['type']>(type: T, callback: DataEventCallback<this, Extract<E, {
type: T;
}>>): Function;
}
/**
* Object to manage an event.
*/
export interface DataEventHCEventObject {
fn: DataEventCallback<unknown, DataEvent>;
order?: number;
}
/**
* Collection of events managed by Highcharts utility functions.
*/
export type DataEventHCEventsCollection = (Record<string, Array<DataEventHCEventObject>>);
export default DataEvent;