|
1 | | -import { getListener, batch, DEV, $PROXY, $TRACK, createSignal } from "solid-js"; |
| 1 | +import { $PROXY, $TRACK, batch, createSignal, DEV, getListener } from "solid-js"; |
2 | 2 |
|
3 | 3 | export const $RAW = Symbol("store-raw"), |
4 | 4 | $NODE = Symbol("store-node"), |
@@ -49,11 +49,27 @@ function wrap<T extends StoreNode>(value: T): T { |
49 | 49 | Object.defineProperty(value, $PROXY, { value: (p = new Proxy(value, proxyTraps)) }); |
50 | 50 | if (!Array.isArray(value)) { |
51 | 51 | const keys = Object.keys(value), |
52 | | - desc = Object.getOwnPropertyDescriptors(value); |
| 52 | + desc = Object.getOwnPropertyDescriptors(value), |
| 53 | + proto = Object.getPrototypeOf(value); |
| 54 | + |
| 55 | + const isClass = |
| 56 | + proto !== null && |
| 57 | + value !== null && |
| 58 | + typeof value === "object" && |
| 59 | + !Array.isArray(value) && |
| 60 | + proto !== Object.prototype; |
| 61 | + if (isClass) { |
| 62 | + const descriptors = Object.getOwnPropertyDescriptors(proto); |
| 63 | + keys.push(...Object.keys(descriptors)); |
| 64 | + Object.assign(desc, descriptors); |
| 65 | + } |
| 66 | + |
53 | 67 | for (let i = 0, l = keys.length; i < l; i++) { |
54 | 68 | const prop = keys[i]; |
| 69 | + if (isClass && prop === "constructor") continue; |
55 | 70 | if (desc[prop].get) { |
56 | 71 | Object.defineProperty(value, prop, { |
| 72 | + configurable: true, |
57 | 73 | enumerable: desc[prop].enumerable, |
58 | 74 | get: desc[prop].get!.bind(p) |
59 | 75 | }); |
|
0 commit comments