//>>built
define("dstore/legacy/DstoreAdapter",["dojo/_base/declare","dojo/_base/array","dojo/store/util/QueryResults"],function(p,l,q){function g(d){return d}var n={store:null,constructor:function(d){this.store=d;if(d._getQuerierFactory("filter")||d._getQuerierFactory("sort"))this.queryEngine=function(b,a){a=a||{};var c=d._getQuerierFactory("filter"),e=c?c(b):g,c=d._getQuerierFactory("sort"),f=g;c&&(f=c(l.map(a.sort,function(a){return{property:a.attribute,descending:a.descending}})));var m=g;isNaN(a.start)&&
isNaN(a.count)||(m=function(b){var c=a.start||0,c=b.slice(c,c+(a.count||Infinity));c.total=b.length;return c});return function(a){return m(f(e(a)))}};var c=this;d.on("add,update,delete",function(b){var a=b.type,h=b.target;c.notify("add"===a||"update"===a?h:void 0,"delete"===a||"update"===a?"id"in b?b.id:d.getIdentity(h):void 0)})},query:function(d,c){c=c||{};var b=this.store.filter(d),a,h,e;if(e=c.sort)if("[object Array]"===Object.prototype.toString.call(e))for(var f;f=e.pop();)b=b.sort(f.attribute,
f.descending);else b=b.sort(e);b.track&&!b.tracking&&(b=b.track(),h=!0);"start"in c&&(a=c.start||0,a=b[b.fetchRangeSync?"fetchRangeSync":"fetchRange"]({start:a,end:c.count?a+c.count:Infinity}));a=a||b[b.fetchSync?"fetchSync":"fetch"]();e=a.totalLength;a=new q(a);a.total=e;a.observe=function(a,c){function d(a){return void 0===a&&h?-1:a}var e=b.on("add",function(c){a(c.target,-1,d(c.index))}),f=b.on("update",function(b){!c&&b.previousIndex===b.index&&isFinite(b.index)||a(b.target,d(b.previousIndex),
d(b.index))}),g=b.on("delete",function(b){a(b.target,d(b.previousIndex),-1)}),k={remove:function(){e.remove();f.remove();g.remove()}};k.cancel=k.remove;return k};return a},notify:function(){}};l.forEach(["get","put","add","remove","getIdentity"],function(d){n[d]=function(){var c=this.store;return(c[d+"Sync"]||c[d]).apply(c,arguments)}});return p(null,n)});
//# sourceMappingURL=DstoreAdapter.js.map