summaryrefslogtreecommitdiff
path: root/lib/dojo/data/util/simpleFetch.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/dojo/data/util/simpleFetch.js')
-rw-r--r--lib/dojo/data/util/simpleFetch.js139
1 files changed, 86 insertions, 53 deletions
diff --git a/lib/dojo/data/util/simpleFetch.js b/lib/dojo/data/util/simpleFetch.js
index b3cc365d1..0bfb19ec3 100644
--- a/lib/dojo/data/util/simpleFetch.js
+++ b/lib/dojo/data/util/simpleFetch.js
@@ -5,60 +5,93 @@
*/
-if(!dojo._hasResource["dojo.data.util.simpleFetch"]){
-dojo._hasResource["dojo.data.util.simpleFetch"]=true;
+if(!dojo._hasResource["dojo.data.util.simpleFetch"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
+dojo._hasResource["dojo.data.util.simpleFetch"] = true;
dojo.provide("dojo.data.util.simpleFetch");
dojo.require("dojo.data.util.sorter");
-dojo.data.util.simpleFetch.fetch=function(_1){
-_1=_1||{};
-if(!_1.store){
-_1.store=this;
-}
-var _2=this;
-var _3=function(_4,_5){
-if(_5.onError){
-var _6=_5.scope||dojo.global;
-_5.onError.call(_6,_4,_5);
-}
-};
-var _7=function(_8,_9){
-var _a=_9.abort||null;
-var _b=false;
-var _c=_9.start?_9.start:0;
-var _d=(_9.count&&(_9.count!==Infinity))?(_c+_9.count):_8.length;
-_9.abort=function(){
-_b=true;
-if(_a){
-_a.call(_9);
-}
-};
-var _e=_9.scope||dojo.global;
-if(!_9.store){
-_9.store=_2;
-}
-if(_9.onBegin){
-_9.onBegin.call(_e,_8.length,_9);
-}
-if(_9.sort){
-_8.sort(dojo.data.util.sorter.createSortFunction(_9.sort,_2));
-}
-if(_9.onItem){
-for(var i=_c;(i<_8.length)&&(i<_d);++i){
-var _f=_8[i];
-if(!_b){
-_9.onItem.call(_e,_f,_9);
-}
-}
-}
-if(_9.onComplete&&!_b){
-var _10=null;
-if(!_9.onItem){
-_10=_8.slice(_c,_d);
-}
-_9.onComplete.call(_e,_10,_9);
-}
-};
-this._fetchItems(_1,_7,_3);
-return _1;
+
+dojo.data.util.simpleFetch.fetch = function(/* Object? */ request){
+ // summary:
+ // The simpleFetch mixin is designed to serve as a set of function(s) that can
+ // be mixed into other datastore implementations to accelerate their development.
+ // The simpleFetch mixin should work well for any datastore that can respond to a _fetchItems()
+ // call by returning an array of all the found items that matched the query. The simpleFetch mixin
+ // is not designed to work for datastores that respond to a fetch() call by incrementally
+ // loading items, or sequentially loading partial batches of the result
+ // set. For datastores that mixin simpleFetch, simpleFetch
+ // implements a fetch method that automatically handles eight of the fetch()
+ // arguments -- onBegin, onItem, onComplete, onError, start, count, sort and scope
+ // The class mixing in simpleFetch should not implement fetch(),
+ // but should instead implement a _fetchItems() method. The _fetchItems()
+ // method takes three arguments, the keywordArgs object that was passed
+ // to fetch(), a callback function to be called when the result array is
+ // available, and an error callback to be called if something goes wrong.
+ // The _fetchItems() method should ignore any keywordArgs parameters for
+ // start, count, onBegin, onItem, onComplete, onError, sort, and scope.
+ // The _fetchItems() method needs to correctly handle any other keywordArgs
+ // parameters, including the query parameter and any optional parameters
+ // (such as includeChildren). The _fetchItems() method should create an array of
+ // result items and pass it to the fetchHandler along with the original request object
+ // -- or, the _fetchItems() method may, if it wants to, create an new request object
+ // with other specifics about the request that are specific to the datastore and pass
+ // that as the request object to the handler.
+ //
+ // For more information on this specific function, see dojo.data.api.Read.fetch()
+ request = request || {};
+ if(!request.store){
+ request.store = this;
+ }
+ var self = this;
+
+ var _errorHandler = function(errorData, requestObject){
+ if(requestObject.onError){
+ var scope = requestObject.scope || dojo.global;
+ requestObject.onError.call(scope, errorData, requestObject);
+ }
+ };
+
+ var _fetchHandler = function(items, requestObject){
+ var oldAbortFunction = requestObject.abort || null;
+ var aborted = false;
+
+ var startIndex = requestObject.start?requestObject.start:0;
+ var endIndex = (requestObject.count && (requestObject.count !== Infinity))?(startIndex + requestObject.count):items.length;
+
+ requestObject.abort = function(){
+ aborted = true;
+ if(oldAbortFunction){
+ oldAbortFunction.call(requestObject);
+ }
+ };
+
+ var scope = requestObject.scope || dojo.global;
+ if(!requestObject.store){
+ requestObject.store = self;
+ }
+ if(requestObject.onBegin){
+ requestObject.onBegin.call(scope, items.length, requestObject);
+ }
+ if(requestObject.sort){
+ items.sort(dojo.data.util.sorter.createSortFunction(requestObject.sort, self));
+ }
+ if(requestObject.onItem){
+ for(var i = startIndex; (i < items.length) && (i < endIndex); ++i){
+ var item = items[i];
+ if(!aborted){
+ requestObject.onItem.call(scope, item, requestObject);
+ }
+ }
+ }
+ if(requestObject.onComplete && !aborted){
+ var subset = null;
+ if(!requestObject.onItem){
+ subset = items.slice(startIndex, endIndex);
+ }
+ requestObject.onComplete.call(scope, subset, requestObject);
+ }
+ };
+ this._fetchItems(request, _fetchHandler, _errorHandler);
+ return request; // Object
};
+
}