Skip to content

Commit 60bd3eb

Browse files
committed
fixes #37
1 parent e7fd5e2 commit 60bd3eb

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

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] }) =>

0 commit comments

Comments
 (0)