Arguments In Whenalldone Promise/deferred Javascript Helper Not Working When I Wrap Existing Code Into A Deferred
I'm trying to implement the following in TypeScript: https://stackoverflow.com/a/15094263/166231 UPDATE 2 - The problem with original answer is that it doesn't support a single def
Solution 1:
The problem was inside jquery's when
method.
jquery.when: function( subordinate /* , ..., subordinateN */ ) { ...
It has a line like:
// If resolveValues consist of only a single Deferred, just use that.
deferred = remaining === 1 ? subordinate : jQuery.Deferred(),
And this changes the shape of the arguments, so I had to put it back to the common shape my code expects (i.e. the same shape when multiple deferreds are passed to whenAllDone
)
const deferredArgs = jqueryWhenUsesSubordinate
? [[ arguments[ 0 ], arguments[ 1 ] ]]
: arguments
$.each(deferredArgs, function (i, resolvedArgs) {
var target = !resolvedArgs[0] ? failures : successes;
var data = resolvedArgs[1];
target.push(data.length === 1 ? data[0] : data);
});
Post a Comment for "Arguments In Whenalldone Promise/deferred Javascript Helper Not Working When I Wrap Existing Code Into A Deferred"