BetterDiscordApp-v2/client/src/modules/events.js

53 lines
1.4 KiB
JavaScript
Raw Normal View History

2018-01-29 18:46:24 +01:00
/**
* BetterDiscord Events Module
* Copyright (c) 2015-present Jiiks/JsSucks - https://github.com/Jiiks / https://github.com/JsSucks
2018-01-29 18:46:24 +01:00
* All rights reserved.
* https://betterdiscord.net
2018-01-29 18:46:24 +01:00
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
2018-01-29 18:46:24 +01:00
*/
import { EventEmitter } from 'events';
const emitter = new EventEmitter();
export default class {
/**
* Adds an event listener.
* @param {String} event The event to listen for
* @param {Function} callback The function to call when the event is emitted
*/
static on(event, callback) {
emitter.on(event, callback);
}
/**
* Adds an event listener that is only called once.
* @param {String} event The event to listen for
* @param {Function} callback The function to call when the event is emitted
*/
static once(event, callback) {
emitter.once(event, callback);
2018-01-29 18:46:24 +01:00
}
/**
* Removes an event listener.
* @param {String} event The event to remove
* @param {Function} callback The listener to remove
*/
static off(event, callback) {
emitter.removeListener(event, callback);
2018-01-29 18:46:24 +01:00
}
/**
* Emits an event
* @param {String} event The event to emit
* @param {Any} ...data Data to pass to the event listeners
*/
2018-01-29 18:46:24 +01:00
static emit(...args) {
emitter.emit(...args);
}
2018-02-01 03:36:47 +01:00
}