vnt

0.0.1 • Public • Published

vnt

Take events out of your EventEmitter

Once upon a time, events were trapped in their emitters. They yearned to get out, and noone would show them a way...until now!

vnt allows you to take the events out of your EventEmitter derived classes. With events as their own objects, they can be passed around your code as first-class citizens:

  • Pass them as function arguments!
  • Return them from a function!
  • Assign them to a variable!

Quickstart

Seriously, though - this is super quick.

All you need to do to use vnt is use it as a drop-in replacement for the EventEmitter:

var EventEmitter = require('vnt').EventEmitter;

All that's left to do is to free your events:

var obj = new EventEmitter();
 
// Free your event! Show him the world!
var changeEvent = obj.event('change');

Any valid function from EventEmitter that targets an event is fair game:

.emit

Emit an event with changeEvent.emit()

.addListener / .on

Add a new listener with changeEvent.addListener(fn)

.once

Add a one-time listener with changeEvent.once(fn)

.removeListener

Remove a listener with changeEvent.removeListener(fn)

.removeAllListeners

Remove all listeners with changeEvent.removeAllListeners()

.listeners

Retrieve an array of listeners with changeEvent.listeners()


Feel free to contribute. The tests are their own beast, and convergence with the node.js specs would be sublime.


Want asynchronous eventing? Check out pwn.

@zzmp

Package Sidebar

Install

npm i vnt

Weekly Downloads

5

Version

0.0.1

License

MIT

Last publish

Collaborators

  • zzmp