node package manager


Basic event emitter


A simple event emitter. I implemented my own so I could optimise for performance and implement new features as I require. The main advantage of this implementation is its handling of context. It allows you to specify a context when you create a subscription (a la backbone.js) but also takes this into account when unsubscribing. So when unsubscribing you have three levels of specificity available to you. topic(s), topic(s)+callback, and topic(s)+callback+context. This makes it possible to work with methods defined on an objects prototype without wrapping them since you now have a way of differentiating between subscriptions belonging to different instances.

Download the production version or the development version.

With component

$ component install jkroso/emitter

with npm

$ npm install jkroso/emitter

Generate an instance of Emitter

var emitter = new Emitter

An alternative constructor syntax

Add emitter behavior to any object

Generate an event

emitter.emit('event', new Date)

Add a subscription under a topic name

emitter.on('event', function(data){})
emitter.on('a | b', function(data){})

Add the subscription but insure it never called more than once

Remove subscriptions // clears all topics'topic') // clears all handlers under 'topic''topic', fn) // removes fn from 'topic''topic', fn, window) // removes fn from 'topic' with context of `window` 

Throw down!

(Nothing yet)

Copyright (c) 2012 Jakeb Rosoman
Licensed under the MIT license.