Socket
Socket
Sign inDemoInstall

qi-events

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

qi-events - npm Package Compare versions

Comparing version 0.0.5 to 1.0.0

6

index.js
/**
* qi-events 0.0.5
* http://drkibitz.github.io/qi-events/
* Copyright (c) 2013 Dr. Kibitz, http://drkibitz.com
* Copyright (c) 2013-2015 Dr. Kibitz, http://drkibitz.com
* A no nonsense event API (BASED ON Backbone.Events).
* built: Sun Jan 26 2014 23:44:53 GMT-0800 (PST)
* built: Tue Apr 21 2015 22:37:59 GMT-0700 (PDT)
*

@@ -14,2 +14,2 @@ * Backbone.js 0.9.10

*/
!function(t,e){"use strict";function n(t,e,n,r,s){var c,l,a;if(!n)return!0;if("string"==typeof n){if(i.test(n))for(c=n.split(i),l=0,a=c.length;a>l;l++)e.call(t,c[l],r,s);return!0}if(Array.isArray(n))for(l=0,a=n.length;a>l;l++)e.call(t,n[l],r,s);else for(var o in n)e.call(t,o,n[o],r)}function r(t,e,n){var r,s=-1,i=t.length,c=e[n],l=e[n+1],a=e[n+2];switch(e.length-n){case 0:for(;++s<i;)(r=t[s]).callback.call(r.context);return;case 1:for(;++s<i;)(r=t[s]).callback.call(r.context,c);return;case 2:for(;++s<i;)(r=t[s]).callback.call(r.context,c,l);return;case 3:for(;++s<i;)(r=t[s]).callback.call(r.context,c,l,a);return;default:for(e=n?Array.prototype.slice.call(e,n):e;++s<i;)(r=t[s]).callback.apply(r.context,e)}}function s(){}var i=/\s+/;s.ALL="all";var c=s.prototype;c.mixin=function(t){return t.on=c.on,t.once=c.once,t.off=c.off,t.trigger=c.trigger,t},c.on=function l(t,e,r){return n(this,l,t,e,r)&&e?(this._events||(this._events={}),this._events[t]||(this._events[t]=[]),this._events[t].push({callback:e,context:r||this}),this):this},c.once=function a(t,e,r){if(!n(this,a,t,e,r)||!e)return this;var s,i=this,c=function(){s||(s=!0,i.off(t,c),e.apply(this,arguments))};return c._callback=e,this.on(t,c,r)},c.off=function o(t,e,r){var s,i,c,l,a,f,h,u;if(!this._events||!n(this,o,t,e,r))return this;if(!t&&!e&&!r)return this._events=null,this;for(l=t?[t]:Object.keys(this._events),a=0,f=l.length;f>a;a++)if(t=l[a],c=this._events[t]){if(this._events[t]=s=[],e||r)for(h=0,u=c.length;u>h;h++)i=c[h],(e&&e!==i.callback&&e!==i.callback._callback||r&&r!==i.context)&&s.push(i);s.length||(this._events[t]=null)}return this},c.trigger=function(t){var e,n=this._events;return n?(e=n[s.ALL],n[t]&&r(n[t],arguments,1),e&&r(e,arguments,0),this):this},e=t.exports=new s,e.Events=s}(module,exports);
!function(t,e){"use strict";function n(t,e,n,r,s){var l,i,a;if(!n)return!0;if("string"==typeof n){if(c.test(n))for(l=n.split(c),i=0,a=l.length;a>i;i++)e.call(t,l[i],r,s);return!0}if(Array.isArray(n))for(i=0,a=n.length;a>i;i++)e.call(t,n[i],r,s);else for(var o in n)e.call(t,o,n[o],r)}function r(t,e,n){var r,s=-1,c=t.length,l=e[n],i=e[n+1],a=e[n+2],o=e[n+3];switch(e.length-n){case 0:for(;++s<c;)(r=t[s]).callback.call(r.context);return;case 1:for(;++s<c;)(r=t[s]).callback.call(r.context,l);return;case 2:for(;++s<c;)(r=t[s]).callback.call(r.context,l,i);return;case 3:for(;++s<c;)(r=t[s]).callback.call(r.context,l,i,a);return;case 4:for(;++s<c;)(r=t[s]).callback.call(r.context,l,i,a,o);return;default:for(e=n?Array.prototype.slice.call(e,n):e;++s<c;)(r=t[s]).callback.apply(r.context,e)}}function s(){}var c=/\s+/;s.ALL="all";var l=s.prototype;l.mixin=function(t){return t.on=l.on,t.once=l.once,t.off=l.off,t.trigger=l.trigger,t},l.on=function i(t,e,r){return n(this,i,t,e,r)&&e?(this._events||(this._events={}),this._events[t]||(this._events[t]=[]),this._events[t].push({callback:e,context:r||this}),this):this},l.once=function a(t,e,r){if(!n(this,a,t,e,r)||!e)return this;var s,c=this,l=function(){s||(s=!0,c.off(t,l),e.apply(this,arguments))};return l._callback=e,this.on(t,l,r)},l.off=function o(t,e,r){var s,c,l,i,a,f,h,u;if(!this._events||!n(this,o,t,e,r))return this;if(!t&&!e&&!r)return this._events=null,this;for(i=t?[t]:Object.keys(this._events),a=0,f=i.length;f>a;a++)if(t=i[a],l=this._events[t]){if(this._events[t]=s=[],e||r)for(h=0,u=l.length;u>h;h++)c=l[h],(e&&e!==c.callback&&e!==c.callback._callback||r&&r!==c.context)&&s.push(c);s.length||(this._events[t]=null)}return this},l.trigger=function(t){var e,n=this._events;return n?(e=n[s.ALL],n[t]&&r(n[t],arguments,1),e&&r(e,arguments,0),this):this},e=t.exports=new s,e.Events=s}(module,exports);

@@ -6,8 +6,12 @@ {

"devDependencies": {
"gulp": "~3.5.0",
"gulp-jshint": "~1.3.4",
"gulp-mocha": "~0.4.1",
"gulp-uglify": "~0.2.0",
"coveralls": "*",
"gulp": "^3.8.11",
"gulp-jshint": "^1.10.0",
"gulp-mocha": "^2.0.1",
"gulp-uglify": "^1.2.0",
"gulp-util": "*",
"map-stream": "~0.1.0",
"ink-docstrap": "https://github.com/Pilatch/docstrap/archive/master.tar.gz",
"istanbul": "*",
"jshint-stylish": "^1.0.1",
"map-stream": "^0.1.0",
"mocha": "*"

@@ -30,5 +34,9 @@ },

"scripts": {
"test": "grunt test"
"jshint": "gulp jshint",
"test": "istanbul cover gulp test-source",
"coveralls": "cat ./build/coverage/lcov.info | coveralls",
"test-dist": "gulp test-dist",
"docs": "jsdoc -c jsdoc.conf.json && git checkout gh-pages && rm -fR ./api && mkdir ./api && mv ./docs/*/* ./api/latest && rm -fR ./docs"
},
"version": "0.0.5"
"version": "1.0.0"
}

@@ -1,8 +0,5 @@

[![Build Status](https://travis-ci.org/drkibitz/qi-events.png?branch=master)](https://travis-ci.org/drkibitz/qi-events)
[![Coverage Status](https://coveralls.io/repos/drkibitz/qi-events/badge.png)](https://coveralls.io/r/drkibitz/qi-events)
[![NPM version](https://badge.fury.io/js/qi-events.png)](http://badge.fury.io/js/qi-events)
[![devDependency Status](https://david-dm.org/drkibitz/qi-events/dev-status.png)](https://david-dm.org/drkibitz/qi-events#info=devDependencies)
# Qi Events
[![Version npm](https://img.shields.io/npm/v/qi-events.svg?style=flat-square)](https://www.npmjs.com/package/qi-events)[![Build Status](https://img.shields.io/travis/drkibitz/qi-events/master.svg?style=flat-square)](https://travis-ci.org/drkibitz/qi-events)[![Dependencies](https://img.shields.io/david/dev/drkibitz/qi-events.svg?style=flat-square)](https://david-dm.org/drkibitz/qi-events#info=devDependencies)[![Coverage Status](https://img.shields.io/coveralls/drkibitz/qi-events/master.svg?style=flat-square)](https://coveralls.io/r/drkibitz/qi-events?branch=master)[![API Documentation](https://img.shields.io/badge/API-Documentation-0099dd.svg?style=flat-square)](https://drkibitz.github.io/qi-events/api/latest/)
http://drkibitz.github.io/qi-events/

@@ -20,10 +17,59 @@

There are just 4 main methods to remember.
- [on](http://drkibitz.github.io/qi-events/api/latest/module-qi-events.Events.html#on)
- [once](http://drkibitz.github.io/qi-events/api/latest/module-qi-events.Events.html#once)
- [off](http://drkibitz.github.io/qi-events/api/latest/module-qi-events.Events.html#off)
- [trigger](http://drkibitz.github.io/qi-events/api/latest/module-qi-events.Events.html#trigger)
Use the [mixin](http://drkibitz.github.io/qi-events/api/latest/module-qi-events.Events.html#toc6) method to allow any object to trigger events.
```javascript
require('qi-events').mixin({});
.on('myevent', console.log, console)
.trigger('myevent', 'something')
.trigger('myevent', 'something', 'something')
.trigger('myevent', 'something', 'something', 'darkside');
// > something
// > something something
// > something something darkside
```
Mixin into any prototype object.
```javascript
var events = require('qi-events');
function MyEmitter() {}
events.mixin(MyEmitter.prototype);
var emitter = new MyEmitter();
emitter
.on('myevent', console.log, console)
.trigger('myevent', 'something', 'something', 'darkside');
// > something something darkside
```
Extend the provided class.
```javascript
var Events = require('qi-events').Events;
function MyEmitter() {}
MyEmitter.prototype = Object.create(Events.prototype, {
constructor: {value: MyEmitter}
});
var emitter = new MyEmitter();
emitter
.on('myevent', console.log, console)
.trigger('myevent', 'something', 'something', 'darkside');
// > something something darkside
```
Use the module itself as a central dispatcher.
```javascript
require('qi-events');
.once('myevent', console.log, console)
.trigger('myevent', 'something', 'something', 'darkside');
// > something something darkside
```
## Goals

@@ -67,4 +113,36 @@

## Why not EventEmitter?
So I think we already have **four separate versions** of EventEmitter at the time of writing this paragraph (April 2015). At this point in time, I am refusing to raise that count to five, or linking to any of them. Just to be clear, I am pretty sure I published this library when there were only two versions published, and I originally implemented my changes privately on top of Backbone.Events before it was broken up into parts. With all of this said, though I may be biased, I still prefer this library. If you are interested in how this API compares to the [EventEmitter API](https://nodejs.org/api/events.html), the following example should help.
```javascript
var events = require('qi-events');
function EventEmitter25() {}
var proto = EventEmitter25.prototype;
proto.emit = events.trigger;
proto.on = proto.addListener = events.on;
proto.once = events.once;
proto.removeListener = events.off;
proto.listeners = function (event) {
if (!this._events || !this._events[event]) return [];
for (var i = 0, l = this._events[event].length, arr = new Array(l); i < l; i++) {
arr[i] = this._events[event][i].callback;
}
return arr;
};
proto.removeAllListeners = function (event) {
return events.off.call(this, event);
};
proto.setMaxListeners = function () {
return this;
};
module.exports = EventEmitter25;
```
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/drkibitz/qi-events/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc