Skip to content

Commit

Permalink
Merge pull request #38 from react18-tools/fix-37
Browse files Browse the repository at this point in the history
Fix 37: different state shapes
  • Loading branch information
mayank1513 authored Dec 18, 2024
2 parents e7fd5e2 + ce6058b commit cbccde8
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 4 deletions.
6 changes: 6 additions & 0 deletions lib/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# r18gs

## 3.0.1

### Patch Changes

- 005e935: Fix #37: Edgecase when the old and new state have different shape

## 3.0.0

### Major Changes
Expand Down
2 changes: 1 addition & 1 deletion lib/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": "3.0.0",
"version": "3.0.1",
"description": "A simple yet elegant, light weight, react18 global store to replace Zustand for better tree shaking.",
"license": "MPL-2.0",
"main": "./dist/index.js",
Expand Down
2 changes: 1 addition & 1 deletion lib/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const useRGS = <T>(
l: [],
s: val => {
const rgs = globalRGS[key] as RGS;
const oldV = rgs.v as T;
const oldV = rgs.v ?? {};
rgs.v = val instanceof Function ? val(oldV) : val;
triggerListeners(rgs, oldV, rgs.v);
},
Expand Down
3 changes: 2 additions & 1 deletion lib/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export const triggerListeners = <T>(rgs: RGS, oldV: T, newV: T) => {
const updatedFiels: string[] = [];
// no need to test this --- it will automatically fail
// if (typeof oldV === "object" && typeof rgs.v === "object")
for (const key in oldV) if (oldV[key] !== newV[key]) updatedFiels.push(key);
for (const obj of [oldV, newV])
for (const key in obj) if (oldV[key] !== newV[key]) updatedFiels.push(key);
// const testStr = updatedFiels.join("; ");
rgs.l.forEach(
({ l, s: [includeRegExp, excludeRegExp] }) =>
Expand Down
7 changes: 7 additions & 0 deletions packages/shared/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @repo/shared

## 0.0.7

### Patch Changes

- Updated dependencies [005e935]
- [email protected]

## 0.0.6

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@repo/shared",
"version": "0.0.6",
"version": "0.0.7",
"private": true,
"sideEffects": false,
"main": "./dist/index.js",
Expand Down

0 comments on commit cbccde8

Please sign in to comment.