Skip to content

Commit

Permalink
feat: withProxy
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi committed Jul 13, 2024
1 parent 9ab6125 commit f67b324
Show file tree
Hide file tree
Showing 6 changed files with 698 additions and 646 deletions.
7 changes: 4 additions & 3 deletions examples/01_counter/src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { createWithProxy } from 'zustand-valtio';
import { create } from 'zustand';
import { withProxy } from 'zustand-valtio';

const useCounterState = createWithProxy({ count: 0 });
const useCounterState = create(withProxy({ count: 0 }));

const Counter = () => {
const count = useCounterState((state) => state.count);
const inc = () => ++useCounterState.proxyState.count;
const inc = () => ++useCounterState.getProxyState().count;
return (
<>
<div>Count: {count}</div>
Expand Down
17 changes: 10 additions & 7 deletions examples/02_methods/src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { createWithProxy } from 'zustand-valtio';
import { create } from 'zustand';
import { withProxy } from 'zustand-valtio';

const useCounterState = createWithProxy({
count: 0,
inc() {
this.count++;
},
});
const useCounterState = create(
withProxy({
count: 0,
inc() {
this.count++;
},
}),
);

const Counter = () => {
const count = useCounterState((state) => state.count);
Expand Down
44 changes: 21 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,36 +53,34 @@
"singleQuote": true
},
"devDependencies": {
"@testing-library/jest-dom": "^6.4.2",
"@testing-library/react": "^15.0.2",
"@testing-library/jest-dom": "^6.4.6",
"@testing-library/react": "^16.0.0",
"@testing-library/user-event": "^14.5.2",
"@types/node": "^20.12.7",
"@types/react": "^18.2.79",
"@types/react-dom": "^18.2.25",
"@typescript-eslint/eslint-plugin": "^7.7.0",
"@typescript-eslint/parser": "^7.7.0",
"eslint": "^8.57.0",
"@types/node": "^20.14.10",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@typescript-eslint/eslint-plugin": "^7.16.0",
"@typescript-eslint/parser": "^7.16.0",
"eslint": "8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jsx-a11y": "^6.8.0",
"eslint-plugin-react": "^7.34.1",
"eslint-plugin-react-hooks": "^4.6.0",
"happy-dom": "^14.7.1",
"prettier": "^3.2.5",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"eslint-plugin-jsx-a11y": "^6.9.0",
"eslint-plugin-react": "^7.34.3",
"eslint-plugin-react-hooks": "^4.6.2",
"happy-dom": "^14.12.3",
"prettier": "^3.3.2",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"ts-expect": "^1.3.0",
"typescript": "^5.4.5",
"valtio": "^1.13.2",
"vite": "^5.2.10",
"vitest": "^1.5.0",
"zustand": "^4.5.2",
"typescript": "^5.5.3",
"valtio": "^2.0.0-rc.0",
"vite": "^5.3.3",
"vitest": "^2.0.2",
"zustand": "^4.5.4",
"zustand-valtio": "link:."
},
"peerDependencies": {
"react": ">=18.0.0",
"valtio": ">=1.0.0",
"zustand": ">=4.0.0"
"valtio": ">=2.0.0-rc.0"
}
}
Loading

0 comments on commit f67b324

Please sign in to comment.