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

fix(props): add mergeProps utility to resolve all defaultProps warnings #2581

Merged
merged 3 commits into from
Sep 10, 2024

Conversation

Alex-huxiyang
Copy link
Collaborator

@Alex-huxiyang Alex-huxiyang commented Sep 9, 2024

  • 日常 bug 修复
  • 重构
  • 代码风格优化

Summary by CodeRabbit

  • 新功能

    • 引入了 mergeProps 工具函数,以改进多个组件(如 ActionSheetCountUpBaseDialogNotifyToast)中属性的合并逻辑,提升了属性管理的灵活性和可维护性。
  • 修复

    • 移除了不再使用的 defaultProps 赋值,简化了组件的默认属性管理。
  • 文档

    • 更新了 mergeProps 函数的实现,支持合并多个对象,增强了功能。

Copy link

coderabbitai bot commented Sep 9, 2024

Walkthrough

此次变更涉及多个组件的属性合并逻辑,主要通过引入新的实用函数 mergeProps 来替代之前的扩展运算符方法。所有相关组件(如 ActionSheetCountUpBaseDialogNotifyToast)均更新了属性合并的实现方式,移除了对 defaultProps 的直接赋值。这些更改旨在提高代码的可维护性和灵活性。

Changes

文件路径 变更摘要
src/packages/actionsheet/actionsheet.taro.tsx 使用 mergeProps 替代扩展运算符合并 defaultPropsprops
src/packages/animatingnumbers/countup.taro.tsx 使用 mergeProps 替代扩展运算符合并 defaultPropsprops,移除对 CountUp.defaultProps 的显式设置。
src/packages/dialog/dialog.taro.tsx 使用 mergeProps 替代扩展运算符合并 defaultPropsprops,移除对 BaseDialog.defaultProps 的赋值。
src/packages/dialog/dialog.tsx 使用 mergeProps 替代扩展运算符合并 defaultPropsprops,移除对 Dialog.defaultProps 的赋值。
src/packages/notify/notify.taro.tsx 使用 mergeProps 替代扩展运算符合并 defaultPropsprops,移除对 Notify.defaultProps 的赋值。
src/packages/toast/toast.taro.tsx 使用 mergeProps 替代扩展运算符合并 defaultPropsprops,移除对 Toast.defaultProps 的赋值。
src/utils/merge-props.ts mergeProps 函数的实现和签名进行了重大更改,支持合并多个对象,并引入了 mergeProp 函数以处理多个参数的合并。

Suggested labels

size/XL

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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Alex-huxiyang Alex-huxiyang changed the title fix: add mergeProps utility to resolve all defaultProps warnings fix(props): add mergeProps utility to resolve all defaultProps warnings Sep 9, 2024
Copy link

@coderabbitai coderabbitai bot left a 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

Comment on lines +18 to +32
/**
* 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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

批准更改并建议记录使用案例

mergeProp 函数的实现正确地处理了属性列表,并返回第一个非 undefined 值,后面的属性具有更高的优先级。这对于处理已弃用的属性非常有用。建议在文档中添加此函数的使用案例,以帮助开发者了解其在实际场景中的应用。

Copy link

codecov bot commented Sep 9, 2024

Codecov Report

Attention: Patch coverage is 68.96552% with 9 lines in your changes missing coverage. Please review.

Project coverage is 83.11%. Comparing base (cec2549) to head (3d7f7fb).
Report is 1 commits behind head on next.

Files with missing lines Patch % Lines
src/utils/merge-props.ts 60.86% 9 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants