-
Notifications
You must be signed in to change notification settings - Fork 5
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
feat: 👔 supported zustand v5 #21
Conversation
Reviewer's Guide by SourceryThis PR updates the library to support Zustand v5, including upgrading dependencies and modernizing the testing approach. The implementation focuses on integrating Zustand's new useShallow hook for selector optimization and updating the build configuration. Class diagram for Zustand selector functionsclassDiagram
class ZustandFuncSelectors {
+use: object
}
class ZustandHookSelectors {
+use: object
}
class StoreApi
class UseBoundStore
class useStore
class useShallow
ZustandFuncSelectors --> StoreApi
ZustandFuncSelectors --> UseBoundStore
ZustandFuncSelectors --> useStore
ZustandFuncSelectors --> useShallow
ZustandHookSelectors --> StoreApi
ZustandHookSelectors --> UseBoundStore
ZustandHookSelectors --> useStore
ZustandHookSelectors --> useShallow
note for useShallow "New hook integrated for selector optimization"
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @Albert-Gao - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟢 Security: all looks good
- 🟡 Testing: 1 issue found
- 🟡 Complexity: 1 issue found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
@@ -32,44 +32,49 @@ | |||
"node": ">=18.0.0" | |||
}, | |||
"peerDependencies": { | |||
"zustand": "*" | |||
"zustand": ">=5.0.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (bug_risk): Consider adding upper bound to zustand peer dependency
To prevent potential breaking changes, consider specifying an upper bound version constraint (e.g., '>=5.0.0 <6.0.0').
"zustand": ">=5.0.0" | |
"zustand": ">=5.0.0 <6.0.0" |
|
||
expect(getByTestId('text').textContent).toBe('2'); | ||
expect(screen.getByTestId('text').textContent).toBe('2'); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (testing): Missing tests for new useShallow functionality
Since the implementation now uses useShallow from zustand/react/shallow, we should add specific tests to verify that the shallow comparison behavior works as expected, especially with object and array state values.
@@ -0,0 +1,61 @@ | |||
import typescriptEslint from '@typescript-eslint/eslint-plugin'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (complexity): Consider restructuring the ESLint configuration to use dynamic imports and consistent plugin handling patterns
The configuration can be simplified while maintaining all functionality. Here's a cleaner approach:
import { FlatCompat } from '@eslint/eslintrc';
import globals from 'globals';
import js from '@eslint/js';
import { fixupPluginRules } from '@eslint/compat';
// Import and fix up all plugins consistently
const plugins = {
'@typescript-eslint': fixupPluginRules(await import('@typescript-eslint/eslint-plugin')),
'prettier': fixupPluginRules(await import('eslint-plugin-prettier')),
'react-hooks': fixupPluginRules(await import('eslint-plugin-react-hooks'))
};
export default [
...(new FlatCompat()).extends(
'prettier',
'plugin:prettier/recommended',
'plugin:@typescript-eslint/eslint-recommended'
),
{
plugins,
languageOptions: {
globals: { ...globals.browser, Atomics: 'readonly', SharedArrayBuffer: 'readonly' },
parser: (await import('@typescript-eslint/parser')).default,
ecmaVersion: 2018,
sourceType: 'module',
parserOptions: { ecmaFeatures: { jsx: true } }
},
rules: {
'prettier/prettier': 'error',
'@typescript-eslint/explicit-function-return-type': 'off',
'no-use-before-define': 'off',
'@typescript-eslint/no-use-before-define': ['error'],
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn',
'react/react-in-jsx-scope': 'off'
}
}
];
Key improvements:
- Removed unnecessary path manipulation since FlatCompat defaults work fine
- Standardized plugin handling with consistent use of fixupPluginRules
- Used dynamic imports to reduce top-level import complexity
- Flattened configuration structure where possible
- Removed intermediate variables that weren't adding clarity
Summary by Sourcery
Add support for Zustand v5 by updating peer dependencies and refactor test files to use the 'screen' object from '@testing-library/react'. Update Rollup configuration to use '@rollup/plugin-terser' and enhance ESLint configuration with a new setup.
New Features:
Enhancements:
Build:
Tests: