Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minify #26

Merged
merged 2 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

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 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;
Dismissed Show dismissed Hide dismissed
(rgs[LISTENERS] as Listener[]).forEach(listener => listener());
};
};
Expand Down
Loading