control-freak-ide/Code/client/build/dgrid/dstore/tests/Trackable.js
plastic-hub-dev-node-saturn 538369cff7 latest
2021-05-12 18:35:18 +02:00

20 lines
8.9 KiB
JavaScript

//>>built
define("dstore/tests/Trackable","intern!object intern/chai!assert dojo/_base/array dojo/_base/declare dojo/_base/lang dstore/Memory dstore/Store dstore/Trackable dstore/SimpleQuery".split(" "),function(m,d,q,r,t,l,w,u,x){function n(d){var f=[],k;for(k=0;k<d;k++)f.push({id:k,name:"item "+k,order:k});return f}function v(y,f){function k(){return f({data:[{id:0,name:"zero",even:!0,prime:!1},{id:1,name:"one",prime:!1},{id:2,name:"two",even:!0,prime:!0},{id:3,name:"three",prime:!0},{id:4,name:"four",even:!0,
prime:!1},{id:5,name:"five",prime:!0}]},l)}function p(a){return f({data:n(a),track:function(){this.backingMemoryStore=this.backingMemoryStore.track();return this.inherited(arguments)}},m)}var m=r([w,x],function(){var a={constructor:function(){this.backingMemoryStore=f({data:this.data},l);delete this.data}};q.forEach("getIdentity get add put remove getSync addSync putSync removeSync fetch fetchRange fetchSync fetchRangeSync".split(" "),function(c){a[c]=function(){var a=this.backingMemoryStore;return a[c].apply(a,
arguments)}});q.forEach(["filter","sort"],function(c){a[c]=function(){var a=this.backingMemoryStore[c].apply(this.backingMemoryStore,arguments);return t.mixin(this.inherited(arguments),{backingMemoryStore:a})}});return a}()),h=k();return{name:y,get:function(){d.strictEqual(h.getSync(1).name,"one");d.strictEqual(h.getSync(4).name,"four");d.isTrue(h.getSync(5).prime)},filter:function(){var a=[],c=[],e=h.filter({prime:!0}).track();e.fetch();d.strictEqual(e._results.length,3);e.on("add, update, delete",
function(b){a.push(b)});var b=e.on("update",function(a){c.push(a)}),g=e.on("delete",function(a){c.push(a)}),z=e.on("add",function(a){c.push(a)}),f=[],k=[],l=e._results[0];l.prime=!1;h.put(l);d.strictEqual(e._results.length,2);f.push({type:"update",target:l,index:void 0,previousIndex:0,totalLength:2});k.push(f[f.length-1]);b.remove();g.remove();z.remove();b=h.getSync(1);b.prime=!0;h.put(b);f.push({type:"update",target:b,index:2,previousIndex:void 0,totalLength:3});d.strictEqual(e._results.length,3);
b={id:6,name:"six"};h.add(b);d.strictEqual(e._results.length,3);f.push({type:"add",target:h._restore(b),index:void 0,totalLength:3});b={id:7,name:"seven",prime:!0};h.add(b);d.strictEqual(e._results.length,4);f.push({type:"add",target:h._restore(b),index:3,totalLength:4});b=h.getSync(3);h.remove(3);f.push({type:"delete",id:3,target:h._restore(b),previousIndex:0,totalLength:3});d.strictEqual(e._results.length,3);d.deepEqual(c,k);d.deepEqual(a,f)},"filter with zero id":function(){var a=h.filter({}),
c;a.fetch().then(function(a){c=a});d.strictEqual(c.length,7);a.track().on("update",function(a){d.ok(a.index===a.previousIndex)});h.put({id:5,name:"-FIVE-",prime:!0});h.put({id:0,name:"-ZERO-",prime:!1})},"paging with store.data":function(){var a,c=f({data:n(100)},l),e=[];a=c.filter({}).sort("order").track();a.on("update",function(a){e.push(a)});a.on("add",function(a){e.push(a)});a.on("delete",function(a){e.push(a)});a.fetchRange({start:0,end:25});a.fetchRange({start:25,end:50});a.fetchRange({start:50,
end:75});a.fetchRange({start:75,end:100});a=a.fetchSync();c.add({id:101,name:"one oh one",order:2.5});d.strictEqual(a.length,101);d.strictEqual(e.length,1);c.remove(101);d.strictEqual(e.length,2);d.strictEqual(a.length,100);c.add({id:102,name:"one oh two",order:26.5});d.strictEqual(a.length,101);d.strictEqual(e.length,3)},"paging with store._partialResults":function(){var a=p(100),c,e=a.filter({}).sort("order").track(),b,g=function(a){a=t.delegate(a);a.type in{add:1,update:1}&&!("index"in a)&&(a.index=
void 0);a.type in{update:1,"delete":1}&&!("previousIndex"in a)&&(a.previousIndex=void 0);d.deepEqual(c,a)};e.on("update",function(a){c=a});e.on("add",function(a){c=a});e.on("delete",function(a){c=a});b=a.getSync(0);b.order=1.25;a.put(b);g({type:"update",target:b});b=a._restore({id:1.5,name:"item 1.5",order:1.5});a.add(b);g({type:"add",target:b});a.remove(b.id);g({type:"delete",id:b.id});e.fetchRange({start:0,end:25});b=a.getSync(0);b.order=0;a.put(b);g({type:"update",target:b,index:0,previousIndex:1,
totalLength:100});b=a._restore({id:-1,name:"item -1",order:-1});a.add(b);g({type:"add",target:b,index:0,totalLength:101});a.remove(b.id);g({type:"delete",id:b.id,previousIndex:0,totalLength:100});b=a.getSync(24);b.name="item 24 updated";a.put(b);g({type:"update",target:b,previousIndex:24,totalLength:99});b=a._restore({id:24.1,name:"item 24.1",order:24.1});a.add(b);g({type:"add",target:b,totalLength:99});a.remove(b.id);g({type:"delete",id:b.id,totalLength:99});e.fetchRange({start:24,end:50});b=a.getSync(22);
b.order=23.1;a.put(b);g({type:"update",target:b,index:23,previousIndex:22,totalLength:100});b=a._restore({id:23.2,name:"item 23.2",order:23.2});a.add(b);g({type:"add",target:b,index:24,totalLength:101});a.remove(b.id);g({type:"delete",id:b.id,previousIndex:24,totalLength:100});b=a.getSync(25);b.order=23.9;a.put(b);g({type:"update",target:b,index:24,previousIndex:25,totalLength:100});b=a._restore({id:23.8,name:"item 23.8",order:23.8});a.add(b);g({type:"add",target:b,index:24,totalLength:101});a.remove(b.id);
g({type:"delete",id:b.id,previousIndex:24,totalLength:100});e.fetchRange({start:75,end:100});b=a.getSync(98);b.order=99.1;a.put(b);g({type:"update",target:b,index:99,previousIndex:98,totalLength:100});b=a._restore({id:99.2,name:"item 99.2",order:99.2});a.add(b);g({type:"add",target:b,index:100,totalLength:101});b=a.getSync(76);b.order=74.9;a.put(b);g({type:"update",target:b,previousIndex:76,totalLength:100});b=a._restore({id:74.8,name:"item 74.8",order:74.8});a.add(b);g({type:"add",target:b,totalLength:100})},
"paging releaseRange with store._partialResults":function(){var a=p(100).track(),c=function(b,c){for(;b<c;++b)d.notEqual(a._partialResults[b],void 0)},e=function(b,c){for(;b<c;++b)d.equal(a._partialResults[b],void 0)};a.fetchRange({start:5,end:15});c(5,15);a.releaseRange(0,20);e(5,15);a.fetchRange({start:25,end:45});c(25,45);a.releaseRange(30,40);c(25,30);e(30,40);c(40,45);a.fetchRange({start:55,end:65});c(55,65);a.releaseRange(50,60);e(50,60);c(60,65);a.fetchRange({start:80,end:95});c(80,95);a.releaseRange(90,
100);c(80,90);e(90,100)},"new item with default index":function(){var a=p(100),c=a.track();return c.fetchRange({start:0,end:25}).then(function(){var e=null;c.on("add",function(a){e=a});var b=a._restore({id:200,name:"item-200",order:Infinity});a.add(b);d.isNotNull(e);d.deepEqual(e.target,b);d.isTrue("index"in e);d.isUndefined(e.index);a.defaultNewToStart=!0;e=null;b=a._restore({id:201,name:"item-201",order:Infinity});a.add(b);d.isDefined(e);d.deepEqual(e.target,b);d.propertyVal(e,"index",0);a.defaultNewToStart=
!1;return c.fetchRange({start:25,end:102}).then(function(){b=a._restore({id:202,name:"item-202",order:Infinity});a.add(b);d.isDefined(e);d.deepEqual(e.target,b);d.propertyVal(e,"index",102)})})},"new item in empty store - with queryExecutor":function(){var a=f({data:[]},l).filter({type:"test-item"}).track();a.fetch();var c;a.on("add",function(a){c=a});a=a.addSync({type:"test-item",id:1,name:"one"});d.deepEqual(c,{type:"add",index:0,target:a,totalLength:1})},"new item in empty store - without queryExecutor":function(){var a=
f({data:[]},l).track();a.fetch();var c;a.on("add",function(a){c=a});a=a.addSync({type:"test-item",id:1,name:"one"});d.deepEqual(c,{type:"add",index:0,target:a,totalLength:1})},"new item - with options.beforeId and queryExecutor":function(){var a=k(),c=a.filter({even:!0}).track().fetchSync();a.defaultNewToStart=!0;a.add({id:6,name:"six",even:!0},{beforeId:2});a.add({id:-2,name:"negative-two",even:!0},{beforeId:null});d.strictEqual(c[1].id,6);d.strictEqual(c[2].id,2);d.strictEqual(c[c.length-1].id,
-2)},"new item - with options.beforeId and no queryExecutor":function(){var a=k(),c=a.track().fetchSync();a.defaultNewToStart=!0;a.add({id:6,name:"six",even:!0},{beforeId:2});a.add({id:-2,name:"negative-two",even:!0},{beforeId:null});d.strictEqual(c[2].id,6);d.strictEqual(c[3].id,2);d.strictEqual(c[c.length-1].id,-2)},"updated item - with options.beforeId and queryExecutor":function(){var a=k(),c=a.filter({even:!0}).track().fetchSync();a.defaultNewToStart=!0;a.put(a.getSync(4),{beforeId:2});a.put(a.getSync(0),
{beforeId:null});d.strictEqual(c[0].id,4);d.strictEqual(c[1].id,2);d.strictEqual(c[c.length-1].id,0)},"updated item - with options.beforeId and no queryExecutor":function(){var a=k(),c=a.track().fetchSync();a.defaultNewToStart=!0;a.put(a.getSync(4),{beforeId:2});a.put(a.getSync(3),{beforeId:null});d.strictEqual(c[2].id,4);d.strictEqual(c[3].id,2);d.strictEqual(c[c.length-1].id,3)},type:function(){d.isFalse(h===h.track(function(){}))},"track and collection.tracking.remove":function(){var a=f({data:n(10)},
l),c=a.track();d.property(c,"tracking");c.fetch();var e=null;c.on("add, update",function(a){e=a});a.put({id:11,name:"item-11",order:11});d.isNotNull(e);d.isDefined(e.index);c.tracking.remove();e=null;a.put({id:12,name:"item-12",order:12});d.isNull(e)}}}m(v("Trackable mixin",function(d,f){return new (r([f,u]))(d)}));m(v("Trackable.create()",function(d,f){return u.create(new f(d))}))});
//# sourceMappingURL=Trackable.js.map