StatefulArray.js 2.15 KB
//>>built
define(["dojo/_base/lang","dojo/Stateful"],function(a,h){function m(a){a._watchElementCallbacks&&a._watchElementCallbacks(void 0,[],[]);return a}var c=function(k){k=a._toArray(k||[]);k.constructor=c;return a.mixin(k,{pop:function(){return this.splice(this.get("length")-1,1)[0]},push:function(){this.splice.apply(this,[this.get("length"),0].concat(a._toArray(arguments)));return this.get("length")},reverse:function(){return m([].reverse.apply(this,a._toArray(arguments)))},shift:function(){return this.splice(0,
1)[0]},sort:function(){return m([].sort.apply(this,a._toArray(arguments)))},splice:function(b,d){var e=this.get("length");b+=0>b?e:0;var l=Math.min(b,e),g=this.slice(b,b+d),f=a._toArray(arguments).slice(2);[].splice.apply(this,[b,d].concat(Array(f.length)));for(var c=0;c<f.length;c++)this[l+c]=f[c];this._watchElementCallbacks&&this._watchElementCallbacks(b,g,f);this._watchCallbacks&&this._watchCallbacks("length",e,e-g.length+f.length);return g},unshift:function(){this.splice.apply(this,[0,0].concat(a._toArray(arguments)));
return this.get("length")},concat:function(b){return new c([].concat.apply(this,arguments))},join:function(b){for(var d=[],e=this.get("length"),a=0;a<e;a++)d.push(this.get(a));return d.join(b)},slice:function(b,d){var a=this.get("length");d=(void 0===d?a:d)+(0>d?a:0);var l=[];for(b=b+(0>b?a:0)||0;b<Math.min(d,this.get("length"));b++)l.push(this.get(b));return new c(l)},watchElements:function(b){var d=this._watchElementCallbacks,a=this;d||(d=this._watchElementCallbacks=function(b,c,e){for(var f=[].concat(d.list),
g=0;g<f.length;g++)f[g].call(a,b,c,e)},d.list=[]);d.list.push(b);var c={};c.unwatch=c.remove=function(){for(var a=d.list,c=0;c<a.length;c++)if(a[c]==b){a.splice(c,1);break}};return c}},h.prototype,{set:function(b,a){if("length"==b)b=this.get("length"),b<a?this.splice.apply(this,[b,0].concat(Array(a-b))):a<b&&this.splice.apply(this,[a,b-a]);else{var c=this.length;h.prototype.set.call(this,b,a);c!=this.length&&h.prototype.set.call(this,"length",this.length)}return this},isInstanceOf:function(a){return h.prototype.isInstanceOf.apply(this,
arguments)||a==c}})};c._meta={bases:[h]};return a.setObject("dojox.mvc.StatefulArray",c)});