react-state-custom 1.0.5 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js
CHANGED
|
@@ -1041,7 +1041,7 @@ const br = (e, t) => {
|
|
|
1041
1041
|
}, _r = ({ Root: e, useCtxState: t, useCtxStateStrict: r, resolveCtxName: u }) => ({
|
|
1042
1042
|
useCtxState: (c) => {
|
|
1043
1043
|
const n = u(c), f = ar(Y("auto-ctx"), "subscribe");
|
|
1044
|
-
return L(() => f(e, c), [f, n]), Y(n);
|
|
1044
|
+
return L(() => f == null ? void 0 : f(e, c), [f, n]), Y(n);
|
|
1045
1045
|
}
|
|
1046
1046
|
}), Er = (e) => {
|
|
1047
1047
|
const [, t] = U(0), { proxy: r, finalGetter: u, openGetter: c, clean: n } = z(
|
package/dist/index.umd.js
CHANGED
|
@@ -19,4 +19,4 @@
|
|
|
19
19
|
<%s {...props} />
|
|
20
20
|
React keys must be passed directly to JSX without using spread:
|
|
21
21
|
let props = %s;
|
|
22
|
-
<%s key={someKey} {...props} />`,C,j,H,j),Ae[j+C]=!0)}if(j=null,w!==void 0&&(n(w),j=""+w),l(m)&&(n(m.key),j=""+m.key),"key"in m){w={};for(var de in m)de!=="key"&&(w[de]=m[de])}else w=m;return j&&h(w,typeof s=="function"?s.displayName||s.name||"Unknown":s),b(s,j,N,k,c(),w,fe,le)}function S(s){typeof s=="object"&&s!==null&&s.$$typeof===P&&s._store&&(s._store.validated=1)}var O=v,P=Symbol.for("react.transitional.element"),x=Symbol.for("react.portal"),y=Symbol.for("react.fragment"),R=Symbol.for("react.strict_mode"),A=Symbol.for("react.profiler"),U=Symbol.for("react.consumer"),V=Symbol.for("react.context"),i=Symbol.for("react.forward_ref"),a=Symbol.for("react.suspense"),o=Symbol.for("react.suspense_list"),f=Symbol.for("react.memo"),d=Symbol.for("react.lazy"),E=Symbol.for("react.activity"),g=Symbol.for("react.client.reference"),L=O.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,M=Object.prototype.hasOwnProperty,oe=Array.isArray,Q=console.createTask?console.createTask:function(){return null};O={"react-stack-bottom-frame":function(s){return s()}};var je,Le={},Pe=O["react-stack-bottom-frame"].bind(O,r)(),Ne=Q(u(r)),Ae={};B.Fragment=y,B.jsx=function(s,m,w,C,k){var N=1e4>L.recentlyCreatedOwnerStacks++;return _(s,m,w,!1,C,k,N?Error("react-stack-top-frame"):Pe,N?Q(u(s)):Ne)},B.jsxs=function(s,m,w,C,k){var N=1e4>L.recentlyCreatedOwnerStacks++;return _(s,m,w,!0,C,k,N?Error("react-stack-top-frame"):Pe,N?Q(u(s)):Ne)}}()),B}var Ce;function an(){return Ce||(Ce=1,process.env.NODE_ENV==="production"?re.exports=rn():re.exports=on()),re.exports}var G=an();const sn=(e,t)=>{const n=c=>[e,...Object.entries(c??{}).sort((r,l)=>r[0].localeCompare(l[0])).flat()].join("-");let u=new Set;return{resolveCtxName:n,Root:c=>{const r=n(c),l=F(r),h=t(c),p=v.useMemo(()=>new Error().stack,[]);return ce(l,...Object.entries(h)),v.useEffect(()=>{if(u.has(r)){const b=new Error("RootContext "+r+" are mounted more than once");throw b.stack=p,b}return u.add(r),()=>{u.delete(r)}}),G.jsx(G.Fragment,{})},useCtxStateStrict:c=>{const r=n(c),l=v.useMemo(()=>new Error().stack,[]);return v.useEffect(()=>{if(!u.has(r)){const h=new Error("RootContext ["+r+"] is not mounted");throw h.stack=l,h}},[r]),F(r)},useCtxState:c=>{const r=n(c),l=v.useMemo(()=>new Error().stack,[]);return v.useEffect(()=>{if(!u.has(r)){const h=new Error("RootContext ["+r+"] is not mounted");h.stack=l;let p=setTimeout(()=>console.error(h),1e3);return()=>clearTimeout(p)}},[u.has(r)]),F(r)}}},un=function(){const e=new WeakMap;return t=>{let n=e.get(t);return n||e.set(t,n=((t==null?void 0:t.name)??"")+Math.random().toString()),n}}(),cn=e=>[...Object.entries(e??{}).sort((t,n)=>t[0].localeCompare(n[0])).flat()].join("-"),fn=({Wrapper:e=v.Fragment})=>{const t=F("auto-ctx"),[n,u]=v.useState({}),c=v.useCallback((r,l)=>{const h=un(r),p=cn(l);return u(({[h]:{Component:b=r,subState:{[p]:_={params:l,counter:0},...S}={}}={},...O})=>({...O,[h]:{Component:b,subState:{...S,[p]:{..._,counter:_.counter+1}}}})),()=>u(({[h]:{Component:b=r,subState:{[p]:_={params:l,counter:0},...S}={}}={},...O})=>({...O,[h]:{Component:b,subState:{...S,..._.counter>1?{[p]:{..._,counter:_.counter-1}}:{}}}}))},[]);return ce(t,["subscribe",c],["state",n]),G.jsx(G.Fragment,{children:Object.entries(n).flatMap(([r,{Component:l,subState:h}])=>Object.entries(h).map(([p,{counter:b,params:_}])=>({key:r+p,Component:l,params:_,counter:b})).filter(p=>p.counter>0).map(({key:p,params:b,Component:_})=>G.jsx(e,{children:G.jsx(_,{...b})},p)))})},ln=({Root:e,useCtxState:t,useCtxStateStrict:n,resolveCtxName:u})=>({useCtxState:c=>{const r=u(c),l=we(F("auto-ctx"),"subscribe");return v.useEffect(()=>l(e,c),[l,r]),F(r)}}),dn=e=>{const[,t]=v.useState(0),{proxy:n,finalGetter:u,openGetter:c,clean:r}=v.useMemo(()=>{const l=new Set,h={},p=new Map,b=new Proxy(e==null?void 0:e.data,{get(y,R){if(_)return l.add(R),h[R]=y[R];throw new Error("now allow here")}});let _=!0,S=ne(()=>{[...l.values()].some(y=>{var R;return h[y]!=((R=e==null?void 0:e.data)==null?void 0:R[y])})&&t(y=>y+1)},0),O=()=>{_=!0,l.clear()},P=()=>{_=!1,[...l.values()].filter(y=>!p.has(y)).forEach(y=>{p.set(y,e==null?void 0:e.subscribe(y,S))}),[...p.keys()].filter(y=>!l.has(y)).forEach(y=>{let R=p.get(y);R==null||R(),p.delete(y)})};return{proxy:b,finalGetter:P,openGetter:O,clean:()=>{O(),P(),t(y=>y+1)}}},[e]);return c(),setTimeout(u,0),v.useEffect(()=>()=>r(),[r]),n};T.AutoRootCtx=fn,T.Context=ye,T.createAutoCtx=ln,T.createRootCtx=sn,T.getContext=Te,T.useDataContext=F,T.useDataSource=qt,T.useDataSourceMultiple=ce,T.useDataSubscribe=we,T.useDataSubscribeMultiple=tn,T.useDataSubscribeMultipleWithDebounce=nn,T.useDataSubscribeWithTransform=en,T.useQuickSubscribe=dn,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"})});
|
|
22
|
+
<%s key={someKey} {...props} />`,C,j,H,j),Ae[j+C]=!0)}if(j=null,w!==void 0&&(n(w),j=""+w),l(m)&&(n(m.key),j=""+m.key),"key"in m){w={};for(var de in m)de!=="key"&&(w[de]=m[de])}else w=m;return j&&h(w,typeof s=="function"?s.displayName||s.name||"Unknown":s),b(s,j,N,k,c(),w,fe,le)}function S(s){typeof s=="object"&&s!==null&&s.$$typeof===P&&s._store&&(s._store.validated=1)}var O=v,P=Symbol.for("react.transitional.element"),x=Symbol.for("react.portal"),y=Symbol.for("react.fragment"),R=Symbol.for("react.strict_mode"),A=Symbol.for("react.profiler"),U=Symbol.for("react.consumer"),V=Symbol.for("react.context"),i=Symbol.for("react.forward_ref"),a=Symbol.for("react.suspense"),o=Symbol.for("react.suspense_list"),f=Symbol.for("react.memo"),d=Symbol.for("react.lazy"),E=Symbol.for("react.activity"),g=Symbol.for("react.client.reference"),L=O.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,M=Object.prototype.hasOwnProperty,oe=Array.isArray,Q=console.createTask?console.createTask:function(){return null};O={"react-stack-bottom-frame":function(s){return s()}};var je,Le={},Pe=O["react-stack-bottom-frame"].bind(O,r)(),Ne=Q(u(r)),Ae={};B.Fragment=y,B.jsx=function(s,m,w,C,k){var N=1e4>L.recentlyCreatedOwnerStacks++;return _(s,m,w,!1,C,k,N?Error("react-stack-top-frame"):Pe,N?Q(u(s)):Ne)},B.jsxs=function(s,m,w,C,k){var N=1e4>L.recentlyCreatedOwnerStacks++;return _(s,m,w,!0,C,k,N?Error("react-stack-top-frame"):Pe,N?Q(u(s)):Ne)}}()),B}var Ce;function an(){return Ce||(Ce=1,process.env.NODE_ENV==="production"?re.exports=rn():re.exports=on()),re.exports}var G=an();const sn=(e,t)=>{const n=c=>[e,...Object.entries(c??{}).sort((r,l)=>r[0].localeCompare(l[0])).flat()].join("-");let u=new Set;return{resolveCtxName:n,Root:c=>{const r=n(c),l=F(r),h=t(c),p=v.useMemo(()=>new Error().stack,[]);return ce(l,...Object.entries(h)),v.useEffect(()=>{if(u.has(r)){const b=new Error("RootContext "+r+" are mounted more than once");throw b.stack=p,b}return u.add(r),()=>{u.delete(r)}}),G.jsx(G.Fragment,{})},useCtxStateStrict:c=>{const r=n(c),l=v.useMemo(()=>new Error().stack,[]);return v.useEffect(()=>{if(!u.has(r)){const h=new Error("RootContext ["+r+"] is not mounted");throw h.stack=l,h}},[r]),F(r)},useCtxState:c=>{const r=n(c),l=v.useMemo(()=>new Error().stack,[]);return v.useEffect(()=>{if(!u.has(r)){const h=new Error("RootContext ["+r+"] is not mounted");h.stack=l;let p=setTimeout(()=>console.error(h),1e3);return()=>clearTimeout(p)}},[u.has(r)]),F(r)}}},un=function(){const e=new WeakMap;return t=>{let n=e.get(t);return n||e.set(t,n=((t==null?void 0:t.name)??"")+Math.random().toString()),n}}(),cn=e=>[...Object.entries(e??{}).sort((t,n)=>t[0].localeCompare(n[0])).flat()].join("-"),fn=({Wrapper:e=v.Fragment})=>{const t=F("auto-ctx"),[n,u]=v.useState({}),c=v.useCallback((r,l)=>{const h=un(r),p=cn(l);return u(({[h]:{Component:b=r,subState:{[p]:_={params:l,counter:0},...S}={}}={},...O})=>({...O,[h]:{Component:b,subState:{...S,[p]:{..._,counter:_.counter+1}}}})),()=>u(({[h]:{Component:b=r,subState:{[p]:_={params:l,counter:0},...S}={}}={},...O})=>({...O,[h]:{Component:b,subState:{...S,..._.counter>1?{[p]:{..._,counter:_.counter-1}}:{}}}}))},[]);return ce(t,["subscribe",c],["state",n]),G.jsx(G.Fragment,{children:Object.entries(n).flatMap(([r,{Component:l,subState:h}])=>Object.entries(h).map(([p,{counter:b,params:_}])=>({key:r+p,Component:l,params:_,counter:b})).filter(p=>p.counter>0).map(({key:p,params:b,Component:_})=>G.jsx(e,{children:G.jsx(_,{...b})},p)))})},ln=({Root:e,useCtxState:t,useCtxStateStrict:n,resolveCtxName:u})=>({useCtxState:c=>{const r=u(c),l=we(F("auto-ctx"),"subscribe");return v.useEffect(()=>l==null?void 0:l(e,c),[l,r]),F(r)}}),dn=e=>{const[,t]=v.useState(0),{proxy:n,finalGetter:u,openGetter:c,clean:r}=v.useMemo(()=>{const l=new Set,h={},p=new Map,b=new Proxy(e==null?void 0:e.data,{get(y,R){if(_)return l.add(R),h[R]=y[R];throw new Error("now allow here")}});let _=!0,S=ne(()=>{[...l.values()].some(y=>{var R;return h[y]!=((R=e==null?void 0:e.data)==null?void 0:R[y])})&&t(y=>y+1)},0),O=()=>{_=!0,l.clear()},P=()=>{_=!1,[...l.values()].filter(y=>!p.has(y)).forEach(y=>{p.set(y,e==null?void 0:e.subscribe(y,S))}),[...p.keys()].filter(y=>!l.has(y)).forEach(y=>{let R=p.get(y);R==null||R(),p.delete(y)})};return{proxy:b,finalGetter:P,openGetter:O,clean:()=>{O(),P(),t(y=>y+1)}}},[e]);return c(),setTimeout(u,0),v.useEffect(()=>()=>r(),[r]),n};T.AutoRootCtx=fn,T.Context=ye,T.createAutoCtx=ln,T.createRootCtx=sn,T.getContext=Te,T.useDataContext=F,T.useDataSource=qt,T.useDataSourceMultiple=ce,T.useDataSubscribe=we,T.useDataSubscribeMultiple=tn,T.useDataSubscribeMultipleWithDebounce=nn,T.useDataSubscribeWithTransform=en,T.useQuickSubscribe=dn,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -125,7 +125,7 @@ export const createAutoCtx = <U extends object, V extends object,>({ Root, useCt
|
|
|
125
125
|
const subscribe = useDataSubscribe(useDataContext<any>("auto-ctx"), "subscribe")
|
|
126
126
|
|
|
127
127
|
useEffect(() => {
|
|
128
|
-
return subscribe(Root, e)
|
|
128
|
+
return subscribe?.(Root, e)
|
|
129
129
|
}, [subscribe, ctxName])
|
|
130
130
|
|
|
131
131
|
return useDataContext<V>(ctxName)
|