🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

event-lite

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

event-lite - npm Package Compare versions

Comparing version

to
0.0.4

.travis.yml

2

dist/event-lite.min.js

@@ -1,1 +0,1 @@

function EventLite(){return this instanceof EventLite?void 0:new EventLite}!function(t){function n(t){for(var n in u)t[n]=u[n];return t}function e(t,n){return o(this,t).push(n),this}function i(t,n){function e(){this.off(t,e),n.apply(this,arguments)}return o(this,t).push(e),this}function r(t,n){function e(t){return t!==n}var i=o(this,t);return t?n?this.listeners[t]=i.filter(e):delete this.listeners[t]:delete this.listeners,this}function s(t,n){function e(t){t.apply(this,i)}var i=Array.prototype.slice.call(arguments,1),r=o(this,t);return r.forEach(e.bind(this)),!!r.length}function o(t,n){var e=t.listeners||(t.listeners={});return e[n]||(e[n]=[])}"undefined"!=typeof module&&(module.exports=t);var u={on:e,once:i,off:r,emit:s};n(t.prototype),t.mixin=n}(EventLite);
function EventLite(){return this instanceof EventLite?void 0:new EventLite}!function(t){function e(t){for(var e in l)t[e]=l[e];return t}function n(t,e){return o(this,t).push(e),this}function i(t,e){function n(){r.call(i,t,n),e.apply(this,arguments)}var i=this;return o(i,t).push(n),i}function r(t,e){function n(t){return t!==e}var i,u=this;if(t){if(e){if(i=o(u,t,!0)){if(i=i.filter(n),!i.length)return r.call(u,t);u[f][t]=i}}else if(delete u[f][t],!Object.keys(u[f]).length)return r.call(u)}else delete u[f];return u}function u(t,e){function n(t){t.apply(i,r)}var i=this,r=Array.prototype.slice.call(arguments,1),u=o(i,t,!0);return u?(u.forEach(n),!!u.length):!1}function o(t,e,n){if(!n||t[f]){var i=t[f]||(t[f]={});return i[e]||(i[e]=[])}}"undefined"!=typeof module&&(module.exports=t);var f="listeners",l={on:n,once:i,off:r,emit:u};e(t.prototype),t.mixin=e}(EventLite);

@@ -6,4 +6,5 @@ /**

* @license MIT
* @returns {EventLite}
* @constructor
* @see https://github.com/kawanet/event-lite
* @see http://kawanet.github.io/event-lite/EventLite.html
* @example

@@ -32,2 +33,5 @@ * var EventLite = require("event-lite");

// property name to hold listeners
var LISTENERS = "listeners";
// methods to export

@@ -50,3 +54,3 @@ var methods = {

*
* @name EventLite.mixin
* @function EventLite.mixin
* @param target {Prototype}

@@ -65,6 +69,6 @@ */

*
* @name EventLite.prototype.on
* @function EventLite.prototype.on
* @param type {string}
* @param func {Function}
* @returns {EventLite}
* @returns {EventLite} Self for method chaining
*/

@@ -80,14 +84,15 @@

*
* @name EventLite.prototype.once
* @function EventLite.prototype.once
* @param type {string}
* @param func {Function}
* @returns {EventLite}
* @returns {EventLite} Self for method chaining
*/
function once(type, func) {
getListeners(this, type).push(wrap);
return this;
var that = this;
getListeners(that, type).push(wrap);
return that;
function wrap() {
this.off(type, wrap);
off.call(that, type, wrap);
func.apply(this, arguments);

@@ -100,18 +105,25 @@ }

*
* @name EventLite.prototype.off
* @function EventLite.prototype.off
* @param [type] {string}
* @param [func] {Function}
* @returns {EventLite}
* @returns {EventLite} Self for method chaining
*/
function off(type, func) {
var listners = getListeners(this, type);
var that = this;
var listners;
if (!type) {
delete this.listeners;
delete that[LISTENERS];
} else if (!func) {
delete this.listeners[type];
delete that[LISTENERS][type];
if (!Object.keys(that[LISTENERS]).length) return off.call(that);
} else {
this.listeners[type] = listners.filter(ne);
listners = getListeners(that, type, true);
if (listners) {
listners = listners.filter(ne);
if (!listners.length) return off.call(that, type);
that[LISTENERS][type] = listners;
}
}
return this;
return that;

@@ -126,21 +138,28 @@ function ne(test) {

*
* @name EventLite.prototype.emit
* @function EventLite.prototype.emit
* @param type {string}
* @param [value] {*}
* @returns {boolean}
* @returns {boolean} True when a listener received the event
*/
function emit(type, value) {
var that = this;
var args = Array.prototype.slice.call(arguments, 1);
var listeners = getListeners(this, type);
listeners.forEach(run.bind(this));
var listeners = getListeners(that, type, true);
if (!listeners) return false;
listeners.forEach(run);
return !!listeners.length;
function run(func) {
func.apply(this, args);
func.apply(that, args);
}
}
function getListeners(that, type) {
var listeners = that.listeners || (that.listeners = {});
/**
* @ignore
*/
function getListeners(that, type, readonly) {
if (readonly && !that[LISTENERS]) return;
var listeners = that[LISTENERS] || (that[LISTENERS] = {});
return listeners[type] || (listeners[type] = []);

@@ -147,0 +166,0 @@ }

{
"name": "event-lite",
"version": "0.0.2",
"version": "0.0.4",
"description": "Light-weight EventEmitter (less than 1KB when minified)",

@@ -19,7 +19,19 @@ "main": "event-lite.js",

"homepage": "https://github.com/kawanet/event-lite",
"keywords": [
"event",
"emitter",
"trigger"
],
"devDependencies": {
"jsdoc": "^3.3.2",
"jshint": "^2.8.0",
"mocha": "^2.2.5",
"uglify-js": "^2.4.23"
},
"jshintConfig": {
"undef": true,
"globals": {
"module": true
}
}
}

@@ -1,6 +0,6 @@

# event-lite.js
# event-lite.js [![Build Status](https://travis-ci.org/kawanet/event-lite.svg?branch=master)](https://travis-ci.org/kawanet/event-lite)
Light-weight EventEmitter (less than 1KB when minified)
## Usage
### Usage

@@ -22,3 +22,3 @@ ```js

## Node.js
### Node.js

@@ -29,3 +29,3 @@ ```sh

## Browsers
### Browsers

@@ -36,11 +36,15 @@ ```html

## Repository
### Repository
https://github.com/kawanet/event-lite
- https://github.com/kawanet/event-lite
## See Also
### Documentation
- http://kawanet.github.io/event-lite/EventLite.html
### See Also
- https://nodejs.org/api/events.html
## License
### License

@@ -67,2 +71,2 @@ The MIT License (MIT)

OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.

@@ -1,5 +0,6 @@

#!/usr/bin/env ./node_modules/.bin/mocha -R spec
#!/usr/bin/env mocha -R spec
var assert = require("assert");
var EventLite = require("../event-lite");
var TITLE = __filename.replace(/^.*\//, "") + ":";

@@ -9,3 +10,3 @@ events_test();

function events_test() {
describe("EventLite", function() {
describe(TITLE, function() {
var event = EventLite();

@@ -12,0 +13,0 @@

@@ -1,5 +0,6 @@

#!/usr/bin/env ./node_modules/.bin/mocha -R spec
#!/usr/bin/env mocha -R spec
var assert = require("assert");
var EventLite = require("../event-lite");
var TITLE = __filename.replace(/^.*\//, "") + ":";

@@ -16,3 +17,3 @@ function MyEvent() {

function events_test() {
describe("EventLite.mixin", function() {
describe(TITLE, function() {
var event = MyEvent();

@@ -19,0 +20,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet