From e21bb2c5f52ce4d0397a1f2fb06daf732736ea82 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 10 Jan 2025 16:43:18 +0800 Subject: [PATCH 1/2] fix: static-store setValue with setterFn has correct arguments - if a key is not listened to, setValue on that key was wrapping the prev value in an array when passed as argument to a setterFn --- packages/static-store/src/index.ts | 2 +- packages/static-store/test/index.test.ts | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/static-store/src/index.ts b/packages/static-store/src/index.ts index fb8b652d7..ae91fcaf0 100644 --- a/packages/static-store/src/index.ts +++ b/packages/static-store/src/index.ts @@ -68,7 +68,7 @@ export function createStaticStore( const setValue = (key: keyof T, value: SetterParam): void => { const signal = cache[key]; if (signal) return signal[1](value); - if (key in copy) copy[key] = accessWith(value, [copy[key]]); + if (key in copy) copy[key] = accessWith(value, copy[key]); }; return [ diff --git a/packages/static-store/test/index.test.ts b/packages/static-store/test/index.test.ts index 23f179030..6e8319904 100644 --- a/packages/static-store/test/index.test.ts +++ b/packages/static-store/test/index.test.ts @@ -32,6 +32,9 @@ describe("createStaticStore", () => { d: [0, 1, 2], }); + setState('a', prev => prev + 1); + expect(state.a).toBe(10); + createEffect(() => { state.a; aUpdates++; From 56d9511c0355dcf3e885b9567982c621ed7d595e Mon Sep 17 00:00:00 2001 From: Damian Tarnawski Date: Fri, 10 Jan 2025 11:01:07 +0100 Subject: [PATCH 2/2] Add changeset --- .changeset/silent-paws-approve.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/silent-paws-approve.md diff --git a/.changeset/silent-paws-approve.md b/.changeset/silent-paws-approve.md new file mode 100644 index 000000000..f5eca98e2 --- /dev/null +++ b/.changeset/silent-paws-approve.md @@ -0,0 +1,5 @@ +--- +"@solid-primitives/static-store": patch +--- + +fix: static-store setValue with setterFn has correct arguments