UNPKG

r18gs

Version:

A simple yet elegant, light weight, react18 global store to replace Zustand for better tree shaking.

2 lines (1 loc) 1.78 kB
"use strict";var u=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var P=Object.prototype.hasOwnProperty;var y=(t,e)=>{for(var n in e)u(t,n,{get:e[n],enumerable:!0})},A=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of d(e))!P.call(t,s)&&s!==n&&u(t,s,{get:()=>e[s],enumerable:!(i=R(e,s))||i.enumerable});return t};var E=t=>A(u({},"__esModule",{value:!0}),t);var f=(t,e,n)=>new Promise((i,s)=>{var o=a=>{try{l(n.next(a))}catch(c){s(c)}},r=a=>{try{l(n.throw(a))}catch(c){s(c)}},l=a=>a.done?i(a.value):Promise.resolve(a.value).then(o,r);l((n=n.apply(t,e)).next())});var L={};y(L,{create:()=>U,useRGSWithPlugins:()=>g,withPlugins:()=>b});module.exports=E(L);var x=require("react");var p=globalThis;p.rgs||(p.rgs={});var T=p.rgs,h=(t,e,n)=>{let i=[];for(let s of[e,n])for(let o in s)e[o]!==n[o]&&i.push(o);t.l.forEach(({l:s,s:[o,r]})=>(!(n instanceof Object)||i.filter(l=>(!o||o.test(l))&&(!r||!r.test(l))).length)&&s())},W=(t,e,n)=>{let i=T[t],s=()=>i.v;return[(0,x.useSyncExternalStore)(r=>{let l={l:r,s:[e,n]};return i.l.push(l),()=>{i.l=i.l.filter(a=>a!==l)}},s,s),i.s]},v=!1,m=(t,e)=>f(void 0,null,function*(){var s;let n=T[t],i=o=>{let r=n.v;n.v=o,h(n,r,o)};for(let o of e)yield(s=o.init)==null?void 0:s.call(o,t,n.v,i);v=!0}),G=(t,e,n=[],i=!1)=>{if(e=e instanceof Function?e():e,i){T[t]={v:e,l:[],s:null};return}let s=r=>{if(!v)return;let l=T[t],a=l.v;l.v=r instanceof Function?r(a):r,h(l,a,l.v),n.forEach(c=>{var S;return(S=c.onChange)==null?void 0:S.call(c,t,l.v)})},o=T[t];o?(o.v=e,o.s=s):T[t]={v:e,l:[],s},m(t,n)},g=(t,e,n,i=!1,s,o)=>{var r;return(r=T[t])!=null&&r.s||G(t,e,n,i),W(t,s,o)};var U=(t,e,n)=>()=>g(t,e,n),b=t=>(n,i,s=!1)=>g(n,i,t,s);0&&(module.exports={create,useRGSWithPlugins,withPlugins});