Security News
vlt Debuts New JavaScript Package Manager and Serverless Registry at NodeConf EU
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
http://drkibitz.github.io/qi-events/
A no nonsense event API (BASED ON Backbone.Events).
There are just 4 main methods to remember.
Use the mixin method to allow any object to trigger events.
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.
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.
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.
require('qi-events');
.once('myevent', console.log, console)
.trigger('myevent', 'something', 'something', 'darkside');
// > something something darkside
Backbone.js 0.9.10 (c) 2010-2013 Jeremy Ashkenas, DocumentCloud Inc. Backbone may be freely distributed under the MIT license. For all details and documentation: http://backbonejs.org
Added "use strict"
Converted to CommonJS module
Module is a constructor that can be used with class inheritence
Removed very minor dependencies on underscore.js and Backbone.js
Completely removed listenTo(), listenToOnce(), and stopListening() methods
Change eventsApi() to accept an array of event names
Change eventsApi() to receive function references instead of "action" strings
trigger() no longer calls eventsApi(), this is a very rare (and mostly unnecessary) use case that can be avoided
With trigger not using eventsApi(), it allowed further optimizations on eventsApi() and trigger()
Added aStart argument to triggerEvents() as a logical slice removing slice call for most cases
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, the following example should help.
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;
FAQs
A no nonsense event API (BASED ON Backbone.Events).
We found that qi-events demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
Security News
Research
The Socket Research Team uncovered a malicious Python package typosquatting the popular 'fabric' SSH library, silently exfiltrating AWS credentials from unsuspecting developers.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.