Event emmiter for everything.
JavaScript
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
README.md
TODO
event_api_notes.md
index.js
package.json
tap_testem.js
testem.yml
tests.html
tests.js

README.md

Emmitt - Event Emitter for Everything

Emmitt is a small Javascript library that can emit events on any Javascript object. It works with

  1. Plain Javascript objects (POJOs)
  2. jQuery wraped DOM elements
  3. Backbone models or objects extended with Backbone.Events
  4. Raw DOM elements

Install

Install via NPM npm install emmitt; or bower bower install emmitt.

Usage

Simple example

var E = require('emmitt');

var obj = new SomeObject();
E.on(obj, 'refresh', function(data){
  console.log(obj, 'was refreshed with', data);
});

// then later on...
E.emit(obj, 'refresh', data);

If the object in question is a jQuery wrapped DOM element, a Backbone model, or a raw DOM element, event handling will delegate properly to their respective methods for event handling.

API

  • on(object, event, handler) - registers an event handler for a given event on an object.
  • off(object, event, [handler]) - unregisters an event handler. If handler is not provided, removes all event handlers for the given event. Aliased to removeListener.
  • emit(object, event, [...args]) - emits an event on an object with the given arguments. Aliased to trigger.
  • allOff(object) - remove all event handlers from an object. Aliased to clearAllListeners.

Support

  • Node
  • Standard compliant browsers
  • Non-standard IE 7 and up