jvent.js
An universal JavaScript Emitter based on NodeJS EventEmitter.
Installation
$ npm install jvent
$ bower install jvent
Standalone
Also, you can use the standalone version without components.
How-to
First, requires Jvent:
var Jvent = ;
Creates a new instance:
var emitter = ;
Now, defines a listener:
{ ;})
Then, adds a new event live with a listener:
emitter;
Emitsthe event with some data:
emitter;
API
Jvent#on(event, listener)
Adds a listener
to the collection for a specified event
.
event
- The name of the event you want to add.listener
- Listener you want to add from given event.
emitter;
Jvent#once(event, listener)
Adds a one time listener
to the collection for a specified event
. It will execute only once.
event
- The name of the event.listener
- Listener you want to add from the given event.
emitter;
Jvent#off(event, listener)
Removes a listener
from the collection for a specified event
.
event
- The name of the event.listener
- Listener you want to remove from the given event.
emitter;
Jvent#removeAllListeners(event)
Removes all listeners
from the collection for a specified event
.
event
- The name of the event you want to remove.
emitter;
Jvent#listeners(event)
Returns all listeners
from the collection for a specified event
.
event
- The name of the event.
emitter;
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.
event
- The name of the event you want to emit.
emitter;
With ❤️ by
- Guille Paz (Front-end developer | Web standards lover)
- E-mail: guille87paz@gmail.com
- Twitter: @pazguille
- Web: http://pazguille.me
License
MIT license. Copyright © 2016 @pazguille.