Comparing version 0.1.0 to 0.1.1
@@ -224,3 +224,3 @@ /* | ||
*/ | ||
SuperGroup.prototype.cb = function (cb, _onlySuccess) { | ||
SuperGroup.prototype.onComplete = function (cb, _onlySuccess) { | ||
if (!cb) { return this.f; } | ||
@@ -237,2 +237,7 @@ if (!_onlySuccess) { | ||
} | ||
// backwards compatibility | ||
SuperGroup.prototype.cb = SuperGroup.prototype.onComplete; | ||
SuperGroup.prototype.success = SuperGroup.prototype.onSuccess; | ||
SuperGroup.prototype.error = SuperGroup.prototype.onError; | ||
@@ -247,3 +252,3 @@ /** | ||
if (!cb) { return this.f; } | ||
return this.cb(function() { | ||
return this.onComplete(function() { | ||
!this.isError && cb.apply(this, slice.call(arguments, 1)); | ||
@@ -259,3 +264,3 @@ }.bind(this), true); | ||
if (!cb) { return this.f; } | ||
return this.cb(function() { | ||
return this.onComplete(function() { | ||
this.isError && cb.apply(this, arguments); | ||
@@ -262,0 +267,0 @@ }.bind(this)); |
{ | ||
"name": "ff", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Concise, Powerful Asynchronous Flow Control in JavaScript", | ||
@@ -5,0 +5,0 @@ "engine": [ "node >=0.2.0" ], |
@@ -40,3 +40,3 @@ # <img src="http://f.cl.ly/items/3K113g321o0n0W0Y0Z33/Fast%20Forward%20Icon%20in%2032x32%20px.png" width=25 height=25> ff: Concise, Powerful Asynchronous JavaScript Flow Control | ||
} | ||
).cb(nextFn); | ||
).onComplete(nextFn); | ||
``` | ||
@@ -167,3 +167,3 @@ | ||
from the current function). The result handlers (`.onSuccess()` and | ||
`.cb()`) will be called as soon as the current step returns. No other | ||
`.onComplete()`) will be called as soon as the current step returns. No other | ||
steps will be executed afterward. | ||
@@ -175,3 +175,3 @@ | ||
occurred (after you return from the current function). The result | ||
handlers (`.onError()` and `.cb()`) will be called as soon as the | ||
handlers (`.onError()` and `.onComplete()`) will be called as soon as the | ||
current step returns. No other steps will be executed afterward. | ||
@@ -190,3 +190,3 @@ | ||
### Finally, remember to handle the result! (`.cb`, `.onError`, `.onSuccess`) | ||
### Finally, remember to handle the result! (`.onComplete`, `.onError`, `.onSuccess`) | ||
@@ -200,6 +200,6 @@ After you've called `ff()` with your steps, you'll want to handle the | ||
// steps here... | ||
).cb(resultHandler); | ||
).onComplete(resultHandler); | ||
``` | ||
That final callback will be passed arguments node-style: `cb(err, | ||
That final callback will be passed arguments node-style: `onComplete(err, | ||
results...)`. The number of arguments after `err` depends on how many | ||
@@ -211,5 +211,5 @@ slots you passed from the last function in the chain. | ||
#### `f.cb( function (err, results...) { } )` | ||
#### `f.onComplete( function (err, results...) { } )` | ||
A `.cb()` result handler will *always* be called, whether or not an | ||
A `.onComplete()` result handler will *always* be called, whether or not an | ||
error occurred. An error object will be passed first (null if there | ||
@@ -238,3 +238,3 @@ was no error.) | ||
the callbacks (as in `callback(err, result)`), the error will be | ||
propagated immediately to your result handlers (`.cb()` and | ||
propagated immediately to your result handlers (`.onComplete()` and | ||
`.onError()`). If a result handler throws an exception, that exception | ||
@@ -269,5 +269,5 @@ will bubble up into Node's `unhandledException` handler or the | ||
// If any call had returned an err, this function would not be | ||
// called, and the error would have been passed down to `cb`. | ||
// called, and the error would have been passed down to `onComplete`. | ||
} | ||
).cb(nextFn); | ||
).onComplete(nextFn); | ||
``` | ||
@@ -283,3 +283,3 @@ | ||
two, | ||
).cb(three); | ||
).onComplete(three); | ||
``` | ||
@@ -291,7 +291,7 @@ | ||
f.next(two); | ||
f.cb(three); | ||
f.onComplete(three); | ||
``` | ||
Error handling is actually quite simple: If an error occurs in any | ||
step, it gets passed down to the `cb` or `onError` handler, skipping over any `.next` handlers. | ||
step, it gets passed down to the `onComplete` or `onError` handler, skipping over any `.next` handlers. | ||
@@ -326,3 +326,3 @@ --- | ||
In addition to using `then` to attach completion handlers, you can also use the regular | ||
ff `.onSuccess()`, `.onError()`, and `.cb()` to do so. | ||
ff `.onSuccess()`, `.onError()`, and `.onComplete()` to do so. | ||
@@ -390,3 +390,3 @@ And just like regular `ff`, you can pass functions into `ff.defer(...)`: | ||
} | ||
).cb(nextFn); // <-- usually you'll have someone else handle a (err, result...) callback | ||
).onComplete(nextFn); // <-- usually you'll have someone else handle a (err, result...) callback | ||
@@ -397,3 +397,3 @@ // Add a timeout (which would result in a failure with a timeout Error | ||
// Don't forget all the result handler options (attach as many as you like!) | ||
f.cb(function (err, args...) { }); // triggered on both success and error | ||
f.onComplete(function (err, args...) { }); // triggered on both success and error | ||
f.onSuccess(function (args...) { }); // only on success | ||
@@ -400,0 +400,0 @@ f.onError(function (err) { }); // only on error |
@@ -150,3 +150,3 @@ if (typeof module !== "undefined") { | ||
assert.fail(); | ||
}).cb(function(err, two) { | ||
}).onComplete(function(err, two) { | ||
assert(err == 4 && !two); | ||
@@ -285,3 +285,3 @@ done(); | ||
n++; | ||
}).cb(function(e) { | ||
}).onComplete(function(e) { | ||
if (e) throw e; | ||
@@ -288,0 +288,0 @@ assert(n == 2); |
33692
707