double-done
Advanced tools
Comparing version 0.0.2 to 0.0.3
20
index.js
@@ -8,21 +8,11 @@ "use strict"; | ||
var args = [null]; | ||
for(var i = 0; i < arguments.length; ++i) | ||
args.push(arguments[i]); | ||
done.apply(null, args); | ||
done.apply(null, [null].concat(Array.from(arguments))); | ||
}; | ||
ret.dd = function(callbackOk) { | ||
return function() { | ||
if(arguments[0]) | ||
return done(arguments[0]); | ||
return function(err) { | ||
if(err) | ||
return done(err); | ||
var args = []; | ||
for(var i = 1; i < arguments.length; ++i) | ||
args.push(arguments[i]); | ||
callbackOk.apply(null, args); | ||
callbackOk.apply(null, Array.prototype.slice.call(arguments, 1)); | ||
}; | ||
@@ -29,0 +19,0 @@ }; |
{ | ||
"name": "double-done", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Double Done design pattern", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -23,5 +23,5 @@ # double-done | ||
I have always liked __JavaScript__, but when I deeply understood its power, I have fallen in love with it! | ||
I always liked __JavaScript__, but when I deeply understood its power, I felt in love with it! | ||
One of the greatest aspect of __JavaScript__ is that, thanks to its other strenght points, it helps saving the _most | ||
One of the greatest aspect of __JavaScript__ is that it helps saving the _most | ||
expensive_ resource of the whole software life cycle: __developers time__. | ||
@@ -35,3 +35,3 @@ | ||
In my experience I found that so often I have to write an _async function_ which has to call some other async functions | ||
In my experience often happens that I have to write an _async function_ which has to call some other async functions | ||
to achieve its ojective. Many of the functions I wrote look like: | ||
@@ -60,3 +60,3 @@ | ||
After written some functions I found that continuously repeated block | ||
What I think is that the continuously repeated block | ||
@@ -68,3 +68,3 @@ ```javascript | ||
was just a time waster, both when writing and reading the code. | ||
is just a time waster, both when writing and reading the code. | ||
@@ -76,3 +76,3 @@ ### Hard Double Done desing pattern | ||
An environment where async functions accept two __done__ functions, one called in case of error and one called in case | ||
of success could help saving that time. My same async function would appear so: | ||
of success could help saving that time. My same async function would look like: | ||
@@ -97,9 +97,9 @@ ```javascript | ||
I immediately realized that changing __myAsyncFunctionSD__ in __myAsyncFunctionHDD__ would be a breaking change. More | ||
than this I had to considerate that not always calling an HDD async function is more confortable than calling a SD | ||
I immediately realized that changing __myAsyncFunctionSD__ in __myAsyncFunctionHDD__ would be a breaking change. Beside | ||
this I had to consider that calling an HDD async function is not always more comfortable than calling a SD | ||
async function (i.e.: when we have to do something both in cases of error or success). | ||
_For these two reasons I decided to write this package which may help us writing DD async funciotns_. | ||
_For these two reasons I decided to write this package which may helps writing DD async functions_. | ||
A __DD async funciotn__ should be documentete as follows: | ||
A __DD async funciotn__ should be documented as follows: | ||
@@ -117,6 +117,13 @@ ``` | ||
### Installation | ||
With [npm](https://www.npmjs.com/package/double-done): | ||
```sh | ||
npm install double-done | ||
``` | ||
## API definition | ||
```javascript | ||
require('doble-done'); | ||
require('double-done'); | ||
``` | ||
@@ -131,2 +138,4 @@ | ||
```javascript | ||
var dd = require('double-done'); | ||
function myAsyncFunctionDD(param1, done, doneOk) { | ||
@@ -136,8 +145,8 @@ doneOk = dd(done, doneOk); | ||
From now on __done__ and __doneOk__ are the functions to call respectively in case of error or success. | ||
From now on __done__ and __doneOk__ are the functions to be called respectively in case of error or success. | ||
### doneOk.dd(callbackOk) | ||
Lets us to call an SD async function writing only the __callbackOk__ function, if the called async function gets an | ||
error, __doneOk.dd__ makes it calling the original __done__ function. | ||
This function lets us call an SD async function writing only the __callbackOk__ function, if the called async function | ||
gets an error, __doneOk.dd__ makes it calling the original __done__ function. | ||
@@ -156,12 +165,20 @@ ```javascript | ||
## Licence | ||
### Compatibility | ||
The package it tested under [several Node.js versions](https://travis-ci.org/iccicci/double-done). | ||
__Required: Node.js 4.0__ | ||
### Licence | ||
[MIT Licence](https://github.com/iccicci/double-done/blob/master/LICENSE) | ||
## Bugs | ||
### Bugs | ||
Do not hesitate to report any bug or consideration [@github](https://github.com/iccicci/double-done/issues). | ||
## ChangeLog | ||
### ChangeLog | ||
* 2017-01-09 - v0.0.3 | ||
* README review and optimization | ||
* 2017-01-05 - v0.0.2 | ||
@@ -168,0 +185,0 @@ * Cosmetics |
15616
11
113
180