From f0cfe83e3725f9a3928da97a6e3085e79cb25309 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 18 Mar 2013 10:26:24 +0400 Subject: upgrade dojo to 1.8.3 (refs #570) --- .../store/util/QueryResults.js.uncompressed.js | 63 ++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 lib/dojo/store/util/QueryResults.js.uncompressed.js (limited to 'lib/dojo/store/util/QueryResults.js.uncompressed.js') diff --git a/lib/dojo/store/util/QueryResults.js.uncompressed.js b/lib/dojo/store/util/QueryResults.js.uncompressed.js new file mode 100644 index 000000000..58503179a --- /dev/null +++ b/lib/dojo/store/util/QueryResults.js.uncompressed.js @@ -0,0 +1,63 @@ +define("dojo/store/util/QueryResults", ["../../_base/array", "../../_base/lang", "../../_base/Deferred" +], function(array, lang, Deferred){ + +// module: +// dojo/store/util/QueryResults + +var QueryResults = function(results){ + // summary: + // A function that wraps the results of a store query with additional + // methods. + // description: + // QueryResults is a basic wrapper that allows for array-like iteration + // over any kind of returned data from a query. While the simplest store + // will return a plain array of data, other stores may return deferreds or + // promises; this wrapper makes sure that *all* results can be treated + // the same. + // + // Additional methods include `forEach`, `filter` and `map`. + // results: Array|dojo/promise/Promise + // The result set as an array, or a promise for an array. + // returns: + // An array-like object that can be used for iterating over. + // example: + // Query a store and iterate over the results. + // + // | store.query({ prime: true }).forEach(function(item){ + // | // do something + // | }); + + if(!results){ + return results; + } + // if it is a promise it may be frozen + if(results.then){ + results = lang.delegate(results); + } + function addIterativeMethod(method){ + if(!results[method]){ + results[method] = function(){ + var args = arguments; + return Deferred.when(results, function(results){ + Array.prototype.unshift.call(args, results); + return QueryResults(array[method].apply(array, args)); + }); + }; + } + } + addIterativeMethod("forEach"); + addIterativeMethod("filter"); + addIterativeMethod("map"); + if(!results.total){ + results.total = Deferred.when(results, function(results){ + return results.length; + }); + } + return results; // Object +}; + +lang.setObject("dojo.store.util.QueryResults", QueryResults); + +return QueryResults; + +}); -- cgit v1.2.3