metafizzy/ev-emitter

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

Homepage:

Size: 8

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

EvEmitter

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.

API
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();
on

Add an event listener.

ter.on( eventName, listener )
off

Remove an event listener.

ter.off( eventName, listener )
once

Add an event listener to be triggered only once.

ter.once( eventName, listener )
emitEvent

Trigger an event.

ter.emitEvent( eventName, args )
allOff

Removes all event listeners.

ter.allOff()
Code example
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
License

EvEmitter is released under the MIT License. Have at it.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.