diff options
author | Andrew Dolgov <[email protected]> | 2012-08-14 18:59:10 +0400 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2012-08-14 18:59:18 +0400 |
commit | 1354d17270961fff662d40f90521223f8fd0d73b (patch) | |
tree | e9266be71587e47c800303446e968a6d3565e2cf /lib/dojo/store/Memory.js | |
parent | d04f8c826f5283765f52cf6b98b42a1ed8f2d6bc (diff) |
update dojo to 1.7.3
Diffstat (limited to 'lib/dojo/store/Memory.js')
-rw-r--r-- | lib/dojo/store/Memory.js | 160 |
1 files changed, 2 insertions, 158 deletions
diff --git a/lib/dojo/store/Memory.js b/lib/dojo/store/Memory.js index b9001cdaf..9d1b17a98 100644 --- a/lib/dojo/store/Memory.js +++ b/lib/dojo/store/Memory.js @@ -4,161 +4,5 @@ see: http://dojotoolkit.org/license for details */ - -if(!dojo._hasResource["dojo.store.Memory"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. -dojo._hasResource["dojo.store.Memory"] = true; -dojo.provide("dojo.store.Memory"); -dojo.require("dojo.store.util.QueryResults"); -dojo.require("dojo.store.util.SimpleQueryEngine"); - - -dojo.declare("dojo.store.Memory", null, { - // summary: - // This is a basic in-memory object store. It implements dojo.store.api.Store. - constructor: function(/*dojo.store.Memory*/ options){ - // summary: - // Creates a memory object store. - // options: - // This provides any configuration information that will be mixed into the store. - // This should generally include the data property to provide the starting set of data. - this.index = {}; - dojo.mixin(this, options); - this.setData(this.data || []); - }, - // data: Array - // The array of all the objects in the memory store - data:null, - - // idProperty: String - // Indicates the property to use as the identity property. The values of this - // property should be unique. - idProperty: "id", - - // index: Object - // An index of data by id - index:null, - - // queryEngine: Function - // Defines the query engine to use for querying the data store - queryEngine: dojo.store.util.SimpleQueryEngine, - get: function(id){ - // summary: - // Retrieves an object by its identity - // id: Number - // The identity to use to lookup the object - // returns: Object - // The object in the store that matches the given id. - return this.index[id]; - }, - getIdentity: function(object){ - // summary: - // Returns an object's identity - // object: Object - // The object to get the identity from - // returns: Number - return object[this.idProperty]; - }, - put: function(object, options){ - // summary: - // Stores an object - // object: Object - // The object to store. - // options: dojo.store.api.Store.PutDirectives?? - // Additional metadata for storing the data. Includes an "id" - // property if a specific id is to be used. - // returns: Number - var id = options && options.id || object[this.idProperty] || Math.random(); - this.index[id] = object; - var data = this.data, - idProperty = this.idProperty; - for(var i = 0, l = data.length; i < l; i++){ - if(data[i][idProperty] == id){ - data[i] = object; - return id; - } - } - this.data.push(object); - return id; - }, - add: function(object, options){ - // summary: - // Creates an object, throws an error if the object already exists - // object: Object - // The object to store. - // options: dojo.store.api.Store.PutDirectives?? - // Additional metadata for storing the data. Includes an "id" - // property if a specific id is to be used. - // returns: Number - if(this.index[options && options.id || object[this.idProperty]]){ - throw new Error("Object already exists"); - } - return this.put(object, options); - }, - remove: function(id){ - // summary: - // Deletes an object by its identity - // id: Number - // The identity to use to delete the object - delete this.index[id]; - var data = this.data, - idProperty = this.idProperty; - for(var i = 0, l = data.length; i < l; i++){ - if(data[i][idProperty] == id){ - data.splice(i, 1); - return; - } - } - }, - query: function(query, options){ - // summary: - // Queries the store for objects. - // query: Object - // The query to use for retrieving objects from the store. - // options: dojo.store.api.Store.QueryOptions? - // The optional arguments to apply to the resultset. - // returns: dojo.store.api.Store.QueryResults - // The results of the query, extended with iterative methods. - // - // example: - // Given the following store: - // - // | var store = new dojo.store.Memory({ - // | data: [ - // | {id: 1, name: "one", prime: false }, - // | {id: 2, name: "two", even: true, prime: true}, - // | {id: 3, name: "three", prime: true}, - // | {id: 4, name: "four", even: true, prime: false}, - // | {id: 5, name: "five", prime: true} - // | ] - // | }); - // - // ...find all items where "prime" is true: - // - // | var results = store.query({ prime: true }); - // - // ...or find all items where "even" is true: - // - // | var results = store.query({ even: true }); - return dojo.store.util.QueryResults(this.queryEngine(query, options)(this.data)); - }, - setData: function(data){ - // summary: - // Sets the given data as the source for this store, and indexes it - // data: Object[] - // An array of objects to use as the source of data. - if(data.items){ - // just for convenience with the data format IFRS expects - this.idProperty = data.identifier; - data = this.data = data.items; - }else{ - this.data = data; - } - - for(var i = 0, l = data.length; i < l; i++){ - var object = data[i]; - this.index[object[this.idProperty]] = object; - } - } -}); - -} +//>>built +define("dojo/store/Memory",["../_base/declare","./util/QueryResults","./util/SimpleQueryEngine"],function(_1,_2,_3){return _1("dojo.store.Memory",null,{constructor:function(_4){for(var i in _4){this[i]=_4[i];}this.setData(this.data||[]);},data:null,idProperty:"id",index:null,queryEngine:_3,get:function(id){return this.data[this.index[id]];},getIdentity:function(_5){return _5[this.idProperty];},put:function(_6,_7){var _8=this.data,_9=this.index,_a=this.idProperty;var id=(_7&&"id" in _7)?_7.id:_a in _6?_6[_a]:Math.random();if(id in _9){if(_7&&_7.overwrite===false){throw new Error("Object already exists");}_8[_9[id]]=_6;}else{_9[id]=_8.push(_6)-1;}return id;},add:function(_b,_c){(_c=_c||{}).overwrite=false;return this.put(_b,_c);},remove:function(id){var _d=this.index;var _e=this.data;if(id in _d){_e.splice(_d[id],1);this.setData(_e);return true;}},query:function(_f,_10){return _2(this.queryEngine(_f,_10)(this.data));},setData:function(_11){if(_11.items){this.idProperty=_11.identifier;_11=this.data=_11.items;}else{this.data=_11;}this.index={};for(var i=0,l=_11.length;i<l;i++){this.index[_11[i][this.idProperty]]=i;}}});});
\ No newline at end of file |