1.0.2 • Published 10 years ago

node-bound v1.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
10 years ago

Bound Build Status

a simple way do a large amount of event bindings. Heavily inspired by backbones event bindings in views. Bound2

To Install

$ npm install node-bound

This also works with browserify.

Example Usage

Lets say you have a controller, that you want to consume some events from a common messaging system that uses events.

var emitter = new ( require( 'events' ).EventEmitter )(), // new EventEmitter()
    bound = require('node-bound');

function UserController ( data ) {
    bound( emitter, {
        'user:save' : 'handleSave', // emit.addListener( 'user:save', this.handleSave.bind( this ) );
        'user:create' : [ 'handleCreate', data.anonId ] , // support for partials
        'user:delete' : this.handleDelete // pass a function instead
    }, this );
}

UserController.prototype.handleSave = function ( ) { 
    console.log( this ); // [ Object UserController ] 
};
UserController.prototype.handleCreate = function ( partialParam ) { /* ... */ };
UserController.prototype.handleDelete = function ( ) { /* ... */ };

This will bind all the events in the given context to the right method and keep the context that is given, which is great when in the context of a constructor.

    bound( emitter, eventMethodObject, context );
// eventEmitter ^ event : method ^        ^ context of method

There is also a bunch of aliases: bound.on, bound.bind, bound.addEventListener, bound.addListener

You can also unbind events that get bound by bound.

    bound.unbind( emitter, eventMethodObject, context );

Unbinding also has aliases: bound.off, bound.unbind, bound.removeEventListener, bound.removeListener

Contributing

To contribute you will need to make sure all the test are passing. To run the test you will need mocha. Then install the dependecies.

$ npm install

Then to run the test

$ npm test
1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago

0.2.2

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.0

11 years ago

0.0.6

11 years ago

0.0.5

11 years ago

0.0.4

11 years ago

0.0.3

11 years ago