UNPKG

@base-framework/organisms

Version:

This will add default organisms to the base framework.

3 lines (2 loc) 1.12 kB
var r=(f,e,n)=>({index:f,item:e,status:n}),h=class f{static diff(e,n,l){let c=this.arrayToMap(e,l),s=[],i=[],u=n.length;for(let t=0;t<u;t++){let o=n[t],a=o[l];if(!c.has(a)){s.push(r(t,o,"added"));continue}let{item:d}=c.get(a);if(c.delete(a),!this.deepEqual(d,o)){s.push(r(t,o,"updated"));continue}s.push(r(t,o,"unchanged"))}return c.forEach(({item:t})=>{i.push(t)}),{changes:s,deletedItems:i}}static modify(e,n,l,c=!1){let s=[],i=f.arrayToMap(n,l),u=e.length;for(let t=0;t<u;t++){let o=e[t],a=o[l]??null;if(!i.has(a)){if(!c)continue;s.push(r(t,o,"added"));continue}o={...i.get(a).item,...o},s.push(r(t,o,"updated"))}return s}static arrayToMap(e,n){let l=new Map,c=e.length;for(let s=0;s<c;s++){let i=e[s];l.set(i[n],{item:i,index:s})}return l}static deepEqual(e,n,l=0){if(e===n)return!0;if(l>=32||typeof e!="object"||e===null||typeof n!="object"||n===null)return!1;let c=Object.keys(e),s=Object.keys(n);if(c.length!==s.length)return!1;let i=c.length;for(let u=0;u<i;u++){let t=c[u];if(!n.hasOwnProperty(t)||!this.deepEqual(e[t],n[t],l+1))return!1}return!0}};export{h as a}; //# sourceMappingURL=chunk-L2BWIPMB.js.map