Simple EventEmitter

emit and receive events!

As of 21.06.2021. See the latest version.

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greatest.deepsurf.us/scripts/426233/942855/Simple%20EventEmitter.js

const EventEmitter = class {
    constructor() {
        this.a = {};
    }
    on(t, s) {
        !this.a[t] && (this.a[t] = []), this.a[t].push(s);
    }
    once(t, s) {
        !this.a[t] && (this.a[t] = []), this.a[t].push(s);
    }
    emit(t, s) {
        let a = this.a[t];
        a && a.forEach(t => t(s));
    }
};