Permalink
Browse files

Rename to camelCase to match node better.

  • Loading branch information...
1 parent 811e2b6 commit 74653dddee837f19159df7abe2b4c4d855f1bf52 @creationix committed Feb 22, 2010
Showing with 38 additions and 38 deletions.
  1. +23 −23 README.markdown
  2. +1 −1 lib/do.js
  3. +14 −14 test.js
View
@@ -5,8 +5,8 @@
### Continuables
function divide(a, b) { return function (callback, errback) {
- // the timeout it to prove that we're working asynchronously
- setTimeout(function () {
+ // Use nextTick to prove that we're working asynchronously
+ process.nextTick(function () {
if (b === 0) {
errback(new Error("Cannot divide by 0"));
} else {
@@ -47,7 +47,7 @@ Takes an array of actions and runs them all in parallel. You can either pass in
Do.read(__filename)
)(function (passwd, self) {
// Do something
- }, error_handler);
+ }, errorHandler);
// Single argument
var actions = [
@@ -56,7 +56,7 @@ Takes an array of actions and runs them all in parallel. You can either pass in
];
Do.parallel(actions)(function (results) {
// Do something
- }, error_handler);
+ }, errorHandler);
### Do.chain(actions) {...}
@@ -75,7 +75,7 @@ Chains together several actions feeding the output of the first to the input of
}
)(function (stat) {
// Do something
- }, error_handler);
+ }, errorHandler);
// Single argument
var actions = [
@@ -89,7 +89,7 @@ Chains together several actions feeding the output of the first to the input of
];
Do.chain(actions)(function (stat) {
// Do something
- }, error_handler);
+ }, errorHandler);
### Do.map(array, fn) {...}
@@ -99,20 +99,20 @@ Takes an array and does an array map over it using the async callback `fn`. The
// Direct callback filter
var files = ['users.json', 'pages.json', 'products.json'];
- function load_file(filename, callback, errback) {
+ function loadFile(filename, callback, errback) {
fs.read(filename)(function (data) {
callback([filename, data]);
}, errback);
}
- Do.map(files, load_file)(function (contents) {
+ Do.map(files, loadFile)(function (contents) {
// Do something
- }, error_handler);
+ }, errorHandler);
// continuable based filter
var files = ['users.json', 'pages.json', 'products.json'];
Do.map(files, fs.read)(function (contents) {
// Do something
- }, error_handler);
+ }, errorHandler);
### Do.filter(array, fn) {...}
@@ -122,27 +122,27 @@ Takes an array and does an array filter over it using the async callback `fn`. T
// Direct callback filter
var files = ['users.json', 'pages.json', 'products.json'];
- function is_file(filename, callback, errback) {
+ function isFile(filename, callback, errback) {
fs.stat(filename)(function (stat) {
callback(stat.isFile());
}, errback);
}
- Do.filter(files, is_file)(function (filtered_files) {
+ Do.filter(files, isFile)(function (filtered_files) {
// Do something
- }, error_handler);
+ }, errorHandler);
// Continuable based filter
var files = ['users.json', 'pages.json', 'products.json'];
- function is_file(filename) { return function (callback, errback) {
+ function isFile(filename) { return function (callback, errback) {
fs.stat(filename)(function (stat) {
callback(stat.isFile());
}, errback);
}}
- Do.filter(files, is_file)(function (filtered_files) {
+ Do.filter(files, isFile)(function (filtered_files) {
// Do something
- }, error_handler);
+ }, errorHandler);
-### Do.filter_map(array, fn) {...}
+### Do.filterMap(array, fn) {...}
Takes an array and does a combined filter and map over it. If the result
of an item is undefined, then it's filtered out, otherwise it's mapped in.
@@ -155,30 +155,30 @@ The signature of `fn` is `function fn(item, callback, errback)` or any regular c
function check_and_load(filename, callback, errback) {
fs.stat(filename)(function (stat) {
if (stat.isFile()) {
- load_file(filename, callback, errback);
+ loadFile(filename, callback, errback);
} else {
callback();
}
}, errback);
}
- Do.filter_map(files, check_and_load)(function (filtered_files_with_data) {
+ Do.filterMap(files, check_and_load)(function (filtered_files_with_data) {
// Do something
- }, error_handler);
+ }, errorHandler);
// Continuable based filter
var files = ['users.json', 'pages.json', 'products.json'];
function check_and_load(filename) { return function (callback, errback) {
fs.stat(filename)(function (stat) {
if (stat.isFile()) {
- load_file(filename, callback, errback);
+ loadFile(filename, callback, errback);
} else {
callback();
}
}, errback);
}}
- Do.filter_map(files, check_and_load)(function (filtered_files_with_data) {
+ Do.filterMap(files, check_and_load)(function (filtered_files_with_data) {
// Do something
- }, error_handler);
+ }, errorHandler);
## Using with node libraries
View
@@ -98,7 +98,7 @@ exports.filter = function filter(array, fn) { return function (callback, errback
// Takes an array and does a combined filter and map over it. If the result
// of an item is undefined, then it's filtered out, otherwise it's mapped in.
// The signature of `fn` is `function fn(item, callback, errback)`
-exports.filter_map = function filter_map(array, fn) { return function (callback, errback) {
+exports.filterMap = function filterMap(array, fn) { return function (callback, errback) {
var counter = array.length;
var new_array = [];
array.forEach(function (item, index) {
View
28 test.js
@@ -8,7 +8,7 @@ process.mixin(require('sys'));
function debug(message, showHidden) {
puts(inspect(message, showHidden));
}
-function show_error(trace) {
+function showError(trace) {
puts("ERROR: " + inspect(trace));
}
@@ -25,13 +25,13 @@ Do.parallel(
slow_error()
)(function (bad, good) {
puts("Good: " + inspect(arguments));
-}, show_error);
+}, showError);
Do.parallel(
fs.readFile(__filename)
)(function (bad, good) {
puts("Good: " + inspect(arguments));
-}, show_error);
+}, showError);
Do.parallel(
Do.parallel([
@@ -41,7 +41,7 @@ Do.parallel(
fs.readFile(__filename)
)(function () {
puts("Good: " + inspect(arguments));
-}, show_error);
+}, showError);
// Filter callback that only let's files through by using stat
function only_files(filename, callback, errback) {
@@ -78,14 +78,14 @@ function loaddir(path) { return function (callback, errback) {
}, errback);
}, errback);
}}
-loaddir(__dirname)(debug, show_error);
+loaddir(__dirname)(debug, showError);
function fast_loaddir(path) { return function (callback, errback) {
fs.readdir(path)(function (filenames) {
- Do.filter_map(filenames, check_and_load)(callback, errback);
+ Do.filterMap(filenames, check_and_load)(callback, errback);
}, errback);
}}
-fast_loaddir(__dirname)(debug, show_error);
+fast_loaddir(__dirname)(debug, showError);
function get_keywords(text) { return function (callback, errback) {
setTimeout(function () {
@@ -104,18 +104,18 @@ function get_keywords(text) { return function (callback, errback) {
Do.chain(
fs.readFile(__filename),
get_keywords
-)(debug, show_error);
+)(debug, showError);
Do.chain(
fs.readdir(__dirname),
function (filenames) {
- return Do.filter_map(filenames, check_and_load);
+ return Do.filterMap(filenames, check_and_load);
}
-)(debug, show_error);
+)(debug, showError);
// Use the new continuable style map
var files = ["test.js", "README.markdown"];
-Do.map(files, fs.readFile)(debug, show_error);
+Do.map(files, fs.readFile)(debug, showError);
function safe_load(filename) { return function (callback, errback) {
fs.stat(filename)(function (stat) {
@@ -127,7 +127,7 @@ function safe_load(filename) { return function (callback, errback) {
}, errback);
}}
-// Use filter_map with new continuable based filter
+// Use filterMap with new continuable based filter
fs.readdir(__dirname)(function (list) {
- Do.filter_map(list, safe_load)(debug, show_error);
-}, show_error);
+ Do.filterMap(list, safe_load)(debug, showError);
+}, showError);

0 comments on commit 74653dd

Please sign in to comment.