]>
git.wh0rd.org - tt-rss.git/blob - lib/dojo/store/util/QueryResults.js.uncompressed.js
1 define("dojo/store/util/QueryResults", ["../../_base/array", "../../_base/lang", "../../_base/Deferred"
2 ], function(array
, lang
, Deferred
){
5 // dojo/store/util/QueryResults
7 var QueryResults = function(results
){
9 // A function that wraps the results of a store query with additional
12 // QueryResults is a basic wrapper that allows for array-like iteration
13 // over any kind of returned data from a query. While the simplest store
14 // will return a plain array of data, other stores may return deferreds or
15 // promises; this wrapper makes sure that *all* results can be treated
18 // Additional methods include `forEach`, `filter` and `map`.
19 // results: Array|dojo/promise/Promise
20 // The result set as an array, or a promise for an array.
22 // An array-like object that can be used for iterating over.
24 // Query a store and iterate over the results.
26 // | store.query({ prime: true }).forEach(function(item){
33 // if it is a promise it may be frozen
35 results
= lang
.delegate(results
);
37 function addIterativeMethod(method
){
39 results
[method
] = function(){
41 return Deferred
.when(results
, function(results
){
42 Array
.prototype.unshift
.call(args
, results
);
43 return QueryResults(array
[method
].apply(array
, args
));
48 addIterativeMethod("forEach");
49 addIterativeMethod("filter");
50 addIterativeMethod("map");
52 results
.total
= Deferred
.when(results
, function(results
){
53 return results
.length
;
56 return results
; // Object
59 lang
.setObject("dojo.store.util.QueryResults", QueryResults
);