公司小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
817 B

/**
* mini (~500 b) version for event-emitter.
*
* Created by hustcc on 2018/12/31
* Contract: vip@hust.edu.cn
*/
export interface Listener {
cb: Function;
once: boolean;
}
export interface EventsType {
[eventName: string]: Listener[];
}
/**
* const ee = new OnFire();
*
* ee.on('click', (...values) => {});
*
* ee.on('mouseover', (...values) => {});
*
* ee.emit('click', 1, 2, 3);
* ee.fire('mouseover', {}); // same with emit
*
* ee.off();
*/
export default class OnFire {
static ver: string;
es: EventsType;
on(eventName: string, cb: Function, once?: boolean): void;
once(eventName: string, cb: Function): void;
fire(eventName: string, ...params: any[]): void;
off(eventName?: string, cb?: Function): void;
emit(eventName: string, ...params: any[]): void;
}