/**
 * Provides a slightly-decorated FBPromise
 */
if (typeof define !== 'function') { var define = require('amdefine')(module); }
define(['../node_modules/fbpromise/FireBreathPromise'], function(fbpromise) {
    var Deferred = fbpromise.FireBreathPromise;

    Deferred.when = function(val) {
        var dfd = Deferred();
        dfd.resolve(val);
        return dfd.promise;
    };

    Deferred.reject = function(error) {
        var dfd = Deferred();
        dfd.reject(error);
        return dfd.promise;
    };

    /**
     * Turns an array of promises into a promise for an array.  If any of
     * the promises gets rejected, the whole array is rejected immediately.
     * @param promises {Array} an array (or promise for an array)
     *   of values (or promises for values)
     * @returns {promise} a promise for an array of the corresponding values
     */
    // By Mark Miller
    // http://wiki.ecmascript.org/doku.php?id=strawman:concurrency&rev=1308776521#allfulfilled
    Deferred.all = function(promises) {
        return Deferred.when(promises).then(function(promises) {
            var resolvedPromises = [];
            var pendingCount = 0;
            var dfd = Deferred();
            promises.forEach(function(toResolve, idx) {
                pendingCount++;
                Deferred.when(toResolve).then(function(val) {
                    pendingCount--;
                    resolvedPromises[idx] = val;
                    resolveIfDone();
                }, function(error) {
                    dfd.reject(error);
                });
            });
            function resolveIfDone() {
                if (pendingCount === 0) {
                    dfd.resolve(resolvedPromises);
                }
            }
            resolveIfDone();
            return dfd.promise;
        });
    };


    // Converts a function that takes a callback as the last argument to a function that returns a
    // deferred object that is resolved to the callback value.
    Deferred.fn = function(obj, method) {
        return function() {
            var args = Array.prototype.slice.call(arguments, 0);
            var dfd = Deferred();
            var callback = function(status, resp) {
                if (status === 'success') { dfd.resolve(resp); }
                else { dfd.reject(resp); }
            };
            args.push(callback);
            obj[method].apply(obj, args);
            return dfd.promise;
        };
    };

    return Deferred;
});

@@ -1,12 +1,34 @@
+/* global toString */%0A
 /**%0A * Provi
@@ -559,24 +559,36 @@
 rns an array
+ (or object)
  of promises
@@ -619,10 +619,26 @@
 rray
-.
  
+or object.%0A     *
  If 
@@ -643,23 +643,16 @@
 f any of
-%0A     *
  the pro
@@ -682,21 +682,21 @@
 e whole 
-array
+thing
  is reje
@@ -742,16 +742,23 @@
 s %7BArray
+%7CObject
 %7D an arr
@@ -755,24 +755,31 @@
 ct%7D an array
+%7Cobject
  (or promise
@@ -791,16 +791,23 @@
 an array
+%7Cobject
 )%0A     *
@@ -1171,29 +1171,150 @@
 var 
-resolvedP
+isArray = Array.isArray ? Array.isArray(promises) : toString.call(p
 romises
+)
  =
- %5B%5D
+== '%5Bobject Array%5D';%0A            var resolved = isArray ? %5B%5D : %7B%7D
 ;%0A  
@@ -1395,52 +1395,186 @@
     
-promises.forEach(function(toResolve, idx) %7B%0A
+for (var prop in promises) %7B%0A                if (promises.hasOwnProperty(prop)) %7B%0A                    resolved%5Bprop%5D = (void 0); // just to try preserving order of insertion%0A    
     
@@ -1613,24 +1613,28 @@
             
+    
 Deferred.whe
@@ -1639,24 +1639,144 @@
 hen(
-toResolve).then(
+promises%5Bprop%5D).then(thenFn(prop), failFn);%0A                %7D%0A            %7D%0A%0A            function thenFn(prop) %7B%0A                return 
 func
@@ -1855,20 +1855,13 @@
 lved
-Promises%5Bidx
+%5Bprop
 %5D = 
@@ -1923,33 +1923,24 @@
    %7D
-, function(error) %7B%0A
+;%0A       
      
+%7D%0A
     
@@ -1951,65 +1951,53 @@
     
-   dfd.reject(error);%0A                %7D);%0A            %7D);
+function failFn(error) %7B dfd.reject(error); %7D
 %0A   
@@ -2118,16 +2118,8 @@
 lved
-Promises
 );%0A 

Update Deferred.all to work with objects or arrays