branch.js =========

npm install branch
2 downloads in the last day
5 downloads in the last week
8 downloads in the last month

A simple EventEmitter example:

va branch = require("branch"),
EventEmitter = require("events").EventEmitter;

//first give branch 
var chain = branch(EventEmitter);
chain.source([new EventEmitter(), new EventEmitter()]);

//called twice - once per each event emitter
chain.on("hello-world", function(event) {


//called against each event emitter

With soda.js

var chain = branch({})



schemas - class, object, or array of methods to use in the chain. For example:

//using a class
var chain = branch(EventEmitter);
chain.on("hello-world", function(){});

//using an object or prototype
chain = branch({
    "helloWorld": function() {



//using an array
chain = branch(['helloWorld']);

Creates a new chained object


sets the source for the chain

chain.pre(method, factory)

middleware for any method before it's actually called. If method is omitted, then all methods will be run the the middleware function.

var chain = branch(EventEmitter).
pre("on", function(type, callback, next) {
  next("prefix-" + type, callback);
source([new EventEmitter()]);

//actual listener 
chain.on("hello", function() {


chain.emit("prefix-hello", "world!");


adds an item to the chain

Result chain.[CHAIN_METHOD]

created from the prototype, array, or object in the .branch() function.

hain result.async()

Makes the chain asynchronous

var chain = branch(Array);
chain.source([1], [2], [3], [4]); {
  return n + 1;
}).async(function(err, values) {

chain result.sync()

Makes the chain synchronous - values from returned arrays will be

var chain = branch(Array);
var result = {
  return n + 1;

console.log(result); //[2], [3], [4], [5]
npm loves you