Skip to content

Commit 9478e72

Browse files
committed
patch: improve minzip bundle size
1 parent 46cbc18 commit 9478e72

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

lib/r18gs/src/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,16 @@ export type { SetterArgType, SetStateAction, Plugin } from "./utils";
2020
* @param value - Initial value of the store.
2121
* @returns - A tuple (Ordered sequance of values) containing the state and a function to set the state.
2222
*/
23-
const useRGS = <T>(key: string, value?: ValueType<T>): [T, SetStateAction<T>] => {
23+
export default <T>(key: string, value?: ValueType<T>): [T, SetStateAction<T>] => {
2424
/** Initialize the named store when invoked for the first time. */
2525
if (!globalRGS[key])
2626
globalRGS[key] = [
27-
value instanceof Function ? value() : value,
27+
// @ts-expect-error -- ok
28+
typeof value === "function" ? value() : value,
2829
[],
2930
createSetter(key),
3031
createSubcriber(key),
3132
];
3233

3334
return createHook<T>(key);
3435
};
35-
36-
export default useRGS;

lib/r18gs/src/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type RGS = [unknown, Listener[], SetStateAction<unknown> | null, Subscriber];
1515

1616
declare global {
1717
// eslint-disable-next-line no-var -- var required for global declaration.
18+
// skipcq: JS-0102, JS-0239
1819
var rgs: Record<string, RGS | undefined>;
1920
}
2021

@@ -41,7 +42,7 @@ export const createSubcriber = (key: string): Subscriber => {
4142
export const createSetter = <T>(key: string): SetStateAction<unknown> => {
4243
return val => {
4344
const rgs = globalRGS[key] as RGS;
44-
rgs[VALUE] = val instanceof Function ? val(rgs[VALUE] as T) : val;
45+
rgs[VALUE] = typeof val === "function" ? val(rgs[VALUE] as T) : val;
4546
(rgs[LISTENERS] as Listener[]).forEach(listener => listener());
4647
};
4748
};

0 commit comments

Comments
 (0)