ev-emitter

WebJar for ev-emitter

License

License

MIT
GroupId

GroupId

org.webjars.bower
ArtifactId

ArtifactId

ev-emitter
Last Version

Last Version

1.1.1
Release Date

Release Date

Type

Type

jar
Description

Description

ev-emitter
WebJar for ev-emitter
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/metafizzy/ev-emitter

Download ev-emitter

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.bower/ev-emitter/ -->
<dependency>
    <groupId>org.webjars.bower</groupId>
    <artifactId>ev-emitter</artifactId>
    <version>1.1.1</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.bower/ev-emitter/
implementation 'org.webjars.bower:ev-emitter:1.1.1'
// https://jarcasting.com/artifacts/org.webjars.bower/ev-emitter/
implementation ("org.webjars.bower:ev-emitter:1.1.1")
'org.webjars.bower:ev-emitter:jar:1.1.1'
<dependency org="org.webjars.bower" name="ev-emitter" rev="1.1.1">
  <artifact name="ev-emitter" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.bower', module='ev-emitter', version='1.1.1')
)
libraryDependencies += "org.webjars.bower" % "ev-emitter" % "1.1.1"
[org.webjars.bower/ev-emitter "1.1.1"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

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

// Inherit prototype, IE8+
MyClass.prototype = new EvEmitter();

// Inherit prototype, IE9+
MyClass.prototype = Object.create( EvEmitter.prototype );

// Mixin prototype
_.extend( MyClass.prototype, EvEmitter.prototype );

// single instance
var emitter = new EvEmitter();

on

Add an event listener.

emitter.on( eventName, listener )
  • eventName - String - name of the event
  • listener - Function

off

Remove an event listener.

emitter.off( eventName, listener )

once

Add an event listener to be triggered only once.

emitter.once( eventName, listener )

emitEvent

Trigger an event.

emitter.emitEvent( eventName, args )
  • eventName - String - name of the event
  • args - Array - arguments passed to listeners

allOff

Removes all event listeners.

emitter.allOff()

Code example

// create event emitter
var emitter = new EvEmitter();

// listeners
function hey( a, b, c ) {
  console.log( 'Hey', a, b, c )
}

function ho( a, b, c ) {
  console.log( 'Ho', a, b, c )
}

function letsGo( a, b, c ) {
  console.log( 'Lets go', a, b, c )
}

// bind listeners
emitter.on( 'rock', hey )
emitter.on( 'rock', ho )
// trigger letsGo once
emitter.once( 'rock', letsGo )

// emit event
emitter.emitEvent( 'rock', [ 1, 2, 3 ] )
// => 'Hey', 1, 2, 3
// => 'Ho', 1, 2, 3
// => 'Lets go', 1, 2, 3

// unbind
emitter.off( 'rock', ho )

emitter.emitEvent( 'rock', [ 4, 5, 6 ] )
// => 'Hey' 4, 5, 6

License

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

org.webjars.bower

Metafizzy

Delightful JS plugins

Versions

Version
1.1.1
1.0.2
1.0.1