This repository has been archived by the owner on Jan 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalue-ref.min.js
1 lines (1 loc) · 1.69 KB
/
value-ref.min.js
1
Symbol.observable||=Symbol("observable");const e=new FinalizationRegistry((e=>e.call?.())),s=(...e)=>new l(...e),r=e=>e?.map?.((e=>e[3]())),t=new FinalizationRegistry(r);class l{#e=[];#s=[];constructor(...e){this.#s=e,t.register(this,this.#e)}get value(){return this.#s[0]}set value(e){this.#s[0]=e,this.set(...this.#s)}set(...e){this.#s=e;for(let e of this.#e)e[4]?.call?.(),e[4]=e[0](...this.#s)}valueOf(){return this.value}toString(){return this.value}toJSON(){return this.value}[Symbol.toPrimitive](e){return this.value}*[Symbol.iterator](){for(let e of this.#s)yield e}subscribe(e,s,r){s=(e=e?.next||e)?.error||s,r=e?.complete||r;const t=this.#e,l=()=>(i[4]?.call?.(),t.splice(t.indexOf(i)>>>0,1)),i=[e,s,r,l,this.#s.length?e(...this.#s):null];return t.push(i),l.unsubscribe=l}error(e){this.#e.map((s=>s[1]?.(e)))}[Symbol.observable||=Symbol.for("observable")](){return this}async*[Symbol.asyncIterator](){let e,s=[],r=new Promise((s=>e=s)),t=this.subscribe((t=>(s.push(t),e(),r=new Promise((s=>e=s)))));try{for(;;)yield*s.splice(0),await r}catch{}t()}[Symbol.dispose||=Symbol("dispose")](){r(this.#e),this.#s=null,this.#e=null}}const i=l.from=s.from=(...s)=>{let r,t,i;return s[s.length-1]?.call&&(r=s.pop()),t=[],s.map(((s,l)=>{return(e=>e&&!!(e[Symbol.observable]||e[Symbol.asyncIterator]||e.call&&e.set||e.subscribe||e.then))(s)?(a=e=>(t[l]=e,i&&(r?i.value=r(...t):i.set(...t))),(o=s)&&(v=(o[Symbol.observable]?.()||o).subscribe?.(a,u,undefined),n=v&&(()=>v.unsubscribe?.())||o.set&&o.call?.(b,a)||(o.then?.((e=>{!b&&a(e)}),u)||(async e=>{try{for await(e of o){if(b)return;a(e)}}catch(e){}})())&&(e=>b=1),e.register(o,n),n)):t[l]=s;var o,a,u,b,n,v})),i=r?new l(r(...t)):new l(...t)};export{l as Ref,s as default,i as from};