@odoo/o-spreadsheet
Version:
A spreadsheet component
46 lines (45 loc) • 1.37 kB
TypeScript
/**
* This is a generic event bus based on the Owl event bus.
* This bus however ensures type safety across events and subscription callbacks.
*/
export declare class EventBus<Event extends {
type: string;
}> {
subscriptions: {
[eventType: string]: Subscription[];
};
/**
* Add a listener for the 'eventType' events.
*
* Note that the 'owner' of this event can be anything, but will more likely
* be a component or a class. The idea is that the callback will be called with
* the proper owner bound.
*
* Also, the owner should be kind of unique. This will be used to remove the
* listener.
*/
on<T extends Event["type"], E extends Extract<Event, {
type: T;
}>>(type: T, owner: any, callback: (r: Omit<E, "type">) => void): void;
/**
* Emit an event of type 'eventType'. Any extra arguments will be passed to
* the listeners callback.
*/
trigger<T extends Event["type"], E extends Extract<Event, {
type: T;
}>>(type: T, payload?: Omit<E, "type">): void;
/**
* Remove a listener
*/
off<T extends Event["type"]>(eventType: T, owner: any): void;
/**
* Remove all subscriptions.
*/
clear(): void;
}
type Callback = (...args: any[]) => void;
interface Subscription {
owner: any;
callback: Callback;
}
export {};