Skip to content

Commit a510746

Browse files
authored
Merge pull request #26 from react18-tools/minify
Minify
2 parents 46cbc18 + 70faf24 commit a510746

10 files changed

Lines changed: 39 additions & 9 deletions

File tree

examples/nextjs/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# nextjs-example
22

3+
## 0.0.16
4+
5+
### Patch Changes
6+
7+
- Updated dependencies
8+
- r18gs@1.1.1
9+
- shared-ui@0.0.0
10+
311
## 0.0.15
412

513
### Patch Changes

examples/nextjs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nextjs-example",
3-
"version": "0.0.15",
3+
"version": "0.0.16",
44
"private": true,
55
"scripts": {
66
"dev": "next dev",

examples/remix/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# remix-example
22

3+
## 0.0.16
4+
5+
### Patch Changes
6+
7+
- Updated dependencies
8+
- r18gs@1.1.1
9+
- shared-ui@0.0.0
10+
311
## 0.0.15
412

513
### Patch Changes

examples/remix/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "remix-example",
3-
"version": "0.0.15",
3+
"version": "0.0.16",
44
"private": true,
55
"sideEffects": false,
66
"type": "module",

examples/vite/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# vite-example
22

3+
## 0.0.16
4+
5+
### Patch Changes
6+
7+
- Updated dependencies
8+
- r18gs@1.1.1
9+
- shared-ui@0.0.0
10+
311
## 0.0.15
412

513
### Patch Changes

examples/vite/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vite-example",
33
"private": true,
4-
"version": "0.0.15",
4+
"version": "0.0.16",
55
"type": "module",
66
"scripts": {
77
"dev": "vite --port 3001",

lib/r18gs/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# r18gs
22

3+
## 1.1.1
4+
5+
### Patch Changes
6+
7+
- Refactor to reduce minzip size
8+
39
## 1.1.0
410

511
### Minor Changes

lib/r18gs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "r18gs",
33
"author": "Mayank Kumar Chaudhari <https://mayank-chaudhari.vercel.app>",
44
"private": false,
5-
"version": "1.1.0",
5+
"version": "1.1.1",
66
"description": "A simple yet elegant, light weight, react18 global store to replace Zustand for better tree shaking.",
77
"main": "./dist/index.js",
88
"types": "./dist/index.d.ts",

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)