node-binder
Mixin class for managing bindings in Node.js.
Install
npm install node-binder
Interfaces
interface Binder attribute Array bindings; Binding ; Binding ; Binding ; void
interface Binding attribute Binder binder; attribute String event; attribute Function handler; attribute EventEmitter emitter; void
API
Binder
The Binder
class helps you manage bindings when gluing various classes and
events together. When your program or instance no longer needs these bindings,
simply call binder.destroy()
to automatically remove all bindings to their
respective EventEmitter
s.
Binder#bind(emitter, event, handler [, context])
Binds handler
to the event
of emitter
.
Aliases: on
, addListener
Arguments
emitter
- Any object that inheriets fromEventEmitter
.event
- Name of the event onemitter
to which thehandler
will be bound.handler
- Function handler for theevent
.context
- Optional. Context with which to execute thehandler
.
Returns
Binding
Example
var binding = binder; someEventEmitter binding;
Binder#once(emitter, event, handler [, context])
Binds handler
to one emission of event
on emitter
.
Aliases: one
Arguments
emitter
- Any object that inheriets fromEventEmitter
.event
- Name of the event onemitter
to which thehandler
will be bound.handler
- Function handler for theevent
.context
- Optional. Context with which to execute thehandler
.
Returns
Binding
Example
var binding = binder; someEventEmitter
Binder#bindKey(emitter, event, object, key, [, context])
Binds object[key]
to the event
of emitter
.
Arguments
emitter
- Any object that inheriets fromEventEmitter
.event
- Name of the event onemitter
to which thehandler
will be bound.handler
- Function handler for theevent
.context
- Optional. Context with which to execute thehandler
.
Returns
Binding
Example
var someLiteral = { console; } { console; } ; var binding = binder; someLiteraldataHandler = someLiteralfoo;someEventEmitter; // "beep" someLiteraldataHandler = someLiteralbar;someEventEmitter; // "boop"
Binder#destroy()
Unbinds all events previously bound using bind
.
Aliases: removeAllListeners
Example
binder;binder;binder;binder; /* Later on when you no longer need someClassThatHandlesStreams… */binder;
Binding
All Binder
methods that perform a binding return
a Binding
instance which represents the binding created from the Binder
.
This Binding
instance has only one method, unbind
, which removes it's
handler from it's EventEmitter
.
Binding#unbind()
Unbinds the binding it represents.
Aliases: off
, removeListener
Example
var binding = binder; binding;
License
MIT license