Skip to content

Commit

Permalink
Changeset
Browse files Browse the repository at this point in the history
  • Loading branch information
mayank1513 committed Feb 27, 2024
1 parent aea4c4c commit d1b18b7
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 5 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.6

### Patch Changes

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

## 0.0.5

### 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.5",
"version": "0.0.6",
"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.6

### Patch Changes

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

## 0.0.5

### 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.5",
"version": "0.0.6",
"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.6

### Patch Changes

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

## 0.0.5

### 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.5",
"version": "0.0.6",
"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

## 0.1.0

### Minor Changes

- Remove client side hooks. Now this store works well with server components as well. Though, server side use is tricky and not recommended yet.

## 0.0.5

### Patch 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": "0.0.5",
"version": "0.1.0",
"description": "A simple yet elegant, light weight, react18 global store to replace Zustand for better tree shaking.",
"main": "./index.ts",
"types": "./index.ts",
Expand Down
6 changes: 5 additions & 1 deletion lib/r18gs/src/use-rgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ globalThis.subscribers = {};
export default function useRGS<T>(key: string, value?: T): [T, (val: SetterArgType<T>) => void] {
if (!globalThis.subscribers[key]) {
globalThis.subscribers[key] = (listener: () => void) => {
if (!globalThis.rgs[key]) globalThis.rgs[key] = { listeners: [], value };
if (!globalThis.rgs[key]) {
/** opportunity to add initializer */
globalThis.rgs[key] = { listeners: [], value };
}
const rgs = globalThis.rgs[key] as React18GlobalStore;
rgs.listeners.push(listener);
return () => {
Expand All @@ -51,6 +54,7 @@ export default function useRGS<T>(key: string, value?: T): [T, (val: SetterArgTy
globalThis.setters[key] = val => {
const rgs = globalThis.rgs[key] as React18GlobalStore;
rgs.value = val instanceof Function ? val(rgs.value as T) : val;
/** opportunity to add custom listener */
for (const listener of rgs.listeners) listener();
};
}
Expand Down

0 comments on commit d1b18b7

Please sign in to comment.