Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor of selector generation #18

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "auto-zustand-selectors-hook",
"version": "2.0.3",
"version": "2.0.4",
"keywords": [],
"description": "",
"main": "dist/index.min.js",
Expand Down Expand Up @@ -72,4 +72,4 @@
"zustand": "^4.5.2"
},
"packageManager": "[email protected]+sha1.1959a18351b811cdeedbd484a8f86c3cc3bbaf72"
}
}
8 changes: 3 additions & 5 deletions src/createSelectorFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ export function createSelectorFunctions<StateType extends object>(

Object.keys(storeIn.getState()).forEach((key) => {
const selector = (state: StateType) => state[key as keyof StateType];
storeIn.use[key] = () => {
return typeof storeIn === 'function'
? storeIn(selector)
: useStore(storeIn, selector as any);
};
storeIn.use[key] = typeof storeIn === 'function'
? () => storeIn(selector)
: () => useStore(storeIn, selector as any);
});

return store as UseBoundStore<StoreApi<StateType>> &
Expand Down
8 changes: 3 additions & 5 deletions src/createSelectorHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ export function createSelectorHooks<StateType extends object>(

Object.keys(storeIn.getState()).forEach((key) => {
const selector = (state: StateType) => state[key as keyof StateType];
storeIn[`use${capitalize(key)}`] = () => {
return typeof storeIn === 'function'
? storeIn(selector)
: useStore(storeIn, selector as any);
};
storeIn[`use${capitalize(key)}`] = typeof storeIn === 'function'
? () => storeIn(selector)
: () => useStore(storeIn, selector as any);
});

return storeIn as UseBoundStore<StoreApi<StateType>> &
Expand Down
Loading