MCPcopy Create free account
hub / github.com/CoderLine/alphaTab / EventEmitterOfT

Class EventEmitterOfT

packages/alphatab/src/EventEmitter.ts:78–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

76 * @internal
77 */
78export class EventEmitterOfT<T> implements IEventEmitterOfT<T> {
79 private _listeners: ((arg: T) => void)[] = [];
80 private readonly _fireOnRegister: (() => T | null) | undefined;
81
82 public constructor(fireOnRegister: (() => T | null) | undefined = undefined) {
83 this._fireOnRegister = fireOnRegister;
84 }
85 public on(value: (arg: T) => void): () => void {
86 this._listeners.push(value);
87 if (this._fireOnRegister) {
88 const arg = this._fireOnRegister();
89 if (arg !== null) {
90 value(arg);
91 }
92 }
93 return () => {
94 this.off(value);
95 };
96 }
97
98 public off(value: (arg: T) => void): void {
99 this._listeners = this._listeners.filter(l => l !== value);
100 }
101
102 public trigger(arg: T): void {
103 for (const l of this._listeners) {
104 l(arg);
105 }
106 }
107}

Calls

no outgoing calls

Tested by

no test coverage detected