Comparing version 1.0.1 to 1.0.2
@@ -18,2 +18,3 @@ import type { SetStateAction } from "./utils"; | ||
*/ | ||
export default function useRGS<T>(key: string, value?: T): [T, SetStateAction<T>]; | ||
declare const useRGS: <T>(key: string, value?: T) => [T, SetStateAction<T>]; | ||
export default useRGS; |
@@ -1,1 +0,1 @@ | ||
"use strict";var s=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var b=(e,t)=>{for(var n in t)s(e,n,{get:t[n],enumerable:!0})},d=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of l(t))!p.call(e,o)&&o!==n&&s(e,o,{get:()=>t[o],enumerable:!(r=f(t,o))||r.enumerable});return e};var x=e=>d(s({},"__esModule",{value:!0}),e);var A={};b(A,{default:()=>g});module.exports=x(A);var a=require("react");var c=globalThis;c.rgs={};var i=c.rgs;function u(e){return t=>{let n=i[e];return n[1].push(t),()=>{n[1]=n[1].filter(r=>r!==t)}}}function S(e){return t=>{let n=i[e];n[0]=t instanceof Function?t(n[0]):t,n[1].forEach(r=>r())}}function T(e){let t=i[e];return[(0,a.useSyncExternalStore)(t[3],()=>t[0],()=>t[0]),t[2]]}function g(e,t){return i[e]||(i[e]=[t,[],S(e),u(e)]),T(e)} | ||
"use strict";var i=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var p=(e,t)=>{for(var r in t)i(e,r,{get:t[r],enumerable:!0})},b=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of l(t))!f.call(e,o)&&o!==r&&i(e,o,{get:()=>t[o],enumerable:!(n=g(t,o))||n.enumerable});return e};var d=e=>b(i({},"__esModule",{value:!0}),e);var R={};p(R,{default:()=>A});module.exports=d(R);var a=require("react");var c=globalThis;c.rgs={};var s=c.rgs;var S=e=>t=>{let r=s[e];return r[1].push(t),()=>{r[1]=r[1].filter(n=>n!==t)}},T=e=>t=>{let r=s[e];r[0]=t instanceof Function?t(r[0]):t,r[1].forEach(n=>n())},u=e=>{let t=s[e],r=()=>t[0];return[(0,a.useSyncExternalStore)(t[3],r,r),t[2]]};var x=(e,t)=>(s[e]||(s[e]=[t,[],T(e),S(e)]),u(e)),A=x; |
@@ -1,1 +0,1 @@ | ||
"use strict";var a=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var d=(t,e)=>{for(var s in e)a(t,s,{get:e[s],enumerable:!0})},m=(t,e,s,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of u(e))!l.call(t,n)&&n!==s&&a(t,n,{get:()=>e[n],enumerable:!(r=g(e,n))||r.enumerable});return t};var S=t=>m(a({},"__esModule",{value:!0}),t);var P={};d(P,{persist:()=>O});module.exports=S(P);function w(t,e){let s=document.cookie.split("; ").find(r=>r.startsWith(t));switch(e==null?void 0:e.storage){case"cookie":return s==null?void 0:s.split("=")[1];case"session":return sessionStorage.getItem(t);default:return localStorage.getItem(t)}}function I(t,e,s){var r;switch(s==null?void 0:s.storage){case"cookie":document.cookie=`${t}=${e}; max-age=31536000; SameSite=Strict;`,((r=s.sync)==null||r)&&sessionStorage.setItem(t,e);return;case"session":sessionStorage.setItem(t,e);return;default:localStorage.setItem(t,e)}}function O(t){return{init(e,s,r){var f;if(typeof window=="undefined")return;let n=w(e,t),c=JSON.parse(n||"{}").val;c&&r(c),((f=t==null?void 0:t.sync)==null||f)&&addEventListener("storage",i=>{if(i.key===e&&i.newValue){let o=JSON.parse(i.newValue).val;o!==void 0&&r(o)}})},onChange(e,s){typeof window!="undefined"&&I(e,JSON.stringify({val:s}),t)}}}0&&(module.exports={persist}); | ||
"use strict";var a=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var d=(t,e)=>{for(var s in e)a(t,s,{get:e[s],enumerable:!0})},m=(t,e,s,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of l(e))!u.call(t,n)&&n!==s&&a(t,n,{get:()=>e[n],enumerable:!(r=f(e,n))||r.enumerable});return t};var S=t=>m(a({},"__esModule",{value:!0}),t);var P={};d(P,{persist:()=>O});module.exports=S(P);var w=(t,e)=>{let s=document.cookie.split("; ").find(r=>r.startsWith(t));switch(e==null?void 0:e.storage){case"cookie":return s==null?void 0:s.split("=")[1];case"session":return sessionStorage.getItem(t);default:return localStorage.getItem(t)}},I=(t,e,s)=>{var r;switch(s==null?void 0:s.storage){case"cookie":document.cookie=`${t}=${e}; max-age=31536000; SameSite=Strict;`,((r=s.sync)==null||r)&&sessionStorage.setItem(t,e);return;case"session":sessionStorage.setItem(t,e);return;default:localStorage.setItem(t,e)}},O=t=>({init(e,s,r){var o;if(typeof window=="undefined")return;let n=w(e,t),c=JSON.parse(n||"{}").val;c&&r(c),((o=t==null?void 0:t.sync)==null||o)&&addEventListener("storage",i=>{if(i.key===e&&i.newValue){let g=JSON.parse(i.newValue).val;g!==void 0&&r(g)}})},onChange(e,s){typeof window!="undefined"&&I(e,JSON.stringify({val:s}),t)}});0&&(module.exports={persist}); |
@@ -13,2 +13,2 @@ import { Plugin } from ".."; | ||
*/ | ||
export declare function persist<T>(options?: PersistOptions): Plugin<T>; | ||
export declare const persist: <T>(options?: PersistOptions) => Plugin<T>; |
@@ -1,1 +0,1 @@ | ||
"use strict";var a=Object.defineProperty;var o=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var d=(t,e)=>{for(var s in e)a(t,s,{get:e[s],enumerable:!0})},m=(t,e,s,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of u(e))!l.call(t,n)&&n!==s&&a(t,n,{get:()=>e[n],enumerable:!(r=o(e,n))||r.enumerable});return t};var S=t=>m(a({},"__esModule",{value:!0}),t);var P={};d(P,{persist:()=>O});module.exports=S(P);function w(t,e){let s=document.cookie.split("; ").find(r=>r.startsWith(t));switch(e==null?void 0:e.storage){case"cookie":return s==null?void 0:s.split("=")[1];case"session":return sessionStorage.getItem(t);default:return localStorage.getItem(t)}}function I(t,e,s){var r;switch(s==null?void 0:s.storage){case"cookie":document.cookie=`${t}=${e}; max-age=31536000; SameSite=Strict;`,((r=s.sync)==null||r)&&sessionStorage.setItem(t,e);return;case"session":sessionStorage.setItem(t,e);return;default:localStorage.setItem(t,e)}}function O(t){return{init(e,s,r){var f;if(typeof window=="undefined")return;let n=w(e,t),c=JSON.parse(n||"{}").val;c&&r(c),((f=t==null?void 0:t.sync)==null||f)&&addEventListener("storage",i=>{if(i.key===e&&i.newValue){let g=JSON.parse(i.newValue).val;g!==void 0&&r(g)}})},onChange(e,s){typeof window!="undefined"&&I(e,JSON.stringify({val:s}),t)}}}0&&(module.exports={persist}); | ||
"use strict";var a=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var d=(t,e)=>{for(var s in e)a(t,s,{get:e[s],enumerable:!0})},m=(t,e,s,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of l(e))!u.call(t,n)&&n!==s&&a(t,n,{get:()=>e[n],enumerable:!(r=f(e,n))||r.enumerable});return t};var S=t=>m(a({},"__esModule",{value:!0}),t);var P={};d(P,{persist:()=>O});module.exports=S(P);var w=(t,e)=>{let s=document.cookie.split("; ").find(r=>r.startsWith(t));switch(e==null?void 0:e.storage){case"cookie":return s==null?void 0:s.split("=")[1];case"session":return sessionStorage.getItem(t);default:return localStorage.getItem(t)}},I=(t,e,s)=>{var r;switch(s==null?void 0:s.storage){case"cookie":document.cookie=`${t}=${e}; max-age=31536000; SameSite=Strict;`,((r=s.sync)==null||r)&&sessionStorage.setItem(t,e);return;case"session":sessionStorage.setItem(t,e);return;default:localStorage.setItem(t,e)}},O=t=>({init(e,s,r){var g;if(typeof window=="undefined")return;let n=w(e,t),c=JSON.parse(n||"{}").val;c&&r(c),((g=t==null?void 0:t.sync)==null||g)&&addEventListener("storage",i=>{if(i.key===e&&i.newValue){let o=JSON.parse(i.newValue).val;o!==void 0&&r(o)}})},onChange(e,s){typeof window!="undefined"&&I(e,JSON.stringify({val:s}),t)}});0&&(module.exports={persist}); |
@@ -11,7 +11,7 @@ type Listener = () => void; | ||
/** craete subscriber function to subscribe to the store. */ | ||
export declare function createSubcriber(key: string): Subscriber; | ||
export declare const createSubcriber: (key: string) => Subscriber; | ||
/** setter function to set the state. */ | ||
export declare function createSetter<T>(key: string): SetStateAction<unknown>; | ||
export declare const createSetter: <T>(key: string) => SetStateAction<unknown>; | ||
/** Extract coomon create hook logic to utils */ | ||
export declare function createHook<T>(key: string): [T, SetStateAction<T>]; | ||
export declare const createHook: <T>(key: string) => [T, SetStateAction<T>]; | ||
type Mutate<T> = (value?: T) => void; | ||
@@ -23,3 +23,3 @@ export type Plugin<T> = { | ||
/** Initialize the named store when invoked for the first time. */ | ||
export declare function initWithPlugins<T>(key: string, value?: T, plugins?: Plugin<T>[], doNotInit?: boolean): void; | ||
export declare const initWithPlugins: <T>(key: string, value?: T, plugins?: Plugin<T>[], doNotInit?: boolean) => void; | ||
/** | ||
@@ -42,3 +42,3 @@ * Use this hook similar to `useState` hook. | ||
*/ | ||
export declare function useRGSWithPlugins<T>(key: string, value?: T, plugins?: Plugin<T>[], doNotInit?: boolean): [T, SetStateAction<T>]; | ||
export declare const useRGSWithPlugins: <T>(key: string, value?: T, plugins?: Plugin<T>[], doNotInit?: boolean) => [T, SetStateAction<T>]; | ||
export {}; |
@@ -1,1 +0,1 @@ | ||
"use strict";var S=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var G=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var v=(t,e)=>{for(var n in e)S(t,n,{get:e[n],enumerable:!0})},L=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of G(e))!A.call(t,r)&&r!==n&&S(t,r,{get:()=>e[r],enumerable:!(i=R(e,r))||i.enumerable});return t};var P=t=>L(S({},"__esModule",{value:!0}),t);var f=(t,e,n)=>new Promise((i,r)=>{var s=o=>{try{c(n.next(o))}catch(u){r(u)}},T=o=>{try{c(n.throw(o))}catch(u){r(u)}},c=o=>o.done?i(o.value):Promise.resolve(o.value).then(s,T);c((n=n.apply(t,e)).next())});var M={};v(M,{createHook:()=>d,createSetter:()=>w,createSubcriber:()=>g,globalRGS:()=>a,initWithPlugins:()=>x,useRGSWithPlugins:()=>m});module.exports=P(M);var l=require("react");var p=globalThis;p.rgs={};var a=p.rgs;function b(t){t[1].forEach(e=>e())}function g(t){return e=>{let n=a[t];return n[1].push(e),()=>{n[1]=n[1].filter(i=>i!==e)}}}function w(t){return e=>{let n=a[t];n[0]=e instanceof Function?e(n[0]):e,n[1].forEach(i=>i())}}function d(t){let e=a[t];return[(0,l.useSyncExternalStore)(e[3],()=>e[0],()=>e[0]),e[2]]}var h=!1;function E(t,e){return f(this,null,function*(){var r;let n=a[t],i=s=>{n[0]=s,b(n)};for(let s of e)yield(r=s.init)==null?void 0:r.call(s,t,n[0],i);h=!0})}function x(t,e,n=[],i=!1){if(i){a[t]=[e,[],null,g(t)];return}let r=T=>{if(!h)return;let c=a[t];c[0]=T instanceof Function?T(c[0]):T,b(c),n.forEach(o=>{var u;return(u=o.onChange)==null?void 0:u.call(o,t,c[0])})},s=a[t];s?(s[0]=e,s[2]=r):a[t]=[e,[],r,g(t)],E(t,n)}function m(t,e,n,i=!1){var r;return(r=a[t])!=null&&r[2]||x(t,e,n,i),d(t)}0&&(module.exports={createHook,createSetter,createSubcriber,globalRGS,initWithPlugins,useRGSWithPlugins}); | ||
"use strict";var u=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var G=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var v=(t,e)=>{for(var n in e)u(t,n,{get:e[n],enumerable:!0})},L=(t,e,n,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of G(e))!A.call(t,r)&&r!==n&&u(t,r,{get:()=>e[r],enumerable:!(s=R(e,r))||s.enumerable});return t};var P=t=>L(u({},"__esModule",{value:!0}),t);var l=(t,e,n)=>new Promise((s,r)=>{var i=o=>{try{c(n.next(o))}catch(T){r(T)}},S=o=>{try{c(n.throw(o))}catch(T){r(T)}},c=o=>o.done?s(o.value):Promise.resolve(o.value).then(i,S);c((n=n.apply(t,e)).next())});var M={};v(M,{createHook:()=>d,createSetter:()=>w,createSubcriber:()=>g,globalRGS:()=>a,initWithPlugins:()=>x,useRGSWithPlugins:()=>m});module.exports=P(M);var f=require("react");var p=globalThis;p.rgs={};var a=p.rgs,b=t=>t[1].forEach(e=>e()),g=t=>e=>{let n=a[t];return n[1].push(e),()=>{n[1]=n[1].filter(s=>s!==e)}},w=t=>e=>{let n=a[t];n[0]=e instanceof Function?e(n[0]):e,n[1].forEach(s=>s())},d=t=>{let e=a[t],n=()=>e[0];return[(0,f.useSyncExternalStore)(e[3],n,n),e[2]]},h=!1,E=(t,e)=>l(void 0,null,function*(){var r;let n=a[t],s=i=>{n[0]=i,b(n)};for(let i of e)yield(r=i.init)==null?void 0:r.call(i,t,n[0],s);h=!0}),x=(t,e,n=[],s=!1)=>{if(s){a[t]=[e,[],null,g(t)];return}let r=S=>{if(!h)return;let c=a[t];c[0]=S instanceof Function?S(c[0]):S,b(c),n.forEach(o=>{var T;return(T=o.onChange)==null?void 0:T.call(o,t,c[0])})},i=a[t];i?(i[0]=e,i[2]=r):a[t]=[e,[],r,g(t)],E(t,n)},m=(t,e,n,s=!1)=>{var r;return(r=a[t])!=null&&r[2]||x(t,e,n,s),d(t)};0&&(module.exports={createHook,createSetter,createSubcriber,globalRGS,initWithPlugins,useRGSWithPlugins}); |
@@ -20,3 +20,3 @@ import { useRGSWithPlugins } from "./utils"; | ||
*/ | ||
export declare function create<T>(key: string, value?: T, plugins?: Plugin<T>[]): () => [T, SetStateAction<T>]; | ||
export declare const create: <T>(key: string, value?: T, plugins?: Plugin<T>[]) => (() => [T, SetStateAction<T>]); | ||
/** | ||
@@ -28,3 +28,3 @@ * Creates a hook similar to useRGS, but with plugins to be applied on first invocation. | ||
*/ | ||
export declare function withPlugins<T>(plugins: Plugin<T>[]): <U = T>(key: string, value?: U, doNotInit?: boolean) => [U, SetStateAction<U>]; | ||
export declare const withPlugins: <T>(plugins: Plugin<T>[]) => <U = T>(key: string, value?: U | undefined, doNotInit?: boolean) => [U, SetStateAction<U>]; | ||
export { useRGSWithPlugins }; |
@@ -1,1 +0,1 @@ | ||
"use strict";var g=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var R=(t,n)=>{for(var e in n)g(t,e,{get:n[e],enumerable:!0})},G=(t,n,e,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of x(n))!A.call(t,i)&&i!==e&&g(t,i,{get:()=>n[i],enumerable:!(r=d(n,i))||r.enumerable});return t};var v=t=>G(g({},"__esModule",{value:!0}),t);var l=(t,n,e)=>new Promise((r,i)=>{var o=s=>{try{a(e.next(s))}catch(c){i(c)}},T=s=>{try{a(e.throw(s))}catch(c){i(c)}},a=s=>s.done?r(s.value):Promise.resolve(s.value).then(o,T);a((e=e.apply(t,n)).next())});var y={};R(y,{create:()=>w,useRGSWithPlugins:()=>S,withPlugins:()=>W});module.exports=v(y);var p=require("react");var h=globalThis;h.rgs={};var u=h.rgs;function P(t){t[1].forEach(n=>n())}function f(t){return n=>{let e=u[t];return e[1].push(n),()=>{e[1]=e[1].filter(r=>r!==n)}}}function U(t){let n=u[t];return[(0,p.useSyncExternalStore)(n[3],()=>n[0],()=>n[0]),n[2]]}var b=!1;function m(t,n){return l(this,null,function*(){var i;let e=u[t],r=o=>{e[0]=o,P(e)};for(let o of n)yield(i=o.init)==null?void 0:i.call(o,t,e[0],r);b=!0})}function L(t,n,e=[],r=!1){if(r){u[t]=[n,[],null,f(t)];return}let i=T=>{if(!b)return;let a=u[t];a[0]=T instanceof Function?T(a[0]):T,P(a),e.forEach(s=>{var c;return(c=s.onChange)==null?void 0:c.call(s,t,a[0])})},o=u[t];o?(o[0]=n,o[2]=i):u[t]=[n,[],i,f(t)],m(t,e)}function S(t,n,e,r=!1){var i;return(i=u[t])!=null&&i[2]||L(t,n,e,r),U(t)}function w(t,n,e){return()=>S(t,n,e)}function W(t){return(e,r,i=!1)=>S(e,r,t,i)}0&&(module.exports={create,useRGSWithPlugins,withPlugins}); | ||
"use strict";var g=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var R=(t,e)=>{for(var n in e)g(t,n,{get:e[n],enumerable:!0})},G=(t,e,n,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of x(e))!A.call(t,r)&&r!==n&&g(t,r,{get:()=>e[r],enumerable:!(s=d(e,r))||s.enumerable});return t};var v=t=>G(g({},"__esModule",{value:!0}),t);var l=(t,e,n)=>new Promise((s,r)=>{var i=o=>{try{a(n.next(o))}catch(u){r(u)}},T=o=>{try{a(n.throw(o))}catch(u){r(u)}},a=o=>o.done?s(o.value):Promise.resolve(o.value).then(i,T);a((n=n.apply(t,e)).next())});var y={};R(y,{create:()=>w,useRGSWithPlugins:()=>S,withPlugins:()=>W});module.exports=v(y);var p=require("react");var h=globalThis;h.rgs={};var c=h.rgs,P=t=>t[1].forEach(e=>e()),f=t=>e=>{let n=c[t];return n[1].push(e),()=>{n[1]=n[1].filter(s=>s!==e)}};var U=t=>{let e=c[t],n=()=>e[0];return[(0,p.useSyncExternalStore)(e[3],n,n),e[2]]},b=!1,m=(t,e)=>l(void 0,null,function*(){var r;let n=c[t],s=i=>{n[0]=i,P(n)};for(let i of e)yield(r=i.init)==null?void 0:r.call(i,t,n[0],s);b=!0}),L=(t,e,n=[],s=!1)=>{if(s){c[t]=[e,[],null,f(t)];return}let r=T=>{if(!b)return;let a=c[t];a[0]=T instanceof Function?T(a[0]):T,P(a),n.forEach(o=>{var u;return(u=o.onChange)==null?void 0:u.call(o,t,a[0])})},i=c[t];i?(i[0]=e,i[2]=r):c[t]=[e,[],r,f(t)],m(t,n)},S=(t,e,n,s=!1)=>{var r;return(r=c[t])!=null&&r[2]||L(t,e,n,s),U(t)};var w=(t,e,n)=>()=>S(t,e,n),W=t=>(n,s,r=!1)=>S(n,s,t,r);0&&(module.exports={create,useRGSWithPlugins,withPlugins}); |
@@ -5,3 +5,3 @@ { | ||
"private": false, | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "A simple yet elegant, light weight, react18 global store to replace Zustand for better tree shaking.", | ||
@@ -32,5 +32,5 @@ "main": "./dist/index.js", | ||
"devDependencies": { | ||
"@testing-library/react": "^15.0.5", | ||
"@testing-library/react": "^15.0.6", | ||
"@turbo/gen": "^1.13.3", | ||
"@types/node": "^20.12.7", | ||
"@types/node": "^20.12.8", | ||
"@types/react": "^18.3.1", | ||
@@ -37,0 +37,0 @@ "@types/react-dom": "^18.3.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
24440