Browse files

Move Combo to Do.combo and rewrite it in closure style instead of OO …

…style.
  • Loading branch information...
1 parent d7aa46d commit 37137ab429a3b4ae32efbbc2ab31054ddf095116 @creationix committed Feb 21, 2010
Showing with 23 additions and 24 deletions.
  1. +1 −24 build.js
  2. +22 −0 vendor/do.js
View
25 build.js
@@ -69,29 +69,6 @@ function process_folder(path) { return function (callback, errback) {
}, errback);
}}
-// combo library. Allows to group several callbacks.
-function Combo(callback) {
- this.callback = callback;
- this.items = 0;
- this.results = [];
-}
-Combo.prototype = {
- add: function () {
- var self = this,
- id = this.items;
- this.items++;
- return function () {
- self.check(id, arguments);
- };
- },
- check: function (id, arguments) {
- this.results[id] = Array.prototype.slice.call(arguments);
- this.items--;
- if (this.items == 0) {
- this.callback.apply(this, this.results);
- }
- }
-};
// Simple loop over objects.
@@ -129,7 +106,7 @@ exports.build = function (next, error_handler) {
process_folder(ARTICLE_DIR),
process_folder(SKIN_DIR)
)(function (authors, articles, templates) {
- var group = new Combo(function() {
+ var group = Do.combo(function() {
next("Done!\n" + Array.prototype.map.call(arguments, function (args) {
return args[0] + " - " + args[1];
}).join("\n"))
View
22 vendor/do.js
@@ -119,6 +119,28 @@ exports.filter_map = function filter_map(array, fn) { return function (callback,
});
}};
+// Allows to group several callbacks.
+exports.combo = function combo(callback) {
+ var items = 0,
+ results = [];
+ function add() {
+ var id = items;
+ items++;
+ return function () {
+ check(id, arguments);
+ };
+ }
+ function check(id, arguments) {
+ results[id] = Array.prototype.slice.call(arguments);
+ items--;
+ if (items == 0) {
+ callback.apply(this, results);
+ }
+ }
+ return { add: add, check: check };
+}
+
+
// Takes any async lib that uses callback based signatures and converts
// the specified names to continuable style and returns the new library.
exports.convert = function (lib, names) {

0 comments on commit 37137ab

Please sign in to comment.