@hackdonalds/emitter
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -1,57 +0,44 @@ | ||
(function (factory) { | ||
if (typeof module === "object" && typeof module.exports === "object") { | ||
var v = factory(require, exports); | ||
if (v !== undefined) module.exports = v; | ||
export default class Emitter { | ||
constructor(listeners = {}) { | ||
this.listeners = listeners; | ||
this.listeners = listeners; | ||
} | ||
else if (typeof define === "function" && define.amd) { | ||
define(["require", "exports"], factory); | ||
} | ||
})(function (require, exports) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
class Emitter { | ||
constructor(listeners = {}) { | ||
this.listeners = listeners; | ||
this.listeners = listeners; | ||
} | ||
/** | ||
* Register an event handler for the given type. | ||
* | ||
* @param {String} type Type of event to listen for, or `"*"` for all events | ||
* @param {Function} handler Function to call in response to given event | ||
*/ | ||
on(type, handler) { | ||
this.listeners[type] = this.listeners[type] || []; | ||
this.listeners[type].push(handler); | ||
} | ||
/** | ||
* Remove an event handler for the given type. | ||
/** | ||
* Register an event handler for the given type. | ||
* | ||
* @param {String} type Type of event to unregister `handler` from, or `"*"` | ||
* @param {Function} handler Handler function to remove | ||
* @param {String} type Type of event to listen for, or `"*"` for all events | ||
* @param {Function} handler Function to call in response to given event | ||
*/ | ||
off(type, handler) { | ||
if (this.listeners[type]) { | ||
this.listeners[type].splice(this.listeners[type].indexOf(handler) >>> 0, 1); | ||
} | ||
on(type, handler) { | ||
this.listeners[type] = this.listeners[type] || []; | ||
this.listeners[type].push(handler); | ||
} | ||
/** | ||
* Remove an event handler for the given type. | ||
* | ||
* @param {String} type Type of event to unregister `handler` from, or `"*"` | ||
* @param {Function} handler Handler function to remove | ||
*/ | ||
off(type, handler) { | ||
if (this.listeners[type]) { | ||
this.listeners[type].splice(this.listeners[type].indexOf(handler) >>> 0, 1); | ||
} | ||
/** | ||
* Invoke this.listeners handlers for the given type. | ||
* If present, `"*"` handlers are invoked after type-matched handlers. | ||
* | ||
* Note: Manually firing "*" handlers is not supported. | ||
* | ||
* @param {String} type The event type to invoke | ||
* @param {Any} [evt] Any value (object is recommended and powerful), passed to each handler | ||
*/ | ||
emit(type, evt) { | ||
(this.listeners[type] || []).slice().map((handler) => { handler(evt); }); | ||
(this.listeners['*'] || []).slice().map((handler) => { handler(type, evt); }); | ||
} | ||
} | ||
exports.default = Emitter; | ||
if (typeof window !== "undefined") { | ||
window.HackDonalds = { Emitter }; | ||
/** | ||
* Invoke this.listeners handlers for the given type. | ||
* If present, `"*"` handlers are invoked after type-matched handlers. | ||
* | ||
* Note: Manually firing "*" handlers is not supported. | ||
* | ||
* @param {String} type The event type to invoke | ||
* @param {Any} [evt] Any value (object is recommended and powerful), passed to each handler | ||
*/ | ||
emit(type, evt) { | ||
(this.listeners[type] || []).slice().map((handler) => { handler(evt); }); | ||
(this.listeners['*'] || []).slice().map((handler) => { handler(type, evt); }); | ||
} | ||
}); | ||
} | ||
if (typeof window !== "undefined") { | ||
window.HackDonalds = { Emitter }; | ||
} | ||
//# sourceMappingURL=index.js.map |
@@ -5,3 +5,3 @@ { | ||
"keywords": ["event", "emitter", "isomorphic", "events", "nodejs", "Javascript", "mitt", "eventemitter"], | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"main": "dist/index.js", | ||
@@ -8,0 +8,0 @@ "files": ["dist","README.md","src"], |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10562
131