Skip to content
Browse files

Move idProperty and getIdentity to Store

  • Loading branch information...
1 parent f4a5da1 commit e46cd6b8ad796cc2d894ec6b3bdce5799d18d4f1 @kriszyp kriszyp committed Feb 11, 2014
Showing with 25 additions and 29 deletions.
  1. +0 −13 Memory.js
  2. +0 −14 Request.js
  3. +15 −0 Store.js
  4. +10 −2 legacy/StoreAdapter.js
View
13 Memory.js
@@ -19,11 +19,6 @@ define(['dojo/_base/declare', 'dojo/_base/lang', 'dojo/_base/array', './SimpleQu
// 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 indices into the data array by id
index: null,
@@ -37,14 +32,6 @@ define(['dojo/_base/declare', 'dojo/_base/lang', 'dojo/_base/array', './SimpleQu
// The object in the store that matches the given id.
return this.fullData[(this.store || 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
View
14 Request.js
@@ -51,11 +51,6 @@ define([
// sent to the server
target: '',
- // idProperty: String
- // Indicates the property to use as the identity property. The values of this
- // property should be unique.
- idProperty: 'id',
-
// sortParam: String
// The query parameter to used for holding sort information. If this is omitted, than
// the sort information is included in a functional query token to avoid colliding
@@ -73,15 +68,6 @@ define([
// Defines the Accept header to use on HTTP requests
accepts: 'application/json',
- getIdentity: function (object) {
- // summary:
- // Returns an object's identity
- // object: Object
- // The object to get the identity from
- // returns: Number
- return object[this.idProperty];
- },
-
fetch: function () {
if (!this.hasOwnProperty('data')) {
// perform the actual query
View
15 Store.js
@@ -27,6 +27,21 @@ define([
// give a reference back to the store for saving, etc.
this.model.prototype._store = this;
},
+
+ // idProperty: String
+ // Indicates the property to use as the identity property. The values of this
+ // property should be unique.
+ idProperty: '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];
+ },
+
map: function (callback, thisObject) {
var results = [];
// like forEach, except we collect results
View
12 legacy/StoreAdapter.js
@@ -104,11 +104,19 @@ define([
// A dstore object that will have an adapter applied to it.
// config: Object?
// An optional configuration object that will be mixed into the adapted object.
- //
- obj = declare.safeMixin(obj, new StoreAdapter());
+ var adapter = new StoreAdapter();
+ // we need to keep any the original store's own properties
+ for (var i in obj) {
+ if (obj.hasOwnProperty(i)) {
+ adapter[i] = obj[i];
+ }
+ }
+ // we now mixin adapter properties
+ obj = declare.safeMixin(obj, adapter);
if (config) {
obj = lang.mixin(obj, config);
}
+
return obj;
};

0 comments on commit e46cd6b

Please sign in to comment.
Something went wrong with that request. Please try again.