From ab68b839008d4a58f25fd9b42267e679f6c47274 Mon Sep 17 00:00:00 2001 From: adelphes Date: Wed, 1 Feb 2017 09:59:46 +0000 Subject: [PATCH] jq promise fixes return promise in always() allow when() to accept a single array of arguments --- src/jq-promise.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/jq-promise.js b/src/jq-promise.js index f5d982d..e1545f6 100644 --- a/src/jq-promise.js +++ b/src/jq-promise.js @@ -32,7 +32,7 @@ var Deferred = exports.Deferred = function(p, parent) { var thendef = this.then(fn); this.fail(function() { // we cannot bind thendef to the function because we need the caller's this to resolve the thendef - thendef.resolveWith(this, Array.prototype.map.call(arguments,x=>x)); + return thendef.resolveWith(this, Array.prototype.map.call(arguments,x=>x))._promise; }); return thendef; }, @@ -108,6 +108,9 @@ var Deferred = exports.Deferred = function(p, parent) { // $.when() is jQuery's version of Promise.all() // - this version just scans the array of arguments waiting on any Deferreds in turn before finally resolving the return Deferred var when = exports.when = function() { + if (arguments.length === 1 && Array.isArray(arguments[0])) { + return when.apply(this,...arguments).then(() => [...arguments]); + } var x = { def: $.Deferred(), args: Array.prototype.map.call(arguments,x=>x),