]>
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
) {
4 // dojo/store/util/QueryResults
6 // The module defines a query results wrapper
8 var util
= lang
.getObject("dojo.store.util", true);
10 util
.QueryResults = function(results
){
12 // A function that wraps the results of a store query with additional
16 // QueryResults is a basic wrapper that allows for array-like iteration
17 // over any kind of returned data from a query. While the simplest store
18 // will return a plain array of data, other stores may return deferreds or
19 // promises; this wrapper makes sure that *all* results can be treated
22 // Additional methods include `forEach`, `filter` and `map`.
25 // An array-like object that can be used for iterating over.
28 // Query a store and iterate over the results.
30 // | store.query({ prime: true }).forEach(function(item){
37 // if it is a promise it may be frozen
39 results
= lang
.delegate(results
);
41 function addIterativeMethod(method
){
43 results
[method
] = function(){
45 return Deferred
.when(results
, function(results
){
46 Array
.prototype.unshift
.call(args
, results
);
47 return util
.QueryResults(array
[method
].apply(array
, args
));
52 addIterativeMethod("forEach");
53 addIterativeMethod("filter");
54 addIterativeMethod("map");
56 results
.total
= Deferred
.when(results
, function(results
){
57 return results
.length
;
63 return util
.QueryResults
;