Skip to content

Commit

Permalink
Added QUTIL.deep and changed to
Browse files Browse the repository at this point in the history
  • Loading branch information
User authored and User committed Apr 30, 2010
1 parent 7253e6a commit 5c565e4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGES
@@ -0,0 +1,6 @@

0.2.3

* `narwhal/promise-util`
** Renamed `group` to `all`
** Added `deep` for a promise for a fully resolved object tree
26 changes: 23 additions & 3 deletions lib/narwhal/promise-util.js
Expand Up @@ -43,7 +43,7 @@ QUTIL.reduce = function (values, callback, basis) {
* @returns {Promise * Array} a promise for an array of each
* resolved value respectively.
*/
QUTIL.group = function (values) {
QUTIL.all = function (values) {
return QUTIL.reduce(values, function (values, value) {
return values.concat([value]);
}, []);
Expand Down Expand Up @@ -83,7 +83,27 @@ QUTIL.sum = function (values) {
* @param {Function} rejected optional
*/
QUTIL.whenAll = function (values, resolved, rejected) {
return Q.when(QUTIL.group(values), resolved, rejected);
return Q.when(QUTIL.all(values), resolved, rejected);
};

QUTIL.deep = function (object) {
return Q.when(object, function (object) {
if (UTIL.no(object)) {
return object;
} if (Array.isArray(object)) {
return QUTIL.all(object.map(QUTIL.deep));
} else if (typeof object === "object") {
return QUTIL.whenAll(UTIL.mapApply(object, function (key, value) {
return Q.when(QUTIL.deep(value), function (value) {
return [key, value];
});
}), function (pairs) {
return UTIL.object(pairs);
});
} else {
return object;
}
});
};

/**
Expand Down Expand Up @@ -115,7 +135,7 @@ QUTIL.mapDefer = function (values, callback, thisp) {
* resolved value.
*/
QUTIL.map = function (values, callback, thisp) {
return QUTIL.group(QUTIL.mapDefer(values, callback, thisp));
return QUTIL.all(QUTIL.mapDefer(values, callback, thisp));
};

QUTIL.loop = function (provider, block) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "narwhal-lib",
"version": "0.2.2experimental",
"version": "0.2.3",
"description": "A general purpose JavaScript platform",
"keywords": ["javascript", "engine", "platform"],
"author": "Tom Robinson (http://tlrobinson.net/) <tom@280north.com>",
Expand Down

0 comments on commit 5c565e4

Please sign in to comment.