summaryrefslogtreecommitdiff
path: root/lib/dojo/store/util
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2013-04-02 20:06:16 +0400
committerAndrew Dolgov <[email protected]>2013-04-02 20:06:16 +0400
commit870334be3f58507c05bfc72f3edbe5db10af4caf (patch)
tree441e1c41780eb75d422025cabea17724e2cc4a79 /lib/dojo/store/util
parent7caa48fe6a3a37bd08f846f90e407ef31171f12c (diff)
remove dojo uncompressed files
Diffstat (limited to 'lib/dojo/store/util')
-rw-r--r--lib/dojo/store/util/QueryResults.js.uncompressed.js63
-rw-r--r--lib/dojo/store/util/SimpleQueryEngine.js.uncompressed.js110
2 files changed, 0 insertions, 173 deletions
diff --git a/lib/dojo/store/util/QueryResults.js.uncompressed.js b/lib/dojo/store/util/QueryResults.js.uncompressed.js
deleted file mode 100644
index 58503179a..000000000
--- a/lib/dojo/store/util/QueryResults.js.uncompressed.js
+++ /dev/null
@@ -1,63 +0,0 @@
-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;
-
-});
diff --git a/lib/dojo/store/util/SimpleQueryEngine.js.uncompressed.js b/lib/dojo/store/util/SimpleQueryEngine.js.uncompressed.js
deleted file mode 100644
index faf712781..000000000
--- a/lib/dojo/store/util/SimpleQueryEngine.js.uncompressed.js
+++ /dev/null
@@ -1,110 +0,0 @@
-define("dojo/store/util/SimpleQueryEngine", ["../../_base/array" /*=====, "../api/Store" =====*/], function(arrayUtil /*=====, Store =====*/){
-
-// module:
-// dojo/store/util/SimpleQueryEngine
-
-return function(query, options){
- // summary:
- // Simple query engine that matches using filter functions, named filter
- // functions or objects by name-value on a query object hash
- //
- // description:
- // The SimpleQueryEngine provides a way of getting a QueryResults through
- // the use of a simple object hash as a filter. The hash will be used to
- // match properties on data objects with the corresponding value given. In
- // other words, only exact matches will be returned.
- //
- // This function can be used as a template for more complex query engines;
- // for example, an engine can be created that accepts an object hash that
- // contains filtering functions, or a string that gets evaluated, etc.
- //
- // When creating a new dojo.store, simply set the store's queryEngine
- // field as a reference to this function.
- //
- // query: Object
- // An object hash with fields that may match fields of items in the store.
- // Values in the hash will be compared by normal == operator, but regular expressions
- // or any object that provides a test() method are also supported and can be
- // used to match strings by more complex expressions
- // (and then the regex's or object's test() method will be used to match values).
- //
- // options: dojo/store/api/Store.QueryOptions?
- // An object that contains optional information such as sort, start, and count.
- //
- // returns: Function
- // A function that caches the passed query under the field "matches". See any
- // of the "query" methods on dojo.stores.
- //
- // example:
- // Define a store with a reference to this engine, and set up a query method.
- //
- // | var myStore = function(options){
- // | // ...more properties here
- // | this.queryEngine = SimpleQueryEngine;
- // | // define our query method
- // | this.query = function(query, options){
- // | return QueryResults(this.queryEngine(query, options)(this.data));
- // | };
- // | };
-
- // create our matching query function
- switch(typeof query){
- default:
- throw new Error("Can not query with a " + typeof query);
- case "object": case "undefined":
- var queryObject = query;
- query = function(object){
- for(var key in queryObject){
- var required = queryObject[key];
- if(required && required.test){
- // an object can provide a test method, which makes it work with regex
- if(!required.test(object[key], object)){
- return false;
- }
- }else if(required != object[key]){
- return false;
- }
- }
- return true;
- };
- break;
- case "string":
- // named query
- if(!this[query]){
- throw new Error("No filter function " + query + " was found in store");
- }
- query = this[query];
- // fall through
- case "function":
- // fall through
- }
- function execute(array){
- // execute the whole query, first we filter
- var results = arrayUtil.filter(array, query);
- // next we sort
- var sortSet = options && options.sort;
- if(sortSet){
- results.sort(typeof sortSet == "function" ? sortSet : function(a, b){
- for(var sort, i=0; sort = sortSet[i]; i++){
- var aValue = a[sort.attribute];
- var bValue = b[sort.attribute];
- if (aValue != bValue){
- return !!sort.descending == (aValue == null || aValue > bValue) ? -1 : 1;
- }
- }
- return 0;
- });
- }
- // now we paginate
- if(options && (options.start || options.count)){
- var total = results.length;
- results = results.slice(options.start || 0, (options.start || 0) + (options.count || Infinity));
- results.total = total;
- }
- return results;
- }
- execute.matches = query;
- return execute;
-};
-
-});