jotai
Version:
👻 Next gen state management that will spook you
2 lines (1 loc) • 796 B
JavaScript
System.register(["optics-ts","jotai"],function(a){"use strict";var i,m;return{setters:[function(s){i=s},function(s){m=s.atom}],execute:function(){a("focusAtom",v);const s=(t,e)=>{do{const[r,...o]=e,n=t.get(r);if(!n)return;if(!o.length)return n[1];t=n[0],e=o}while(e.length)},f=(t,e,r)=>{do{const[o,...n]=e;let c=t.get(o);if(c||(c=[new WeakMap],t.set(o,c)),!n.length){c[1]=r;return}t=c[0],e=n}while(e.length)},l=(()=>{const t=new WeakMap;return(r,o)=>{const n=s(t,o);if(n)return n;const c=r();return f(t,o,c),c}})(),g=t=>typeof t=="function";function v(t,e){return l(()=>{const r=e(i.optic());return m(n=>A(r,n(t)),(n,c,u)=>{const h=g(u)?i.modify(r)(u):i.set(r)(u);return c(t,h(n(t)))})},[t,e])}const A=(t,e)=>t._tag==="Traversal"?i.collect(t)(e):t._tag==="Prism"?i.preview(t)(e):i.get(t)(e)}}});