lib/createChain.js
function createChain(descriptor, callback) {
    if (typeof descriptor !== 'object') {
        throw new TypeError('createChain: descriptor is not an object: ' +
                            descriptor);
    }

    //Create the Chain class.
    function CustomChain(callback) {
        if (!(this instanceof CustomChain)) {
            return new CustomChain(callback);
        }
        CustomChain.super_.call(this, callback);
        CustomChain._lists.forEach(function(listName) {
            this._result[listName] = [];
        }, this);
    }
    util.inherits(CustomChain, Chain);
    if (callback) {
        CustomChain.prototype._callback = callback;
    }

    //This will come to contain the names of all lists in the chain.
    CustomChain._lists = [];

    //Add descriptor properties to Chain prototype.
    var keys = Object.keys(descriptor);
    keys.forEach(function(key) {
        var property = descriptor[key];
        //When a chain method is called, a number of actions need to take place.
        var actionList = [
            //1. Decide what item to store from the arguments.
            getArgumentInterpreter(property.elem),
            //2. Decide whether to set or push the item to store to an array.
            getPropertySetter(CustomChain, key, property.plural),
            //3. End the chain or return `this` for further chaining.
            getChainEnder(CustomChain, property.end)
        ].reverse();
        CustomChain.prototype[key] = _.compose.apply(null, actionList);
    });

    return CustomChain;
}
function createChain(descriptor, callback) {
    if (typeof descriptor !== 'object') {
        throw new TypeError('createChain: descriptor is not an object: ' +
                            descriptor);
    }

    //Create the Chain class.
    function CustomChain(callback) {
        if (!(this instanceof CustomChain)) {
            return new CustomChain(callback);
        }
        CustomChain.super_.call(this, callback);
        CustomChain._lists.forEach(function(listName) {
            this._result[listName] = [];
        }, this);
    }
    util.inherits(CustomChain, Chain);
    if (callback) {
        CustomChain.prototype._callback = callback;
    }

    //This will come to contain the names of all lists in the chain.
    CustomChain._lists = [];

    //Add descriptor properties to Chain prototype.
    var keys = Object.keys(descriptor);
    keys.forEach(function(key) {
        var property = descriptor[key];
        //When a chain method is called, a number of actions need to take place.
        var actionList = [
            //1. Decide what item to store from the arguments.
            getArgumentInterpreter(property.elem),
            //2. Decide whether to set or push the item to store to an array.
            getPropertySetter(CustomChain, key, property.plural),
            //3. End the chain or return `this` for further chaining.
            getChainEnder(CustomChain, property.end)
        ].reverse();
        CustomChain.prototype[key] = _.compose.apply(null, actionList);
    });

    return CustomChain;
}
function createChain ( descriptor , callback ) { if ( typeof descriptor !== 'object' ) { throw new TypeError ( 'createChain: descriptor is not an object: ' + descriptor ) ; } //Create the Chain class. function CustomChain ( callback ) { if ( ! ( this instanceof CustomChain ) ) { return new CustomChain ( callback ) ; } CustomChain . super_ . call ( this , callback ) ; CustomChain . _lists . forEach ( function ( listName ) { this . _result [ listName ] = [ ] ; } , this ) ; } util . inherits ( CustomChain , Chain ) ; if ( callback ) { CustomChain . prototype . _callback = callback ; } //This will come to contain the names of all lists in the chain. CustomChain . _lists = [ ] ; //Add descriptor properties to Chain prototype. var keys = Object . keys ( descriptor ) ; keys . forEach ( function ( key ) { var property = descriptor [ key ] ; //When a chain method is called, a number of actions need to take place. var actionList = [ //1. Decide what item to store from the arguments. getArgumentInterpreter ( property . elem ) , //2. Decide whether to set or push the item to store to an array. getPropertySetter ( CustomChain , key , property . plural ) , //3. End the chain or return `this` for further chaining. getChainEnder ( CustomChain , property . end ) ] . reverse ( ) ; CustomChain . prototype [ key ] = _ . compose . apply ( null , actionList ) ; } ) ; return CustomChain ; }
Take a descriptor object and return a Chain constructor.
An optional default callback for this type of Chain.
Take a descriptor object and return a Chain constructor . An optional default callback for this type of Chain .