[Pkg-javascript-commits] [dojo] 05/13: Always return QueryResults from map and filter (1.9 backport)
David Prévot
taffit at moszumanska.debian.org
Thu Aug 21 17:39:56 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to annotated tag 1.9.3
in repository dojo.
commit 19146b55a4d13a791245e9c70e2567dc5473bd4b
Author: Bryan Forbes <bryan at reigndropsfall.net>
Date: Sat Jan 18 17:39:12 2014 -0600
Always return QueryResults from map and filter (1.9 backport)
Fixes #17681
(cherry picked from commit bdd52aceb1319e919aa8a5157156c36170bcc098)
---
store/util/QueryResults.js | 30 +++++++++++++++++++-----------
1 file changed, 19 insertions(+), 11 deletions(-)
diff --git a/store/util/QueryResults.js b/store/util/QueryResults.js
index 7b390a6..c57f666 100644
--- a/store/util/QueryResults.js
+++ b/store/util/QueryResults.js
@@ -30,25 +30,33 @@ var QueryResults = function(results){
if(!results){
return results;
}
+
+ var isPromise = !!results.then;
// if it is a promise it may be frozen
- if(results.then){
+ if(isPromise){
results = lang.delegate(results);
}
function addIterativeMethod(method){
- if(!results[method]){
- results[method] = function(){
- var args = arguments;
- return when(results, function(results){
- Array.prototype.unshift.call(args, results);
- return QueryResults(array[method].apply(array, args));
- });
- };
- }
+ // Always add the iterative methods so a QueryResults is
+ // returned whether the environment is ES3 or ES5
+ results[method] = function(){
+ var args = arguments;
+ var result = when(results, function(results){
+ Array.prototype.unshift.call(args, results);
+ return QueryResults(array[method].apply(array, args));
+ });
+ // forEach should only return the result of when()
+ // when we're wrapping a promise
+ if(method !== "forEach" || isPromise){
+ return result;
+ }
+ };
}
+
addIterativeMethod("forEach");
addIterativeMethod("filter");
addIterativeMethod("map");
- if(!results.total){
+ if(results.total == null){
results.total = when(results, function(results){
return results.length;
});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/dojo.git
More information about the Pkg-javascript-commits
mailing list