From db47618f0c3e3828b1514d6ba88ded5eeee7d5db Mon Sep 17 00:00:00 2001 From: David Domonkos Date: Wed, 15 Jan 2025 22:09:29 +0000 Subject: [PATCH 1/2] feat: createMutable support for class inheritance --- packages/solid/store/src/mutable.ts | 10 +++++--- .../store/test/mutableWithClass.spec.tsx | 23 +++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/packages/solid/store/src/mutable.ts b/packages/solid/store/src/mutable.ts index 0929f667..9d2eb45d 100644 --- a/packages/solid/store/src/mutable.ts +++ b/packages/solid/store/src/mutable.ts @@ -104,9 +104,13 @@ function wrap(value: T): T { !Array.isArray(value) && proto !== Object.prototype; if (isClass) { - const descriptors = Object.getOwnPropertyDescriptors(proto); - keys.push(...Object.keys(descriptors)); - Object.assign(desc, descriptors); + let curProto = proto; + while (curProto != null) { + const descriptors = Object.getOwnPropertyDescriptors(curProto); + keys.push(...Object.keys(descriptors)); + Object.assign(desc, descriptors); + curProto = Object.getPrototypeOf(curProto); + } } for (let i = 0, l = keys.length; i < l; i++) { diff --git a/packages/solid/store/test/mutableWithClass.spec.tsx b/packages/solid/store/test/mutableWithClass.spec.tsx index bfc1bc40..3d164ec9 100644 --- a/packages/solid/store/test/mutableWithClass.spec.tsx +++ b/packages/solid/store/test/mutableWithClass.spec.tsx @@ -53,4 +53,27 @@ describe("Class Operator test", () => { expect(count).toBe(3); expect(childCount).toBe(1); }); + + test("inherited properties", () => { + class A { + val = 0; + get getVal() { + return this.val; + } + } + class B extends A {} + + const instance = createMutable(new B()); + let lastVal: number | undefined; + + createRoot(() => { + createEffect(() => { + lastVal = instance.getVal; + }); + }); + + expect(lastVal).toBe(0); + instance.val = 1; + expect(lastVal).toBe(1); + }); }); From a07b27d9d1f91bd55e4405a3eaa28930be91c498 Mon Sep 17 00:00:00 2001 From: Ryan Carniato Date: Wed, 6 Aug 2025 11:35:27 -0700 Subject: [PATCH 2/2] Create tasty-garlics-agree.md --- .changeset/tasty-garlics-agree.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/tasty-garlics-agree.md diff --git a/.changeset/tasty-garlics-agree.md b/.changeset/tasty-garlics-agree.md new file mode 100644 index 00000000..4d59bb20 --- /dev/null +++ b/.changeset/tasty-garlics-agree.md @@ -0,0 +1,5 @@ +--- +"solid-js": patch +--- + +feat: createMutable support for class inheritance