Name: ev-emitter
Owner: Metafizzy
Description: :bell: Lil' event emitter
Created: 2016-01-06 23:58:05.0
Updated: 2018-04-13 06:47:13.0
Pushed: 2017-07-06 13:47:09.0
Size: 8
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Lil' event emitter ? add a little pub/sub
EvEmitter adds publish/subscribe pattern to a browser class. It's a smaller version of Olical/EventEmitter. That EventEmitter is full featured, widely used, and great. This EvEmitter has just the base event functionality to power the event API in libraries like Isotope, Flickity, Masonry, and imagesLoaded.
nherit prototype, IE8+
ass.prototype = new EvEmitter();
nherit prototype, IE9+
ass.prototype = Object.create( EvEmitter.prototype );
ixin prototype
tend( MyClass.prototype, EvEmitter.prototype );
ingle instance
emitter = new EvEmitter();
Add an event listener.
ter.on( eventName, listener )
eventName
- String - name of the eventlistener
- FunctionRemove an event listener.
ter.off( eventName, listener )
Add an event listener to be triggered only once.
ter.once( eventName, listener )
Trigger an event.
ter.emitEvent( eventName, args )
eventName
- String - name of the eventargs
- Array - arguments passed to listenersRemoves all event listeners.
ter.allOff()
reate event emitter
emitter = new EventEmitter();
isteners
tion hey( a, b, c ) {
nsole.log( 'Hey', a, b, c )
tion ho( a, b, c ) {
nsole.log( 'Ho', a, b, c )
tion letsGo( a, b, c ) {
nsole.log( 'Lets go', a, b, c )
ind listeners
ter.on( 'rock', hey )
ter.once( 'rock', ho )
rigger letsGo once
ter.on( 'rock', letsGo )
mit event
ter.emitEvent( 'rock', [ 1, 2, 3 ] )
> 'Hey', 1, 2, 3
> 'Ho', 1, 2, 3
> 'Lets go', 1, 2, 3
nbind
ter.off( 'rock', ho )
ter.emitEvent( 'rock', [ 4, 5, 6 ] )
> 'Hey' 4, 5, 6
EvEmitter is released under the MIT License. Have at it.