-
Notifications
You must be signed in to change notification settings - Fork 266
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
fix(props): add mergeProps utility to resolve all defaultProps warnings #2581
Conversation
Walkthrough此次变更涉及多个组件的属性合并逻辑,主要通过引入新的实用函数 Changes
Suggested labels
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 1
/** | ||
* Merge props and return the first non-undefined value. | ||
* The later has higher priority. e.g. (10, 1, 5) => 5 wins. | ||
* This is useful with legacy props that have been deprecated. | ||
*/ | ||
export function mergeProp<T, DefaultT extends T = T>( | ||
defaultProp: DefaultT, | ||
...propList: T[] | ||
): T | undefined { | ||
for (let i = propList.length - 1; i >= 0; i -= 1) { | ||
if (propList[i] !== undefined) { | ||
return propList[i] | ||
} | ||
} | ||
return defaultProp |
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.
批准更改并建议记录使用案例
mergeProp
函数的实现正确地处理了属性列表,并返回第一个非 undefined 值,后面的属性具有更高的优先级。这对于处理已弃用的属性非常有用。建议在文档中添加此函数的使用案例,以帮助开发者了解其在实际场景中的应用。
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## next #2581 +/- ##
==========================================
- Coverage 83.18% 83.11% -0.07%
==========================================
Files 217 218 +1
Lines 17804 17826 +22
Branches 2543 2546 +3
==========================================
+ Hits 14810 14816 +6
- Misses 2989 3005 +16
Partials 5 5 ☔ View full report in Codecov by Sentry. |
Summary by CodeRabbit
新功能
mergeProps
工具函数,以改进多个组件(如ActionSheet
、CountUp
、BaseDialog
、Notify
和Toast
)中属性的合并逻辑,提升了属性管理的灵活性和可维护性。修复
defaultProps
赋值,简化了组件的默认属性管理。文档
mergeProps
函数的实现,支持合并多个对象,增强了功能。