1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-05-28 19:42:52 +02:00

Added comments to emitter class

This commit is contained in:
Max Guglielmi 2015-12-29 17:05:36 +11:00
parent 784eeea4a1
commit 5da3079c13
2 changed files with 23 additions and 1 deletions

View file

@ -1,6 +1,6 @@
{
"name": "tablefilter",
"version": "0.1.0",
"version": "0.1.1",
"description": "A Javascript library making HTML tables filterable and a bit more",
"license": "MIT",
"author": {

View file

@ -1,19 +1,41 @@
/**
* Event emitter class
*/
export class Emitter {
constructor() {
/**
* Events object
* @type {Object}
*/
this.events = {};
}
/**
* Subscribe to an event
* @param {String} evt Event name
* @param {Function} fn Function invoked when event is emitted
*/
on(evt, fn) {
this.events[evt] = this.events[evt] || [];
this.events[evt].push(fn);
}
/**
* Unsubscribe to an event
* @param {String} evt Event name
* @param {Function} fn Function invoked when event is emitted
*/
off(evt, fn) {
if(evt in this.events) {
this.events[evt].splice(this.events[evt].indexOf(fn), 1);
}
}
/**
* Emit an event
* @param {String} evt Event name followed by any other argument passed to
* the invoked function
*/
emit(evt /*, args...*/) {
if(evt in this.events === false) {
return;