npm.io
0.0.2 • Published 11 years ago

context-events

Licence
Version
0.0.2
Deps
1
Vulns
0
Weekly
0

context-events


God bless arrow functions! The need for this is nil in a post-es2015 world

Node's event emitter with optional context argument, like Backbone.

Forked from https://github.com/Gozala/events

Use require('context-events/monkey') to get a patched version of the original Events. Should be fully backwords compatible, only acts differently when given context argument.

Install

npm install context-events

Require

var EventEmitter = require('context-events')

Usage

See the node.js event emitter docs

Modified proto methods

All context arguments are optional

addListener / on / once (type, listener, context)

Set the context the listener will be called from it.

The first argument in the callback will be the callee. Example:

emitter.on('type', listener, context);
emitter.emit('type', arg1, arg2);
->
listener.call(context, emitter, arg1, arg2)
removeListener (type, listener, context)

Remove a listener added with a context

removeAllListeners (type, context)

Remove listeners with a certain context, type null for all

Keywords