Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Build lazy-model-list.

  • Loading branch information...
commit 0f97aa83f853714eab7d297fa27860a902bda913 1 parent a3891a3
Ryan Grove authored
9 build/lazy-model-list/lazy-model-list-debug.js
View
@@ -204,7 +204,8 @@ Y.LazyModelList = Y.Base.create('lazyModelList', Y.ModelList, [], {
// Convert `items` into an array of plain objects, since we don't want
// model instances.
- items = items.map(this._modelToObject);
+ items = items._isYUIModelList ? items.map(this._modelToObject) :
+ YArray.map(items, this._modelToObject);
facade.models = items;
@@ -228,7 +229,9 @@ Y.LazyModelList = Y.Base.create('lazyModelList', Y.ModelList, [], {
must exist in the list), or may be omitted to revive all items in the list.
Once revived, Model instances are attached to this list and cached so that
- reviving them in the future doesn't require another Model instantiation.
+ reviving them in the future doesn't require another Model instantiation. Use
+ the `free()` method to explicitly uncache and detach a previously revived
+ Model instance.
Note: Specifying an index rather than an object will be faster, since
objects require an `indexOf()` lookup in order to retrieve the index.
@@ -411,7 +414,7 @@ Y.LazyModelList = Y.Base.create('lazyModelList', Y.ModelList, [], {
@protected
**/
_revive: function (index) {
- var model;
+ var item, model;
if (index < 0) {
return null;
2  build/lazy-model-list/lazy-model-list-min.js
View
@@ -1 +1 @@
-YUI.add("lazy-model-list",function(h){var g=h.Attribute.prototype,b=YUI.namespace("Env.Model"),f=h.Lang,e=h.Array,d="add",a="error",c="reset";h.LazyModelList=h.Base.create("lazyModelList",h.ModelList,[],{destructor:function(){this._clear();},free:function(j){var i;if(j){i=f.isNumber(j)?j:this.indexOf(j);if(i>=0){delete this._models[i];}}else{this._models=[];}return this;},get:function(i){if(this.attrAdded(i)){return g.get.apply(this,arguments);}return e.map(this._items,function(j){return j[i];});},getAsHTML:function(i){if(this.attrAdded(i)){return h.Escape.html(g.get.apply(this,arguments));}return e.map(this._items,function(j){return h.Escape.html(j[i]);});},getAsURL:function(i){if(this.attrAdded(i)){return encodeURIComponent(g.get.apply(this,arguments));}return e.map(this._items,function(j){return encodeURIComponent(j[i]);});},indexOf:function(i){return e.indexOf(i._isYUIModel?this._models:this._items,i);},reset:function(i,j){i||(i=[]);j||(j={});var k=h.merge({src:"reset"},j);i=i.map(this._modelToObject);k.models=i;if(j.silent){this._defResetFn(k);}else{if(this.comparator){i.sort(h.bind(this._sort,this));}this.fire(c,k);}return this;},revive:function(l){var k,j,m;if(l||l===0){return this._revive(f.isNumber(l)?l:this.indexOf(l));}else{m=[];for(k=0,j=this._items.length;k<j;k++){m.push(this._revive(k));}return m;}},toJSON:function(){return this.toArray();},_add:function(k,i){var j;i||(i={});k=this._modelToObject(k);if(!("clientId" in k)){k.clientId=this._generateClientId();}if(this._isInList(k)){this.fire(a,{error:"Model is already in the list.",model:k,src:"add"});return;}j=h.merge(i,{index:"index" in i?i.index:this._findIndex(k),model:k});i.silent?this._defAddFn(j):this.fire(d,j);return k;},_clear:function(){e.each(this._models,this._detachList,this);this._clientIdMap={};this._idMap={};this._items=[];this._models=[];},_generateClientId:function(){b.lastId||(b.lastId=0);return this.model.NAME+"_"+(b.lastId+=1);},_isInList:function(i){return !!(("clientId" in i&&this._clientIdMap[i.clientId])||("id" in i&&this._idMap[i.id]));},_modelToObject:function(i){if(i._isYUIModel){i=i.getAttrs();delete i.destroyed;delete i.initialized;}return i;},_remove:function(j,i){if(j._isYUIModel){j=this.indexOf(j);}return h.ModelList.prototype._remove.call(this,j,i);},_revive:function(j){var i;if(j<0){return null;}item=this._items[j];if(!item){return null;}i=this._models[j];if(!i){i=new this.model(item);this._attachList(i);this._models[j]=i;}return i;},_defAddFn:function(j){var i=j.model;this._clientIdMap[i.clientId]=i;if(f.isValue(i.id)){this._idMap[i.id]=i;}this._items.splice(j.index,0,i);},_defRemoveFn:function(l){var j=l.index,k=l.model,i=this._models[j];delete this._clientIdMap[k.clientId];if("id" in k){delete this._idMap[k.id];}if(i){this._detachList(i);this._models.splice(j,1);}this._items.splice(j,1);}});},"@VERSION@",{requires:["model-list"]});
+YUI.add("lazy-model-list",function(h){var g=h.Attribute.prototype,b=YUI.namespace("Env.Model"),f=h.Lang,e=h.Array,d="add",a="error",c="reset";h.LazyModelList=h.Base.create("lazyModelList",h.ModelList,[],{destructor:function(){this._clear();},free:function(j){var i;if(j){i=f.isNumber(j)?j:this.indexOf(j);if(i>=0){delete this._models[i];}}else{this._models=[];}return this;},get:function(i){if(this.attrAdded(i)){return g.get.apply(this,arguments);}return e.map(this._items,function(j){return j[i];});},getAsHTML:function(i){if(this.attrAdded(i)){return h.Escape.html(g.get.apply(this,arguments));}return e.map(this._items,function(j){return h.Escape.html(j[i]);});},getAsURL:function(i){if(this.attrAdded(i)){return encodeURIComponent(g.get.apply(this,arguments));}return e.map(this._items,function(j){return encodeURIComponent(j[i]);});},indexOf:function(i){return e.indexOf(i._isYUIModel?this._models:this._items,i);},reset:function(i,j){i||(i=[]);j||(j={});var k=h.merge({src:"reset"},j);i=i._isYUIModelList?i.map(this._modelToObject):e.map(i,this._modelToObject);k.models=i;if(j.silent){this._defResetFn(k);}else{if(this.comparator){i.sort(h.bind(this._sort,this));}this.fire(c,k);}return this;},revive:function(l){var k,j,m;if(l||l===0){return this._revive(f.isNumber(l)?l:this.indexOf(l));}else{m=[];for(k=0,j=this._items.length;k<j;k++){m.push(this._revive(k));}return m;}},toJSON:function(){return this.toArray();},_add:function(k,i){var j;i||(i={});k=this._modelToObject(k);if(!("clientId" in k)){k.clientId=this._generateClientId();}if(this._isInList(k)){this.fire(a,{error:"Model is already in the list.",model:k,src:"add"});return;}j=h.merge(i,{index:"index" in i?i.index:this._findIndex(k),model:k});i.silent?this._defAddFn(j):this.fire(d,j);return k;},_clear:function(){e.each(this._models,this._detachList,this);this._clientIdMap={};this._idMap={};this._items=[];this._models=[];},_generateClientId:function(){b.lastId||(b.lastId=0);return this.model.NAME+"_"+(b.lastId+=1);},_isInList:function(i){return !!(("clientId" in i&&this._clientIdMap[i.clientId])||("id" in i&&this._idMap[i.id]));},_modelToObject:function(i){if(i._isYUIModel){i=i.getAttrs();delete i.destroyed;delete i.initialized;}return i;},_remove:function(j,i){if(j._isYUIModel){j=this.indexOf(j);}return h.ModelList.prototype._remove.call(this,j,i);},_revive:function(j){var k,i;if(j<0){return null;}k=this._items[j];if(!k){return null;}i=this._models[j];if(!i){i=new this.model(k);this._attachList(i);this._models[j]=i;}return i;},_defAddFn:function(j){var i=j.model;this._clientIdMap[i.clientId]=i;if(f.isValue(i.id)){this._idMap[i.id]=i;}this._items.splice(j.index,0,i);},_defRemoveFn:function(l){var j=l.index,k=l.model,i=this._models[j];delete this._clientIdMap[k.clientId];if("id" in k){delete this._idMap[k.id];}if(i){this._detachList(i);this._models.splice(j,1);}this._items.splice(j,1);}});},"@VERSION@",{requires:["model-list"]});
9 build/lazy-model-list/lazy-model-list.js
View
@@ -204,7 +204,8 @@ Y.LazyModelList = Y.Base.create('lazyModelList', Y.ModelList, [], {
// Convert `items` into an array of plain objects, since we don't want
// model instances.
- items = items.map(this._modelToObject);
+ items = items._isYUIModelList ? items.map(this._modelToObject) :
+ YArray.map(items, this._modelToObject);
facade.models = items;
@@ -228,7 +229,9 @@ Y.LazyModelList = Y.Base.create('lazyModelList', Y.ModelList, [], {
must exist in the list), or may be omitted to revive all items in the list.
Once revived, Model instances are attached to this list and cached so that
- reviving them in the future doesn't require another Model instantiation.
+ reviving them in the future doesn't require another Model instantiation. Use
+ the `free()` method to explicitly uncache and detach a previously revived
+ Model instance.
Note: Specifying an index rather than an object will be faster, since
objects require an `indexOf()` lookup in order to retrieve the index.
@@ -411,7 +414,7 @@ Y.LazyModelList = Y.Base.create('lazyModelList', Y.ModelList, [], {
@protected
**/
_revive: function (index) {
- var model;
+ var item, model;
if (index < 0) {
return null;
Please sign in to comment.
Something went wrong with that request. Please try again.