ConduitJS
ConduitJS copied to clipboard
Recursion
Very interesting module; I'm going to be using it in a large project I just started. As I was reading the code, I noticed what could potentially be a bottleneck: the next function appears to be recursive in sync mode. Should change this and submit a pull request?
var conduit = function() {
var idx = 0;
var retval;
var phase;
var next = function next() {
var args = Array.prototype.slice.call(arguments, 0);
var thisIdx = idx;
var step;
var nextArgs;
idx += 1;
if (thisIdx < _steps.all.length) {
step = _steps.all[thisIdx];
phase = (phase === "target") ? "after" : (step.isTarget) ? "target" : "before";
if (options.sync) {
if (phase === "before") {
nextArgs = step.fn.apply(step.context || _defaultContext, args);
next.apply(this, nextArgs || args);
} else {
retval = step.fn.apply(step.context || _defaultContext, args) || retval;
next.apply(this, [retval].concat(args));
}
} else {
step.fn.apply(step.context || _defaultContext, [next].concat(args));
}
}
};
next.apply(this, arguments);
return retval;
};