//>>built
define("dstore/Memory","dojo/_base/declare dojo/_base/lang dojo/_base/array ./Store ./Promised ./SimpleQuery ./QueryResults".split(" "),function(n,t,u,p,q,r,m){return n([p,q,r],{constructor:function(){this.storage.version=0},postscript:function(){this.inherited(arguments);this.setData(this.data||[])},data:null,autoEmitEvents:!1,getSync:function(a){return this.storage.fullData[this.storage.index[a]]},putSync:function(a,b){b=b||{};var c=this.storage,h=c.index,k=c.fullData,g=this.Model;!g||a instanceof
g||(a=this._restore(a));var f=this.getIdentity(a);null==f&&(this._setIdentity(a,"id"in b?b.id:Math.random()),f=this.getIdentity(a));c.version++;var c=f in h?"update":"add",g={target:a},d;if("update"===c){if(!1===b.overwrite)throw Error("Object already exists");k.splice(d=h[f],1);f=d}else f=this.defaultNewToStart?0:k.length;var e;if("beforeId"in b){var l=b.beforeId;null===l?e=k.length:(e=h[l],d<e&&--e);void 0!==e?g.beforeId=l:e=f}else e=f;k.splice(e,0,a);d=isFinite(d)?Math.min(d,e):e;for(f=k.length;d<
f;++d)h[this.getIdentity(k[d])]=d;this.emit(c,g);return a},addSync:function(a,b){(b=b||{}).overwrite=!1;return this.putSync(a,b)},removeSync:function(a){var b=this.storage,c=b.index,b=b.fullData;if(a in c)return c=b.splice(c[a],1)[0],this._reindex(),this.emit("delete",{id:a,target:c}),!0},setData:function(a){this.parse&&(a=this.parse(a));a.items&&(this.idProperty=a.identifier||this.idProperty,a=a.items);this.storage.fullData=this.data=a;this._reindex()},_reindex:function(){for(var a=this.storage,
b=a.index={},c=a.fullData,h=this.Model,k=Object.prototype,g=0,f=c.length;g<f;g++){var d=c[g];if(h&&!(d instanceof h)){var e=this._restore(d,d.__proto__===k);d!==e&&(c[g]=d=e)}b[this.getIdentity(d)]=g}a.version++},fetchSync:function(){var a=this.data;if(!a||a._version!==this.storage.version){for(var a=this.storage.fullData,b=this.queryLog,c=0,h=b.length;c<h;c++)a=b[c].querier(a);a._version=this.storage.version;this.data=a}return new m(a)},fetchRangeSync:function(a){var b=this.fetchSync();return new m(b.slice(a.start,
a.end),{totalLength:b.length})},_includePropertyInSubCollection:function(a){return"data"!==a&&this.inherited(arguments)}})});
//# sourceMappingURL=Memory.js.map