Skip to content

Commit cbccde8

Browse files
authored
Merge pull request #38 from react18-tools/fix-37
Fix 37: different state shapes
2 parents e7fd5e2 + ce6058b commit cbccde8

File tree

6 files changed

+18
-4
lines changed

6 files changed

+18
-4
lines changed

lib/CHANGELOG.md

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

3+
## 3.0.1
4+
5+
### Patch Changes
6+
7+
- 005e935: Fix #37: Edgecase when the old and new state have different shape
8+
39
## 3.0.0
410

511
### Major Changes

lib/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": "3.0.0",
5+
"version": "3.0.1",
66
"description": "A simple yet elegant, light weight, react18 global store to replace Zustand for better tree shaking.",
77
"license": "MPL-2.0",
88
"main": "./dist/index.js",

lib/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const useRGS = <T>(
3535
l: [],
3636
s: val => {
3737
const rgs = globalRGS[key] as RGS;
38-
const oldV = rgs.v as T;
38+
const oldV = rgs.v ?? {};
3939
rgs.v = val instanceof Function ? val(oldV) : val;
4040
triggerListeners(rgs, oldV, rgs.v);
4141
},

lib/src/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ export const triggerListeners = <T>(rgs: RGS, oldV: T, newV: T) => {
3434
const updatedFiels: string[] = [];
3535
// no need to test this --- it will automatically fail
3636
// if (typeof oldV === "object" && typeof rgs.v === "object")
37-
for (const key in oldV) if (oldV[key] !== newV[key]) updatedFiels.push(key);
37+
for (const obj of [oldV, newV])
38+
for (const key in obj) if (oldV[key] !== newV[key]) updatedFiels.push(key);
3839
// const testStr = updatedFiels.join("; ");
3940
rgs.l.forEach(
4041
({ l, s: [includeRegExp, excludeRegExp] }) =>

packages/shared/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# @repo/shared
22

3+
## 0.0.7
4+
5+
### Patch Changes
6+
7+
- Updated dependencies [005e935]
8+
9+
310
## 0.0.6
411

512
### Patch Changes

packages/shared/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@repo/shared",
3-
"version": "0.0.6",
3+
"version": "0.0.7",
44
"private": true,
55
"sideEffects": false,
66
"main": "./dist/index.js",

0 commit comments

Comments
 (0)