Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@egjs/deview-recycle

Package Overview
Dependencies
Maintainers
8
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@egjs/deview-recycle - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

1

declaration/DeviewRecycle.d.ts

@@ -27,4 +27,5 @@ import Component from "@egjs/component";

private onResize;
private refreshCursor();
private setCursor(startCursor, endCursor);
private recycle(ranges);
}

@@ -7,3 +7,3 @@ /*

repository: git+https://github.com/NAVER-FEPlatform/deview2019-demo.git
version: 0.0.2
version: 0.0.3
*/

@@ -196,2 +196,3 @@ 'use strict';

if (!renderExternal) {
this.refreshCursor();
this.layout();

@@ -212,2 +213,3 @@ }

this.refreshCursor();
this.layout();

@@ -268,3 +270,3 @@ }

var item = items.splice(fromIndex, 1)[0];
items.splice(toIndex, 1, item);
items.splice(toIndex, 0, item);
});

@@ -274,6 +276,7 @@ result.added.forEach(function (index) {

});
this.refreshCursor();
};
__proto.sync = function (elements) {
this.items.splice(this.startCursor, this.endCursor + 1).forEach(function (item, i) {
this.items.slice(this.startCursor, this.endCursor + 1).forEach(function (item, i) {
item.el = elements[i];

@@ -303,2 +306,17 @@ item.mounted = true;

__proto.refreshCursor = function () {
var startCursor = -1;
var endCursor = -1;
this.items.forEach(function (item, i) {
if (!item.mounted) {
return;
}
startCursor < 0 && (startCursor = i);
endCursor = i;
});
this.startCursor = startCursor;
this.endCursor = endCursor;
};
__proto.setCursor = function (startCursor, endCursor) {

@@ -341,3 +359,6 @@ var container = this.container;

this.trigger("visibleChange");
this.trigger("visibleChange", {
startCursor: startCursor,
endCursor: endCursor
});
};

@@ -354,6 +375,6 @@

for (var i = start; i < end; ++i) {
for (var i = start; i <= end; ++i) {
var item = items[i];
if (!item.mounted) {
if (!item || !item.mounted) {
continue;

@@ -360,0 +381,0 @@ }

@@ -7,3 +7,3 @@ /*

repository: git+https://github.com/NAVER-FEPlatform/deview2019-demo.git
version: 0.0.2
version: 0.0.3
*/

@@ -194,2 +194,3 @@ import Component from '@egjs/component';

if (!renderExternal) {
this.refreshCursor();
this.layout();

@@ -210,2 +211,3 @@ }

this.refreshCursor();
this.layout();

@@ -266,3 +268,3 @@ }

var item = items.splice(fromIndex, 1)[0];
items.splice(toIndex, 1, item);
items.splice(toIndex, 0, item);
});

@@ -272,6 +274,7 @@ result.added.forEach(function (index) {

});
this.refreshCursor();
};
__proto.sync = function (elements) {
this.items.splice(this.startCursor, this.endCursor + 1).forEach(function (item, i) {
this.items.slice(this.startCursor, this.endCursor + 1).forEach(function (item, i) {
item.el = elements[i];

@@ -301,2 +304,17 @@ item.mounted = true;

__proto.refreshCursor = function () {
var startCursor = -1;
var endCursor = -1;
this.items.forEach(function (item, i) {
if (!item.mounted) {
return;
}
startCursor < 0 && (startCursor = i);
endCursor = i;
});
this.startCursor = startCursor;
this.endCursor = endCursor;
};
__proto.setCursor = function (startCursor, endCursor) {

@@ -339,3 +357,6 @@ var container = this.container;

this.trigger("visibleChange");
this.trigger("visibleChange", {
startCursor: startCursor,
endCursor: endCursor
});
};

@@ -352,6 +373,6 @@

for (var i = start; i < end; ++i) {
for (var i = start; i <= end; ++i) {
var item = items[i];
if (!item.mounted) {
if (!item || !item.mounted) {
continue;

@@ -358,0 +379,0 @@ }

@@ -7,3 +7,3 @@ /*

repository: git+https://github.com/NAVER-FEPlatform/deview2019-demo.git
version: 0.0.2
version: 0.0.3
*/

@@ -814,2 +814,3 @@ (function (global, factory) {

if (!renderExternal) {
this.refreshCursor();
this.layout();

@@ -830,2 +831,3 @@ }

this.refreshCursor();
this.layout();

@@ -886,3 +888,3 @@ }

var item = items.splice(fromIndex, 1)[0];
items.splice(toIndex, 1, item);
items.splice(toIndex, 0, item);
});

@@ -892,6 +894,7 @@ result.added.forEach(function (index) {

});
this.refreshCursor();
};
__proto.sync = function (elements) {
this.items.splice(this.startCursor, this.endCursor + 1).forEach(function (item, i) {
this.items.slice(this.startCursor, this.endCursor + 1).forEach(function (item, i) {
item.el = elements[i];

@@ -921,2 +924,17 @@ item.mounted = true;

__proto.refreshCursor = function () {
var startCursor = -1;
var endCursor = -1;
this.items.forEach(function (item, i) {
if (!item.mounted) {
return;
}
startCursor < 0 && (startCursor = i);
endCursor = i;
});
this.startCursor = startCursor;
this.endCursor = endCursor;
};
__proto.setCursor = function (startCursor, endCursor) {

@@ -959,3 +977,6 @@ var container = this.container;

this.trigger("visibleChange");
this.trigger("visibleChange", {
startCursor: startCursor,
endCursor: endCursor
});
};

@@ -972,6 +993,6 @@

for (var i = start; i < end; ++i) {
for (var i = start; i <= end; ++i) {
var item = items[i];
if (!item.mounted) {
if (!item || !item.mounted) {
continue;

@@ -978,0 +999,0 @@ }

4

dist/recycle.min.js

@@ -7,5 +7,5 @@ /*

repository: git+https://github.com/NAVER-FEPlatform/deview2019-demo.git
version: 0.0.2
version: 0.0.3
*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).DeviewRecycle=e()}(this,function(){"use strict";var r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};var i=function(){return(i=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function c(t){return void 0===t}var t=function(){var t=function(){function t(){this._eventHandler={},this.options={}}var e=t.prototype;return e.trigger=function(t,e){void 0===e&&(e={});var n=this._eventHandler[t]||[];if(!(0<n.length))return!0;n=n.concat(),e.eventType=t;var r=!1,i=[e],o=0;e.stop=function(){r=!0},e.currentTarget=this;for(var s=arguments.length,c=new Array(2<s?s-2:0),u=2;u<s;u++)c[u-2]=arguments[u];for(1<=c.length&&(i=i.concat(c)),o=0;n[o];o++)n[o].apply(this,i);return!r},e.once=function(i,o){if("object"==typeof i&&c(o)){var t,e=i;for(t in e)this.once(t,e[t]);return this}if("string"==typeof i&&"function"==typeof o){var s=this;this.on(i,function t(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];o.apply(s,n),s.off(i,t)})}return this},e.hasOn=function(t){return!!this._eventHandler[t]},e.on=function(t,e){if("object"==typeof t&&c(e)){var n,r=t;for(n in r)this.on(n,r[n]);return this}if("string"==typeof t&&"function"==typeof e){var i=this._eventHandler[t];c(i)&&(this._eventHandler[t]=[],i=this._eventHandler[t]),i.push(e)}return this},e.off=function(t,e){if(c(t))return this._eventHandler={},this;if(c(e)){if("string"==typeof t)return this._eventHandler[t]=void 0,this;var n,r=t;for(n in r)this.off(n,r[n]);return this}var i,o,s=this._eventHandler[t];if(s)for(i=0;void 0!==(o=s[i]);i++)if(o===e){s=s.splice(i,1);break}return this},t}();return t.VERSION="2.1.2",t}(),y=function(){function t(){this.keys=[],this.values=[]}var e=t.prototype;return e.get=function(t){return this.values[this.keys.indexOf(t)]},e.set=function(t,e){var n=this.keys,r=this.values,i=n.indexOf(t),o=-1===i?n.length:i;n[o]=t,r[o]=e},t}(),w=function(){function t(){this.object={}}var e=t.prototype;return e.get=function(t){return this.object[t]},e.set=function(t,e){this.object[t]=e},t}(),E="function"==typeof Map,o=function(){function t(){}var e=t.prototype;return e.connect=function(t,e){this.prev=t,this.next=e,t&&(t.next=this),e&&(e.prev=this)},e.disconnect=function(){var t=this.prev,e=this.next;t&&(t.next=e),e&&(e.prev=t)},e.getIndex=function(){for(var t=this,e=-1;t;)t=t.prev,++e;return e},t}();var x=function(){function t(t,e,n,r,i,o,s,c){this.prevList=t,this.list=e,this.added=n,this.removed=r,this.changed=i,this.maintained=o,this.changedBeforeAdded=s,this.fixed=c}var e=t.prototype;return Object.defineProperty(e,"ordered",{get:function(){return this.cacheOrdered||this.caculateOrdered(),this.cacheOrdered},enumerable:!0,configurable:!0}),Object.defineProperty(e,"pureChanged",{get:function(){return this.cachePureChanged||this.caculateOrdered(),this.cachePureChanged},enumerable:!0,configurable:!0}),e.caculateOrdered=function(){var t=function(t,n){var c=[],u=[];return t.forEach(function(t){var e=t[0],n=t[1],r=new o;c[e]=r,u[n]=r}),c.forEach(function(t,e){t.connect(c[e-1])}),t.filter(function(t,e){return!n[e]}).map(function(t,e){var n=t[0],r=t[1];if(n===r)return[0,0];var i=c[n],o=u[r-1],s=i.getIndex();return i.disconnect(),o?i.connect(o,o.next):i.connect(void 0,c[0]),[s,i.getIndex()]})}(this.changedBeforeAdded,this.fixed),c=this.changed,u=[];this.cacheOrdered=t.filter(function(t,e){var n=t[0],r=t[1],i=c[e],o=i[0],s=i[1];if(n!==r)return u.push([o,s]),!0}),this.cachePureChanged=u},t}();var e=function(n){function t(t,e){void 0===e&&(e={});var a=n.call(this)||this;return a.container=t,a.items=[],a.containerOffset=0,a.containerHeight=0,a.scrollHeight=0,a.timer=0,a.startCursor=-1,a.endCursor=-1,a.onScroll=function(){var t=a.options,i=t.threshold,o=t.overflow?a.container.scrollTop:document.documentElement.scrollTop,e=o-a.containerOffset,n=a.items,r=n.length;if(r){var s=e+a.containerHeight,c=-1,u=-1;if(n.filter(function(t,e){var n=t.pos,r=n+t.size;return n-i<=s&&o<=r+i&&(c<0&&(c=e),u=e,!0)}).length||(u=c=n[r-1].pos<o?r-1:0),a.setCursor(c,u),u!==r-1)return}e>a.scrollHeight-a.containerHeight-i&&(clearTimeout(a.timer),a.timer=window.setTimeout(function(){a.trigger("append",{requestIndex:a.items.length})},60))},a.onResize=function(){var t=a.options.overflow;a.containerOffset=t?0:a.container.getBoundingClientRect().top,a.containerHeight=t?a.container.offsetHeight:window.innerHeight,a.items.forEach(function(t){t.updated=!1}),a.layout()},a.options=i({threshold:100,margin:0,renderExternal:!1,overflow:!1},e),e.overflow&&(t.style.overflow="scroll"),(e.overflow?t:window).addEventListener("scroll",a.onScroll),window.addEventListener("resize",a.onResize),a.onResize(),a.onScroll(),a}!function(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}(t,n);var e=t.prototype;return e.insert=function(t,e,n){var r=this.options.renderExternal,i=this.items,o={el:r?null:"object"==typeof e?e:function(t){var e=document.createElement("div");return e.innerHTML=t,e.children[0]}(e),key:n,size:0,pos:0,mounted:!1,updated:!1};return i.splice(t,0,o),r||this.layout(),o},e.remove=function(t){var e=this.options,n=this.items.splice(t,1)[0];return e.renderExternal||(n.mounted&&this.container.removeChild(n.el),this.layout()),n},e.layout=function(){var t=this.options,e=t.overflow,n=t.margin,r=void 0===n?0:n,i=0;return this.items.forEach(function(t){t.mounted&&!t.updated&&(t.size=t.el.offsetHeight,t.updated=!0),t.pos=i,i+=t.size+r}),e||(this.container.style.height=i+"px"),this.scrollHeight=i,this.items.forEach(function(t){t.mounted&&(t.el.style.cssText+="position: absolute;top: "+t.pos+"px;")}),this.onScroll(),this},e.beforeSync=function(e){var n=this,i=this.items,t=function(t,e,n){var r=E?Map:n?w:y,i=n||function(t){return t},o=[],s=[],c=[],u=t.map(i),a=e.map(i),f=new r,h=new r,d=[],l=[],v={},p=[],g=0,m=0;return u.forEach(function(t,e){f.set(t,e)}),a.forEach(function(t,e){h.set(t,e)}),u.forEach(function(t,e){var n=h.get(t);void 0===n?(++m,s.push(e)):v[n]=m}),a.forEach(function(t,e){var n=f.get(t);void 0===n?(o.push(e),++g):(c.push([n,e]),m=v[e]||0,d.push([n-m,e-g]),l.push(e===n),n!==e&&p.push([n,e]))}),s.reverse(),new x(t,e,o,s,p,c,d,l)}(this.items.map(function(t){return t.key}),e,function(t){return t});t.removed.forEach(function(t){n.remove(t)}),t.ordered.forEach(function(t){var e=t[0],n=t[1],r=i.splice(e,1)[0];i.splice(n,1,r)}),t.added.forEach(function(t){n.insert(t,"",e[t])})},e.sync=function(n){return this.items.splice(this.startCursor,this.endCursor+1).forEach(function(t,e){t.el=n[e],t.mounted=!0}),this.layout(),this},e.append=function(t){return this.insert(this.items.length,t,""),this},e.destroy=function(){(this.options.overflow?this.container:window).removeEventListener("scroll",this.onScroll),window.removeEventListener("resize",this.onResize)},e.getRenderingIndexes=function(){return{start:this.startCursor,end:this.endCursor}},e.setCursor=function(t,e){var n=this.container,r=this.items,i=this.options.renderExternal;this.recycle([{start:0,end:t-1},{start:e+1,end:r.length}]);var o=this.startCursor,s=this.endCursor;this.startCursor=t;for(var c=this.endCursor=e;t<=c;--c){var u=r[c];if(!u.mounted){var a=r[c+1],f=a&&a.mounted?a.el:null;i||n.insertBefore(u.el,f),u.mounted=!0}}i||o===t&&s===e||this.layout(),this.trigger("visibleChange")},e.recycle=function(t){var o=this,s=this.items,c=this.options.renderExternal;t.forEach(function(t){for(var e=t.start,n=t.end,r=e;r<n;++r){var i=s[r];i.mounted&&(i.mounted=!1,c||o.container.removeChild(i.el))}})},t}(t);return e.DEFAULT_OPTIONS={threshold:100,margin:0,renderExternal:!1,overflow:!1},e});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).DeviewRecycle=e()}(this,function(){"use strict";var r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};var i=function(){return(i=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function c(t){return void 0===t}var t=function(){var t=function(){function t(){this._eventHandler={},this.options={}}var e=t.prototype;return e.trigger=function(t,e){void 0===e&&(e={});var n=this._eventHandler[t]||[];if(!(0<n.length))return!0;n=n.concat(),e.eventType=t;var r=!1,i=[e],o=0;e.stop=function(){r=!0},e.currentTarget=this;for(var s=arguments.length,c=new Array(2<s?s-2:0),u=2;u<s;u++)c[u-2]=arguments[u];for(1<=c.length&&(i=i.concat(c)),o=0;n[o];o++)n[o].apply(this,i);return!r},e.once=function(i,o){if("object"==typeof i&&c(o)){var t,e=i;for(t in e)this.once(t,e[t]);return this}if("string"==typeof i&&"function"==typeof o){var s=this;this.on(i,function t(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];o.apply(s,n),s.off(i,t)})}return this},e.hasOn=function(t){return!!this._eventHandler[t]},e.on=function(t,e){if("object"==typeof t&&c(e)){var n,r=t;for(n in r)this.on(n,r[n]);return this}if("string"==typeof t&&"function"==typeof e){var i=this._eventHandler[t];c(i)&&(this._eventHandler[t]=[],i=this._eventHandler[t]),i.push(e)}return this},e.off=function(t,e){if(c(t))return this._eventHandler={},this;if(c(e)){if("string"==typeof t)return this._eventHandler[t]=void 0,this;var n,r=t;for(n in r)this.off(n,r[n]);return this}var i,o,s=this._eventHandler[t];if(s)for(i=0;void 0!==(o=s[i]);i++)if(o===e){s=s.splice(i,1);break}return this},t}();return t.VERSION="2.1.2",t}(),y=function(){function t(){this.keys=[],this.values=[]}var e=t.prototype;return e.get=function(t){return this.values[this.keys.indexOf(t)]},e.set=function(t,e){var n=this.keys,r=this.values,i=n.indexOf(t),o=-1===i?n.length:i;n[o]=t,r[o]=e},t}(),w=function(){function t(){this.object={}}var e=t.prototype;return e.get=function(t){return this.object[t]},e.set=function(t,e){this.object[t]=e},t}(),E="function"==typeof Map,o=function(){function t(){}var e=t.prototype;return e.connect=function(t,e){this.prev=t,this.next=e,t&&(t.next=this),e&&(e.prev=this)},e.disconnect=function(){var t=this.prev,e=this.next;t&&(t.next=e),e&&(e.prev=t)},e.getIndex=function(){for(var t=this,e=-1;t;)t=t.prev,++e;return e},t}();var C=function(){function t(t,e,n,r,i,o,s,c){this.prevList=t,this.list=e,this.added=n,this.removed=r,this.changed=i,this.maintained=o,this.changedBeforeAdded=s,this.fixed=c}var e=t.prototype;return Object.defineProperty(e,"ordered",{get:function(){return this.cacheOrdered||this.caculateOrdered(),this.cacheOrdered},enumerable:!0,configurable:!0}),Object.defineProperty(e,"pureChanged",{get:function(){return this.cachePureChanged||this.caculateOrdered(),this.cachePureChanged},enumerable:!0,configurable:!0}),e.caculateOrdered=function(){var t=function(t,n){var c=[],u=[];return t.forEach(function(t){var e=t[0],n=t[1],r=new o;c[e]=r,u[n]=r}),c.forEach(function(t,e){t.connect(c[e-1])}),t.filter(function(t,e){return!n[e]}).map(function(t,e){var n=t[0],r=t[1];if(n===r)return[0,0];var i=c[n],o=u[r-1],s=i.getIndex();return i.disconnect(),o?i.connect(o,o.next):i.connect(void 0,c[0]),[s,i.getIndex()]})}(this.changedBeforeAdded,this.fixed),c=this.changed,u=[];this.cacheOrdered=t.filter(function(t,e){var n=t[0],r=t[1],i=c[e],o=i[0],s=i[1];if(n!==r)return u.push([o,s]),!0}),this.cachePureChanged=u},t}();var e=function(n){function t(t,e){void 0===e&&(e={});var h=n.call(this)||this;return h.container=t,h.items=[],h.containerOffset=0,h.containerHeight=0,h.scrollHeight=0,h.timer=0,h.startCursor=-1,h.endCursor=-1,h.onScroll=function(){var t=h.options,i=t.threshold,o=t.overflow?h.container.scrollTop:document.documentElement.scrollTop,e=o-h.containerOffset,n=h.items,r=n.length;if(r){var s=e+h.containerHeight,c=-1,u=-1;if(n.filter(function(t,e){var n=t.pos,r=n+t.size;return n-i<=s&&o<=r+i&&(c<0&&(c=e),u=e,!0)}).length||(u=c=n[r-1].pos<o?r-1:0),h.setCursor(c,u),u!==r-1)return}e>h.scrollHeight-h.containerHeight-i&&(clearTimeout(h.timer),h.timer=window.setTimeout(function(){h.trigger("append",{requestIndex:h.items.length})},60))},h.onResize=function(){var t=h.options.overflow;h.containerOffset=t?0:h.container.getBoundingClientRect().top,h.containerHeight=t?h.container.offsetHeight:window.innerHeight,h.items.forEach(function(t){t.updated=!1}),h.layout()},h.options=i({threshold:100,margin:0,renderExternal:!1,overflow:!1},e),e.overflow&&(t.style.overflow="scroll"),(e.overflow?t:window).addEventListener("scroll",h.onScroll),window.addEventListener("resize",h.onResize),h.onResize(),h.onScroll(),h}!function(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}(t,n);var e=t.prototype;return e.insert=function(t,e,n){var r=this.options.renderExternal,i=this.items,o={el:r?null:"object"==typeof e?e:function(t){var e=document.createElement("div");return e.innerHTML=t,e.children[0]}(e),key:n,size:0,pos:0,mounted:!1,updated:!1};return i.splice(t,0,o),r||(this.refreshCursor(),this.layout()),o},e.remove=function(t){var e=this.options,n=this.items.splice(t,1)[0];return e.renderExternal||(n.mounted&&this.container.removeChild(n.el),this.refreshCursor(),this.layout()),n},e.layout=function(){var t=this.options,e=t.overflow,n=t.margin,r=void 0===n?0:n,i=0;return this.items.forEach(function(t){t.mounted&&!t.updated&&(t.size=t.el.offsetHeight,t.updated=!0),t.pos=i,i+=t.size+r}),e||(this.container.style.height=i+"px"),this.scrollHeight=i,this.items.forEach(function(t){t.mounted&&(t.el.style.cssText+="position: absolute;top: "+t.pos+"px;")}),this.onScroll(),this},e.beforeSync=function(e){var n=this,i=this.items,t=function(t,e,n){var r=E?Map:n?w:y,i=n||function(t){return t},o=[],s=[],c=[],u=t.map(i),h=e.map(i),a=new r,f=new r,d=[],l=[],v={},p=[],g=0,m=0;return u.forEach(function(t,e){a.set(t,e)}),h.forEach(function(t,e){f.set(t,e)}),u.forEach(function(t,e){var n=f.get(t);void 0===n?(++m,s.push(e)):v[n]=m}),h.forEach(function(t,e){var n=a.get(t);void 0===n?(o.push(e),++g):(c.push([n,e]),m=v[e]||0,d.push([n-m,e-g]),l.push(e===n),n!==e&&p.push([n,e]))}),s.reverse(),new C(t,e,o,s,p,c,d,l)}(this.items.map(function(t){return t.key}),e,function(t){return t});t.removed.forEach(function(t){n.remove(t)}),t.ordered.forEach(function(t){var e=t[0],n=t[1],r=i.splice(e,1)[0];i.splice(n,0,r)}),t.added.forEach(function(t){n.insert(t,"",e[t])}),this.refreshCursor()},e.sync=function(n){return this.items.slice(this.startCursor,this.endCursor+1).forEach(function(t,e){t.el=n[e],t.mounted=!0}),this.layout(),this},e.append=function(t){return this.insert(this.items.length,t,""),this},e.destroy=function(){(this.options.overflow?this.container:window).removeEventListener("scroll",this.onScroll),window.removeEventListener("resize",this.onResize)},e.getRenderingIndexes=function(){return{start:this.startCursor,end:this.endCursor}},e.refreshCursor=function(){var n=-1,r=-1;this.items.forEach(function(t,e){t.mounted&&(n<0&&(n=e),r=e)}),this.startCursor=n,this.endCursor=r},e.setCursor=function(t,e){var n=this.container,r=this.items,i=this.options.renderExternal;this.recycle([{start:0,end:t-1},{start:e+1,end:r.length}]);var o=this.startCursor,s=this.endCursor;this.startCursor=t;for(var c=this.endCursor=e;t<=c;--c){var u=r[c];if(!u.mounted){var h=r[c+1],a=h&&h.mounted?h.el:null;i||n.insertBefore(u.el,a),u.mounted=!0}}i||o===t&&s===e||this.layout(),this.trigger("visibleChange",{startCursor:t,endCursor:e})},e.recycle=function(t){var o=this,s=this.items,c=this.options.renderExternal;t.forEach(function(t){for(var e=t.start,n=t.end,r=e;r<=n;++r){var i=s[r];i&&i.mounted&&(i.mounted=!1,c||o.container.removeChild(i.el))}})},t}(t);return e.DEFAULT_OPTIONS={threshold:100,margin:0,renderExternal:!1,overflow:!1},e});
//# sourceMappingURL=recycle.min.js.map
{
"name": "@egjs/deview-recycle",
"version": "0.0.2",
"version": "0.0.3",
"description": "",

@@ -5,0 +5,0 @@ "main": "./dist/recycle.cjs.js",

@@ -59,2 +59,3 @@ import Component from "@egjs/component";

if (!renderExternal) {
this.refreshCursor();
this.layout();

@@ -72,2 +73,3 @@ }

}
this.refreshCursor();
this.layout();

@@ -115,3 +117,3 @@ }

items.splice(toIndex, 1, item);
items.splice(toIndex, 0, item);
});

@@ -121,5 +123,6 @@ result.added.forEach(index => {

});
this.refreshCursor();
}
public sync(elements: HTMLElement[]) {
this.items.splice(this.startCursor, this.endCursor + 1).forEach((item, i) => {
this.items.slice(this.startCursor, this.endCursor + 1).forEach((item, i) => {
item.el = elements[i];

@@ -208,2 +211,16 @@ item.mounted = true;

}
private refreshCursor() {
let startCursor = -1;
let endCursor = -1;
this.items.forEach((item, i) => {
if (!item.mounted) {
return;
}
(startCursor < 0) && (startCursor = i);
endCursor = i;
});
this.startCursor = startCursor;
this.endCursor = endCursor;
}
private setCursor(startCursor: number, endCursor: number) {

@@ -213,2 +230,3 @@ const container = this.container;

const renderExternal = this.options.renderExternal;
this.recycle([

@@ -240,3 +258,6 @@ { start: 0, end: startCursor - 1 },

}
this.trigger("visibleChange");
this.trigger("visibleChange", {
startCursor,
endCursor,
});
}

@@ -248,6 +269,6 @@ private recycle(ranges: Array<{ start: number, end: number }>) {

ranges.forEach(({ start, end }) => {
for (let i = start; i < end; ++i) {
for (let i = start; i <= end; ++i) {
const item = items[i];
if (!item.mounted) {
if (!item || !item.mounted) {
continue;

@@ -254,0 +275,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc