Commit a61853dc authored by Romain Courteaud's avatar Romain Courteaud

Publish build version of rsvp.

parent 595f1186
"use strict"; "use strict";
var defer = require("./defer").defer; var Promise = require("./promise").Promise;
function size(object) { function size(object) {
var s = 0; var s = 0;
...@@ -12,38 +12,61 @@ function size(object) { ...@@ -12,38 +12,61 @@ function size(object) {
} }
function hash(promises) { function hash(promises) {
var results = {}, deferred = defer(), remaining = size(promises);
function canceller() {
var promise,
key;
for (key in promises) {
if (promises.hasOwnProperty(key)) {
promise = promises[key];
if (promise && typeof promise.then === 'function' &&
typeof promise.cancel === 'function') {
promise.cancel();
}
}
}
}
return new Promise(function(resolve, reject) {
var results = {}, remaining = size(promises),
promise;
if (remaining === 0) { if (remaining === 0) {
deferred.resolve({}); resolve(results);
} }
var resolver = function(prop) { function resolver(key) {
return function(value) { return function(value) {
resolveAll(prop, value); resolveAll(key, value);
};
}; };
}
var resolveAll = function(prop, value) { function resolveAll(key, value) {
results[prop] = value; results[key] = value;
if (--remaining === 0) { if (--remaining === 0) {
deferred.resolve(results); resolve(results);
}
} }
};
var rejectAll = function(error) { function cancelAll(rejectionValue) {
deferred.reject(error); reject(rejectionValue);
}; canceller();
}
for (var prop in promises) { for (var prop in promises) {
if (promises[prop] && typeof promises[prop].then === 'function') { promise = promises[prop];
promises[prop].then(resolver(prop), rejectAll);
if (promise && typeof promise.then === 'function') {
promise.then(resolver(prop), cancelAll);
} else { } else {
resolveAll(prop, promises[prop]); resolveAll(prop, promise);
} }
} }
return deferred.promise; }, canceller
);
} }
......
...@@ -342,10 +342,10 @@ define("rsvp/events", ...@@ -342,10 +342,10 @@ define("rsvp/events",
__exports__.EventTarget = EventTarget; __exports__.EventTarget = EventTarget;
}); });
define("rsvp/hash", define("rsvp/hash",
["rsvp/defer","exports"], ["rsvp/promise","exports"],
function(__dependency1__, __exports__) { function(__dependency1__, __exports__) {
"use strict"; "use strict";
var defer = __dependency1__.defer; var Promise = __dependency1__.Promise;
function size(object) { function size(object) {
var s = 0; var s = 0;
...@@ -358,38 +358,61 @@ define("rsvp/hash", ...@@ -358,38 +358,61 @@ define("rsvp/hash",
} }
function hash(promises) { function hash(promises) {
var results = {}, deferred = defer(), remaining = size(promises);
function canceller() {
var promise,
key;
for (key in promises) {
if (promises.hasOwnProperty(key)) {
promise = promises[key];
if (promise && typeof promise.then === 'function' &&
typeof promise.cancel === 'function') {
promise.cancel();
}
}
}
}
return new Promise(function(resolve, reject) {
var results = {}, remaining = size(promises),
promise;
if (remaining === 0) { if (remaining === 0) {
deferred.resolve({}); resolve(results);
} }
var resolver = function(prop) { function resolver(key) {
return function(value) { return function(value) {
resolveAll(prop, value); resolveAll(key, value);
};
}; };
}
var resolveAll = function(prop, value) { function resolveAll(key, value) {
results[prop] = value; results[key] = value;
if (--remaining === 0) { if (--remaining === 0) {
deferred.resolve(results); resolve(results);
}
} }
};
var rejectAll = function(error) { function cancelAll(rejectionValue) {
deferred.reject(error); reject(rejectionValue);
}; canceller();
}
for (var prop in promises) { for (var prop in promises) {
if (promises[prop] && typeof promises[prop].then === 'function') { promise = promises[prop];
promises[prop].then(resolver(prop), rejectAll);
if (promise && typeof promise.then === 'function') {
promise.then(resolver(prop), cancelAll);
} else { } else {
resolveAll(prop, promises[prop]); resolveAll(prop, promise);
} }
} }
return deferred.promise; }, canceller
);
} }
......
...@@ -379,10 +379,10 @@ define("rsvp/events", ...@@ -379,10 +379,10 @@ define("rsvp/events",
__exports__.EventTarget = EventTarget; __exports__.EventTarget = EventTarget;
}); });
define("rsvp/hash", define("rsvp/hash",
["rsvp/defer","exports"], ["rsvp/promise","exports"],
function(__dependency1__, __exports__) { function(__dependency1__, __exports__) {
"use strict"; "use strict";
var defer = __dependency1__.defer; var Promise = __dependency1__.Promise;
function size(object) { function size(object) {
var s = 0; var s = 0;
...@@ -395,38 +395,61 @@ define("rsvp/hash", ...@@ -395,38 +395,61 @@ define("rsvp/hash",
} }
function hash(promises) { function hash(promises) {
var results = {}, deferred = defer(), remaining = size(promises);
function canceller() {
var promise,
key;
for (key in promises) {
if (promises.hasOwnProperty(key)) {
promise = promises[key];
if (promise && typeof promise.then === 'function' &&
typeof promise.cancel === 'function') {
promise.cancel();
}
}
}
}
return new Promise(function(resolve, reject) {
var results = {}, remaining = size(promises),
promise;
if (remaining === 0) { if (remaining === 0) {
deferred.resolve({}); resolve(results);
} }
var resolver = function(prop) { function resolver(key) {
return function(value) { return function(value) {
resolveAll(prop, value); resolveAll(key, value);
};
}; };
}
var resolveAll = function(prop, value) { function resolveAll(key, value) {
results[prop] = value; results[key] = value;
if (--remaining === 0) { if (--remaining === 0) {
deferred.resolve(results); resolve(results);
}
} }
};
var rejectAll = function(error) { function cancelAll(rejectionValue) {
deferred.reject(error); reject(rejectionValue);
}; canceller();
}
for (var prop in promises) { for (var prop in promises) {
if (promises[prop] && typeof promises[prop].then === 'function') { promise = promises[prop];
promises[prop].then(resolver(prop), rejectAll);
if (promise && typeof promise.then === 'function') {
promise.then(resolver(prop), cancelAll);
} else { } else {
resolveAll(prop, promises[prop]); resolveAll(prop, promise);
} }
} }
return deferred.promise; }, canceller
);
} }
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment