Last active
January 3, 2016 04:29
-
-
Save ianstormtaylor/8409798 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Modified `build` to encapsulate state in a `Build` object... | |
*/ | |
Builder.prototype.build = function (fn) { | |
var self = this; | |
this.lookup.end(function (err, components) { | |
if (err) return fn(err); | |
self.build = new Build(components); | |
self.batch.end(function (err) { | |
if (err) return fn(err); | |
fn(null, self.build); | |
}); | |
}) | |
}; | |
/** | |
* Initialize a new build with a `components` of components. | |
* | |
* @param {Array} components | |
*/ | |
function Build (components) { | |
this.components = components; | |
} | |
/** | |
* Loop through each of the components by `type`. | |
* | |
* @param {String} type | |
* @param {Function} fn | |
*/ | |
Build.prototype.each = function (type, fn) { | |
for (var i = 0; i < this.components.length; ++i) { | |
var files = this.components[i][type] || []; | |
for (var j = 0; j < files.length; ++j) { | |
fn(files[j], this.components[i]); | |
} | |
} | |
}; | |
/** | |
* Map each of the components by `type`. | |
* | |
* @param {String} type | |
* @param {Function} fn | |
*/ | |
Build.prototype.map = function (type, fn) { | |
for (var i = 0; i < this.components.length; ++i) { | |
var files = this.components[i][type] || []; | |
for (var j = 0; j < files.length; ++j) { | |
files[j] = fn(files[j], this.components[i]); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment