diff --git a/.changeset/dry-goats-sing.md b/.changeset/dry-goats-sing.md new file mode 100644 index 0000000..225d5c9 --- /dev/null +++ b/.changeset/dry-goats-sing.md @@ -0,0 +1,5 @@ +--- +"deepsignal": patch +--- + +Avoid side-effects on the `ownKeys` trap. diff --git a/packages/deepsignal/core/package.json b/packages/deepsignal/core/package.json index b6a71e5..c17c1e5 100644 --- a/packages/deepsignal/core/package.json +++ b/packages/deepsignal/core/package.json @@ -9,7 +9,7 @@ "source": "src/index.ts", "license": "MIT", "dependencies": { - "@preact/signals-core": "^1.0.0" + "@preact/signals-core": "^1.3.1" }, "exports": { ".": { diff --git a/packages/deepsignal/core/src/index.ts b/packages/deepsignal/core/src/index.ts index ab8c2a0..ae9e7bb 100644 --- a/packages/deepsignal/core/src/index.ts +++ b/packages/deepsignal/core/src/index.ts @@ -117,7 +117,7 @@ const objectHandlers = { }, ownKeys(target: object): (string | symbol)[] { if (!objToIterable.has(target)) objToIterable.set(target, signal(0)); - objToIterable.get(target).value = objToIterable.get(target).value; + (objToIterable as any)._ = objToIterable.get(target).value; return Reflect.ownKeys(target); }, }; diff --git a/packages/deepsignal/core/test/index.test.tsx b/packages/deepsignal/core/test/index.test.tsx index 1a6e81d..a39f17d 100644 --- a/packages/deepsignal/core/test/index.test.tsx +++ b/packages/deepsignal/core/test/index.test.tsx @@ -66,6 +66,20 @@ describe("deepsignal/core", () => { expect(store.aOrB.data).to.equal("b"); }); + it("should support getters using ownKeys traps", () => { + const state = deepSignal({ + x: { + a: 1, + b: 2, + }, + get y() { + return Object.values(state.x); + }, + }); + + expect(state.y).to.deep.equal([1, 2]); + }); + it("should work with normal functions", () => { const store = deepSignal({ value: 1, diff --git a/packages/deepsignal/package.json b/packages/deepsignal/package.json index 407ead2..d838835 100644 --- a/packages/deepsignal/package.json +++ b/packages/deepsignal/package.json @@ -45,9 +45,9 @@ "prepublishOnly": "cp ../../README.md . && cd ../.. && pnpm build" }, "dependencies": { - "@preact/signals-core": "^1.0.0", - "@preact/signals": "^1.0.0", - "@preact/signals-react": "^1.0.0" + "@preact/signals-core": "^1.3.1", + "@preact/signals": "^1.1.4", + "@preact/signals-react": "^1.3.3" }, "peerDependencies": { "preact": "10.x" diff --git a/packages/deepsignal/react/package.json b/packages/deepsignal/react/package.json index 8579cc1..8212290 100644 --- a/packages/deepsignal/react/package.json +++ b/packages/deepsignal/react/package.json @@ -9,8 +9,8 @@ "source": "src/index.ts", "license": "MIT", "dependencies": { - "@preact/signals-core": "^1.0.0", - "@preact/signals-react": "^1.0.0" + "@preact/signals-core": "^1.3.1", + "@preact/signals-react": "^1.3.3" }, "peerDependencies": { "react": "17.x || 18.x" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cac0344..cb808d4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -140,14 +140,14 @@ importers: packages/deepsignal: dependencies: '@preact/signals': - specifier: ^1.0.0 - version: 1.1.3(preact@10.9.0) + specifier: ^1.1.4 + version: 1.1.4(preact@10.9.0) '@preact/signals-core': - specifier: ^1.0.0 - version: 1.2.3 + specifier: ^1.3.1 + version: 1.3.1 '@preact/signals-react': - specifier: ^1.0.0 - version: 1.2.2(react@18.2.0) + specifier: ^1.3.3 + version: 1.3.3(react@18.2.0) devDependencies: '@types/react': specifier: ^18.0.18 @@ -1898,26 +1898,26 @@ packages: fastq: 1.13.0 dev: true - /@preact/signals-core@1.2.3: - resolution: {integrity: sha512-Kui4p7PMcEQevBgsTO0JBo3gyQ88Q3qzEvsVCuSp11t0JcN4DmGCTJcGRVSCq7Bn7lGxJBO+57jNSzDoDJ+QmA==} + /@preact/signals-core@1.3.1: + resolution: {integrity: sha512-DL+3kDssZ3UOMz9HufwSYE/gK0+TnT1jzegfF5rstgyPrnyfjz4BHAoxmzQA6Mkp4UlKe8qjsgl3v5a/obzNig==} dev: false - /@preact/signals-react@1.2.2(react@18.2.0): - resolution: {integrity: sha512-GoESQ9n1bns2FD+8yqH7lBvQMavboKLCNEW+s0hs3Wcp5B1VHvVxwJo6aFs6rpxoh1/q8Tvwbi4vIeehBD2mzA==} + /@preact/signals-react@1.3.3(react@18.2.0): + resolution: {integrity: sha512-Tbv+oWPcrWowAJp1U1eWFiFUJihulOAnL8g/hJ3fUsP0IcsKsj8U0OcIDrwemIPQe7+J/3FuudkZzted0MD/bA==} peerDependencies: - react: 17.x || 18.x + react: ^16.14.0 || 17.x || 18.x dependencies: - '@preact/signals-core': 1.2.3 + '@preact/signals-core': 1.3.1 react: 18.2.0 use-sync-external-store: 1.2.0(react@18.2.0) dev: false - /@preact/signals@1.1.3(preact@10.9.0): - resolution: {integrity: sha512-N09DuAVvc90bBZVRwD+aFhtGyHAmJLhS3IFoawO/bYJRcil4k83nBOchpCEoS0s5+BXBpahgp0Mjf+IOqP57Og==} + /@preact/signals@1.1.4(preact@10.9.0): + resolution: {integrity: sha512-4s0U8yHfy6OzBjTx8lgG0JZGFq1y+ye7xLmaaI8SXyJ5p+jAtMKW40Mg3GDLISM5WyKnqbfrQ4SOmbq1VTBtTw==} peerDependencies: preact: 10.x dependencies: - '@preact/signals-core': 1.2.3 + '@preact/signals-core': 1.3.1 preact: 10.9.0 dev: false