UNPKG

3.52 kBJavaScriptView Raw
1/*
2Copyright (c) 2019-present NAVER Corp.
3name: @egjs/children-differ
4license: MIT
5author: NAVER Corp.
6repository: https://github.com/naver/egjs-children-differ
7version: 1.0.1
8*/
9!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):((t=t||self).eg=t.eg||{},t.eg.ChildrenDiffer=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 _=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}(),b=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}(),x="function"==typeof Map,i=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 O=function(){function t(t,e,n,r,i,o,c,u){this.prevList=t,this.list=e,this.added=n,this.removed=r,this.changed=i,this.maintained=o,this.changedBeforeAdded=c,this.fixed=u}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 u=[],f=[];return t.forEach(function(t){var e=t[0],n=t[1],r=new i;u[e]=r,f[n]=r}),u.forEach(function(t,e){t.connect(u[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=u[n],o=f[r-1],c=i.getIndex();return i.disconnect(),o?i.connect(o,o.next):i.connect(void 0,u[0]),[c,i.getIndex()]})}(this.changedBeforeAdded,this.fixed),u=this.changed,f=[];this.cacheOrdered=t.filter(function(t,e){var n=t[0],r=t[1],i=u[e],o=i[0],c=i[1];if(n!==r)return f.push([o,c]),!0}),this.cachePureChanged=f},t}();function o(t,e,n){var r=x?Map:n?b:_,i=n||function(t){return t},o=[],c=[],u=[],f=t.map(i),s=e.map(i),a=new r,h=new r,d=[],p=[],v={},l=[],g=0,y=0;return f.forEach(function(t,e){a.set(t,e)}),s.forEach(function(t,e){h.set(t,e)}),f.forEach(function(t,e){var n=h.get(t);void 0===n?(++y,c.push(e)):v[n]=y}),s.forEach(function(t,e){var n=a.get(t);void 0===n?(o.push(e),++g):(u.push([n,e]),y=v[e]||0,d.push([n-y,e-g]),p.push(e===n),n!==e&&l.push([n,e]))}),c.reverse(),new O(t,e,o,c,l,u,d,p)}var e,n="function"==typeof Map?void 0:(e=0,function(t){return t.__DIFF_KEY__||(t.__DIFF_KEY__=++e)}),t=function(e){function t(t){return void 0===t&&(t=[]),e.call(this,t,n)||this}return 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,e),t}(function(){function t(t,e){void 0===t&&(t=[]),this.findKeyCallback=e,this.list=[].slice.call(t)}return t.prototype.update=function(t){var e=[].slice.call(t),n=o(this.list,e,this.findKeyCallback);return this.list=e,n},t}());return t.diff=function(t,e){return o(t,e,n)},t});
10//# sourceMappingURL=children-differ.pkgd.min.js.map