Skip to content

Commit

Permalink
Merge pull request #26 from react18-tools/minify
Browse files Browse the repository at this point in the history
Minify
  • Loading branch information
mayank1513 authored Jun 14, 2024
2 parents 46cbc18 + 70faf24 commit a510746
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 9 deletions.
8 changes: 8 additions & 0 deletions examples/nextjs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# nextjs-example

## 0.0.16

### Patch Changes

- Updated dependencies
- [email protected]
- [email protected]

## 0.0.15

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion examples/nextjs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nextjs-example",
"version": "0.0.15",
"version": "0.0.16",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
8 changes: 8 additions & 0 deletions examples/remix/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# remix-example

## 0.0.16

### Patch Changes

- Updated dependencies
- [email protected]
- [email protected]

## 0.0.15

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion examples/remix/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "remix-example",
"version": "0.0.15",
"version": "0.0.16",
"private": true,
"sideEffects": false,
"type": "module",
Expand Down
8 changes: 8 additions & 0 deletions examples/vite/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# vite-example

## 0.0.16

### Patch Changes

- Updated dependencies
- [email protected]
- [email protected]

## 0.0.15

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion examples/vite/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vite-example",
"private": true,
"version": "0.0.15",
"version": "0.0.16",
"type": "module",
"scripts": {
"dev": "vite --port 3001",
Expand Down
6 changes: 6 additions & 0 deletions lib/r18gs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# r18gs

## 1.1.1

### Patch Changes

- Refactor to reduce minzip size

## 1.1.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion lib/r18gs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "r18gs",
"author": "Mayank Kumar Chaudhari <https://mayank-chaudhari.vercel.app>",
"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",
Expand Down
7 changes: 3 additions & 4 deletions lib/r18gs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@ 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 = <T>(key: string, value?: ValueType<T>): [T, SetStateAction<T>] => {
export default <T>(key: string, value?: ValueType<T>): [T, SetStateAction<T>] => {
/** 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),
];

return createHook<T>(key);
};

export default useRGS;
3 changes: 2 additions & 1 deletion lib/r18gs/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type RGS = [unknown, Listener[], SetStateAction<unknown> | null, Subscriber];

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

Expand All @@ -41,7 +42,7 @@ export const createSubcriber = (key: string): Subscriber => {
export const createSetter = <T>(key: string): SetStateAction<unknown> => {
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());
};
};
Expand Down

0 comments on commit a510746

Please sign in to comment.