diff --git a/examples/nextjs/CHANGELOG.md b/examples/nextjs/CHANGELOG.md index ca71a5d4..eff4862e 100644 --- a/examples/nextjs/CHANGELOG.md +++ b/examples/nextjs/CHANGELOG.md @@ -1,5 +1,13 @@ # nextjs-example +## 0.0.16 + +### Patch Changes + +- Updated dependencies + - r18gs@1.1.1 + - shared-ui@0.0.0 + ## 0.0.15 ### Patch Changes diff --git a/examples/nextjs/package.json b/examples/nextjs/package.json index 8972713e..c2072914 100644 --- a/examples/nextjs/package.json +++ b/examples/nextjs/package.json @@ -1,6 +1,6 @@ { "name": "nextjs-example", - "version": "0.0.15", + "version": "0.0.16", "private": true, "scripts": { "dev": "next dev", diff --git a/examples/remix/CHANGELOG.md b/examples/remix/CHANGELOG.md index dee4474e..b90a290e 100644 --- a/examples/remix/CHANGELOG.md +++ b/examples/remix/CHANGELOG.md @@ -1,5 +1,13 @@ # remix-example +## 0.0.16 + +### Patch Changes + +- Updated dependencies + - r18gs@1.1.1 + - shared-ui@0.0.0 + ## 0.0.15 ### Patch Changes diff --git a/examples/remix/package.json b/examples/remix/package.json index 6556c5e2..bef77336 100644 --- a/examples/remix/package.json +++ b/examples/remix/package.json @@ -1,6 +1,6 @@ { "name": "remix-example", - "version": "0.0.15", + "version": "0.0.16", "private": true, "sideEffects": false, "type": "module", diff --git a/examples/vite/CHANGELOG.md b/examples/vite/CHANGELOG.md index 2466ea0f..b8d10792 100644 --- a/examples/vite/CHANGELOG.md +++ b/examples/vite/CHANGELOG.md @@ -1,5 +1,13 @@ # vite-example +## 0.0.16 + +### Patch Changes + +- Updated dependencies + - r18gs@1.1.1 + - shared-ui@0.0.0 + ## 0.0.15 ### Patch Changes diff --git a/examples/vite/package.json b/examples/vite/package.json index ec184200..14a0d2cb 100644 --- a/examples/vite/package.json +++ b/examples/vite/package.json @@ -1,7 +1,7 @@ { "name": "vite-example", "private": true, - "version": "0.0.15", + "version": "0.0.16", "type": "module", "scripts": { "dev": "vite --port 3001", diff --git a/lib/r18gs/CHANGELOG.md b/lib/r18gs/CHANGELOG.md index 10266bfe..5cb32d76 100644 --- a/lib/r18gs/CHANGELOG.md +++ b/lib/r18gs/CHANGELOG.md @@ -1,5 +1,11 @@ # r18gs +## 1.1.1 + +### Patch Changes + +- Refactor to reduce minzip size + ## 1.1.0 ### Minor Changes diff --git a/lib/r18gs/package.json b/lib/r18gs/package.json index 5df83976..cc9f74a9 100644 --- a/lib/r18gs/package.json +++ b/lib/r18gs/package.json @@ -2,7 +2,7 @@ "name": "r18gs", "author": "Mayank Kumar Chaudhari ", "private": false, - "version": "1.1.0", + "version": "1.1.1", "description": "A simple yet elegant, light weight, react18 global store to replace Zustand for better tree shaking.", "main": "./dist/index.js", "types": "./dist/index.d.ts", diff --git a/lib/r18gs/src/index.ts b/lib/r18gs/src/index.ts index 17e6947e..8ac4319a 100644 --- a/lib/r18gs/src/index.ts +++ b/lib/r18gs/src/index.ts @@ -20,11 +20,12 @@ export type { SetterArgType, SetStateAction, Plugin } from "./utils"; * @param value - Initial value of the store. * @returns - A tuple (Ordered sequance of values) containing the state and a function to set the state. */ -const useRGS = (key: string, value?: ValueType): [T, SetStateAction] => { +export default (key: string, value?: ValueType): [T, SetStateAction] => { /** Initialize the named store when invoked for the first time. */ if (!globalRGS[key]) globalRGS[key] = [ - value instanceof Function ? value() : value, + // @ts-expect-error -- ok + typeof value === "function" ? value() : value, [], createSetter(key), createSubcriber(key), @@ -32,5 +33,3 @@ const useRGS = (key: string, value?: ValueType): [T, SetStateAction] => return createHook(key); }; - -export default useRGS; diff --git a/lib/r18gs/src/utils.ts b/lib/r18gs/src/utils.ts index 421ec4ab..f35cd979 100644 --- a/lib/r18gs/src/utils.ts +++ b/lib/r18gs/src/utils.ts @@ -15,6 +15,7 @@ type RGS = [unknown, Listener[], SetStateAction | null, Subscriber]; declare global { // eslint-disable-next-line no-var -- var required for global declaration. + // skipcq: JS-0102, JS-0239 var rgs: Record; } @@ -41,7 +42,7 @@ export const createSubcriber = (key: string): Subscriber => { export const createSetter = (key: string): SetStateAction => { return val => { const rgs = globalRGS[key] as RGS; - rgs[VALUE] = val instanceof Function ? val(rgs[VALUE] as T) : val; + rgs[VALUE] = typeof val === "function" ? val(rgs[VALUE] as T) : val; (rgs[LISTENERS] as Listener[]).forEach(listener => listener()); }; };