Skip to content

Commit

Permalink
Merge branch 'fix-computeds-using-ownkeys'
Browse files Browse the repository at this point in the history
  • Loading branch information
luisherranz committed Jul 10, 2023
2 parents 16b1967 + a846d10 commit 4607f19
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 22 deletions.
5 changes: 5 additions & 0 deletions .changeset/dry-goats-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"deepsignal": patch
---

Avoid side-effects on the `ownKeys` trap.
2 changes: 1 addition & 1 deletion packages/deepsignal/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"source": "src/index.ts",
"license": "MIT",
"dependencies": {
"@preact/signals-core": "^1.0.0"
"@preact/signals-core": "^1.3.1"
},
"exports": {
".": {
Expand Down
2 changes: 1 addition & 1 deletion packages/deepsignal/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
};
Expand Down
14 changes: 14 additions & 0 deletions packages/deepsignal/core/test/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions packages/deepsignal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions packages/deepsignal/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
30 changes: 15 additions & 15 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4607f19

Please sign in to comment.