Home

Awesome

jvent.js

An universal JavaScript Emitter based on NodeJS EventEmitter.

NPM version License Build status Coverage Status Dependency status devDependency status downloads

Installation

$ npm install jvent

$ bower install jvent

Standalone

Also, you can use the standalone version without components.

<script src="../dist/jvent.js"></script>

How-to

First, requires Jvent:

var Jvent = require('jvent');

Creates a new instance:

var emitter = new Jvent();

Now, defines a listener:

function listener(arg1, arg2) {
    alert(arg1 + ' '+ arg2);
})

Then, adds a new event live with a listener:

emitter.on('live', listener);

Emitsthe event with some data:

emitter.emit('live', 'param1', 'param2');

API

Jvent#on(event, listener)

Adds a listener to the collection for a specified event.

emitter.on('live', listener);

Jvent#once(event, listener)

Adds a one time listener to the collection for a specified event. It will execute only once.

emitter.once('live', listener);

Jvent#off(event, listener)

Removes a listener from the collection for a specified event.

emitter.off('live', listener);

Jvent#removeAllListeners(event)

Removes all listeners from the collection for a specified event.

emitter.removeAllListeners('live');

Jvent#listeners(event)

Returns all listeners from the collection for a specified event.

emitter.listeners('live');

Jvent#emit(event, [arg1], [arg2], [...])

Execute each of the listeners collection in order with the given parameters. All emitters emit the event newListener when new listeners are added.

emitter.emit('live', 'data1', 'data2');

With :heart: by

License

MIT license. Copyright © 2016 @pazguille.