mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-21 00:59:29 +00:00
[Modern] Move emitter to utils
This commit is contained in:
parent
a174aaf17d
commit
d7c4df7b66
2 changed files with 23 additions and 23 deletions
|
|
@ -1,26 +1,4 @@
|
|||
import { clamp } from "../utils";
|
||||
|
||||
class Emitter {
|
||||
_cbs: { [event: string]: Array<() => void> } = {};
|
||||
on(event: string, cb: () => void) {
|
||||
if (this._cbs[event] == null) {
|
||||
this._cbs[event] = [];
|
||||
}
|
||||
this._cbs[event].push(cb);
|
||||
return () => {
|
||||
this._cbs[event] = this._cbs[event].filter((c) => c !== cb);
|
||||
};
|
||||
}
|
||||
trigger(event: string) {
|
||||
const subscriptions = this._cbs[event];
|
||||
if (subscriptions == null) {
|
||||
return;
|
||||
}
|
||||
for (const cb of subscriptions) {
|
||||
cb();
|
||||
}
|
||||
}
|
||||
}
|
||||
import { clamp, Emitter } from "../utils";
|
||||
|
||||
export class AudioPlayer {
|
||||
_input: HTMLInputElement = document.createElement("input");
|
||||
|
|
|
|||
|
|
@ -79,3 +79,25 @@ export function findLast<T>(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class Emitter {
|
||||
_cbs: { [event: string]: Array<() => void> } = {};
|
||||
on(event: string, cb: () => void) {
|
||||
if (this._cbs[event] == null) {
|
||||
this._cbs[event] = [];
|
||||
}
|
||||
this._cbs[event].push(cb);
|
||||
return () => {
|
||||
this._cbs[event] = this._cbs[event].filter((c) => c !== cb);
|
||||
};
|
||||
}
|
||||
trigger(event: string) {
|
||||
const subscriptions = this._cbs[event];
|
||||
if (subscriptions == null) {
|
||||
return;
|
||||
}
|
||||
for (const cb of subscriptions) {
|
||||
cb();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue