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:
parent
784eeea4a1
commit
5da3079c13
|
@ -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": {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue