UNPKG

siegel

Version:

Web application development ecosystem

1 lines 671 B
import e from"../array_range_each/index.js";export default function(t="id"){let a={},d=[],r={clear:()=>(a={},d=[],r.lastUpdated=Date.now(),r),addOrUpdate(e){let l=e[t];return a[l]||d.push(l),a[l]=e,r.lastUpdated=Date.now(),r},addAll(e,t){for(let a=0,d=e.length;a<d;a++){let d=e[a];t?.(d,a),this.addOrUpdate(d)}return r.lastUpdated=Date.now(),r},remove(e){if(a[e]){let t=d.findIndex(t=>e==t);d.splice(t,1),delete a[e]}return r.lastUpdated=Date.now(),r},sort:e=>(d.sort((t,d)=>e(a[t],a[d])),r),each:(t,l=0,n=d.length)=>(e(d,l,n,(e,d)=>t(a[e],d)),r),get:e=>a[e],len:()=>d.length,raw:()=>({byID:a,sorted:d}),setRaw:e=>(a=e.byID,d=e.sorted,r),lastUpdated:Date.now()};return r}