UNPKG

1.89 kBTypeScriptView Raw
1import { Tone } from "../Tone.js";
2export interface EmitterEventObject {
3 [event: string]: Array<(...args: any[]) => void>;
4}
5/**
6 * Emitter gives classes which extend it
7 * the ability to listen for and emit events.
8 * Inspiration and reference from Jerome Etienne's [MicroEvent](https://github.com/jeromeetienne/microevent.js).
9 * MIT (c) 2011 Jerome Etienne.
10 * @category Core
11 */
12export declare class Emitter<EventType extends string = string> extends Tone {
13 readonly name: string;
14 /**
15 * Private container for the events
16 */
17 private _events?;
18 /**
19 * Bind a callback to a specific event.
20 * @param event The name of the event to listen for.
21 * @param callback The callback to invoke when the event is emitted
22 */
23 on(event: EventType, callback: (...args: any[]) => void): this;
24 /**
25 * Bind a callback which is only invoked once
26 * @param event The name of the event to listen for.
27 * @param callback The callback to invoke when the event is emitted
28 */
29 once(event: EventType, callback: (...args: any[]) => void): this;
30 /**
31 * Remove the event listener.
32 * @param event The event to stop listening to.
33 * @param callback The callback which was bound to the event with Emitter.on.
34 * If no callback is given, all callbacks events are removed.
35 */
36 off(event: EventType, callback?: (...args: any[]) => void): this;
37 /**
38 * Invoke all of the callbacks bound to the event
39 * with any arguments passed in.
40 * @param event The name of the event.
41 * @param args The arguments to pass to the functions listening.
42 */
43 emit(event: EventType, ...args: any[]): this;
44 /**
45 * Add Emitter functions (on/off/emit) to the object
46 */
47 static mixin(constr: any): void;
48 /**
49 * Clean up
50 */
51 dispose(): this;
52}