Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ProcessingChain, findFirstValidItem, handler param #17

Open
smart--petea opened this issue Sep 6, 2014 · 1 comment
Open

ProcessingChain, findFirstValidItem, handler param #17

smart--petea opened this issue Sep 6, 2014 · 1 comment

Comments

@smart--petea
Copy link
Contributor

The functionProcessingChain.prototype.runChain has the snippet

ProcessingChain.prototype.runChain = function( req, res, finalFn, handler ) {
        ...
    if(handler) {
        var firstItem = self.findFirstValidItem(handler.name)
        firstItem.fn(req, res, next)
    } else {
        this.chain[0].fn(req, res, next )
    }
};

But, function ProcessingChain.prototype.findFirstValidItem

ProcessingChain.prototype.findFirstValidItem = function(name) {
    if(!name) return this.chain[0]  
    ...
}

check its argument name to be not undefined and if name is undefined return first element from chain (else branch of if condition statement from runChain function does the same.)

I think the if statement from runChain function can be replaced and the function get the form

ProcessingChain.prototype.runChain = function( req, res, finalFn, handler ) {
        ...

    self.findFirstValidItem(handler.name)(req, res, next);      
};
@smart--petea
Copy link
Contributor Author

in findFirstValidItem function the statement

item.names && Array.isArray(item.names) && item.names.length > 0

is equivelent to

item.names && Array.isArray(item.names) && item.names.length 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants