Skip to content
Browse files

Consistently work properly with model: null

  • Loading branch information...
1 parent 1eef304 commit 8bd63d50ad41700b684cebd3abb4d1332e214be2 @kriszyp kriszyp committed Feb 18, 2014
Showing with 13 additions and 9 deletions.
  1. +6 −4 Memory.js
  2. +6 −4 Store.js
  3. +1 −1 docs/Store.md
View
10 Memory.js
@@ -48,8 +48,9 @@ define(['dojo/_base/declare', 'dojo/_base/lang', 'dojo/_base/array', './SimpleQu
var id = object[idProperty] = (options && 'id' in options) ?
options.id :
idProperty in object ? object[idProperty] : Math.random();
- var prototype = this.model.prototype;
- if (prototype && !(object instanceof this.model)) {
+ var model = this.model;
+ if (model && !(object instanceof model)) {
+ var prototype = model.prototype;
if (hasProto) {
// the fast easy way
object.__proto__ = prototype;
@@ -127,10 +128,11 @@ define(['dojo/_base/declare', 'dojo/_base/lang', 'dojo/_base/array', './SimpleQu
_reindex: function (data) {
this.fullData = data;
this.index = {};
- var prototype = this.model.prototype;
+ var model = this.model;
+ var prototype = model && model.prototype;
for (var i = 0, l = data.length; i < l; i++) {
var object = data[i];
- if (prototype) {
+ if (model && !(object instanceof model)) {
if (hasProto) {
// the fast easy way
object.__proto__ = prototype;
View
10 Store.js
@@ -19,13 +19,15 @@ define([
constructor: function (options) {
// perform the mixin
declare.safeMixin(this, options);
- if (!this.hasOwnProperty('model')) {
+ if (!this.hasOwnProperty('model') && this.model) {
// we need a distinct model for each store, so we can
// save the reference back to this store on it
this.model = declare(Model, {});
}
- // give a reference back to the store for saving, etc.
- this.model.prototype._store = this;
+ if(this.model){
+ // give a reference back to the store for saving, etc.
+ this.model.prototype._store = this;
+ }
},
// idProperty: String
@@ -82,7 +84,7 @@ define([
// model: Function
// This should be a entity (like a class/constructor) with a 'prototype' property that will be
// used as the prototype for all objects returned from this store. One can set this
- // to an empty object if you don't want any methods to decorate the returned
+ // to null if you don't want any methods to decorate the returned
// objects (this can improve performance by avoiding prototype setting)
model: Model,
View
2 docs/Store.md
@@ -9,7 +9,7 @@ In addition to the methods and properties inherited from [Collections](./Collect
Property | Description
-------- | -----------
`idProperty` | If the store has a single primary key, this indicates the property to use as the identity property. The values of this property should be unique. This defaults to "id".
-`model` | This is the model class to use for all the data objects that originate from this store. By default this will be set to the class from `dstore/Model`. However, you can create your own model classes (and schemas), and assign them to a store. All object that come from the store will have their prototype set such that they will be instances of the model.
+`model` | This is the model class to use for all the data objects that originate from this store. By default this will be set to the class from `dstore/Model`. However, you can create your own model classes (and schemas), and assign them to a store. All object that come from the store will have their prototype set such that they will be instances of the model. This can be set to `null` to disable any prototype modifications and leave data as plain objects.
### Method Summary

0 comments on commit 8bd63d5

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