From a8635c48574f4b6b125ba6d652ee167636348a30 Mon Sep 17 00:00:00 2001 From: kmindubaev Date: Wed, 5 Jun 2024 17:41:18 -0700 Subject: [PATCH 1/2] refactor: generating selectors only once improved perfomance. previously selector hooks were re-generated on every call to store --- src/createSelectorFunctions.ts | 8 +++----- src/createSelectorHooks.ts | 8 +++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/createSelectorFunctions.ts b/src/createSelectorFunctions.ts index 9f1f071..d1ba0a7 100755 --- a/src/createSelectorFunctions.ts +++ b/src/createSelectorFunctions.ts @@ -15,11 +15,9 @@ export function createSelectorFunctions( 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> & diff --git a/src/createSelectorHooks.ts b/src/createSelectorHooks.ts index 92b8f17..0b9cfb5 100755 --- a/src/createSelectorHooks.ts +++ b/src/createSelectorHooks.ts @@ -15,11 +15,9 @@ export function createSelectorHooks( 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> & From 0e109b932ecca821082ac69dd767df9c5de41ba4 Mon Sep 17 00:00:00 2001 From: kmindubaev Date: Wed, 5 Jun 2024 17:46:01 -0700 Subject: [PATCH 2/2] v2.0.4 --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index b025fb0..409f4c3 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "auto-zustand-selectors-hook", - "version": "2.0.3", + "version": "2.0.4", "keywords": [], "description": "", "main": "dist/index.min.js", @@ -72,4 +72,4 @@ "zustand": "^4.5.2" }, "packageManager": "yarn@1.22.21+sha1.1959a18351b811cdeedbd484a8f86c3cc3bbaf72" -} \ No newline at end of file +}