-
Notifications
You must be signed in to change notification settings - Fork 299
feat(notify): [notify] enhance notification function, add type definition and option interface, optimize code structure #3251
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
Conversation
…tion and option interface, optimize code structure
WalkthroughThe changes enhance the type safety and clarity of the Changes
Suggested labels
Suggested reviewers
Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
WARN GET http://10.0.0.28:4873/@antfu%2Feslint-config error (503). Will retry in 10 seconds. 2 retries left. This error happened while installing a direct dependency of /tmp/eslint ✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 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: 0
🧹 Nitpick comments (2)
packages/vue/src/notify/index.ts (2)
21-31
: Comprehensive NotifyOptions interface with one potential improvementGood job structuring the notification options with appropriate types. The interface is well-designed with all properties correctly marked as optional.
However, I notice the use of
any
forstatusIcon
and the catch-all[key: string]: any
property. While this provides flexibility, it reduces type safety.Consider using a more specific type for
statusIcon
if possible:- statusIcon?: any + statusIcon?: Component | VNode | HTMLElement
53-58
: Type-safe icon mapping with potential for improvementUsing
Record<NotifyType, any>
ensures type safety for the keys, but similar to earlier feedback, consider using a more specific type thanany
for the values.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/vue/src/notify/index.ts
(8 hunks)
🔇 Additional comments (12)
packages/vue/src/notify/index.ts (12)
18-19
: Well-defined TypeScript type definitionsThe addition of union types for notification types and positions is excellent for type safety. This ensures that only valid values can be used throughout the codebase.
33-48
: Well-structured state and instance interfacesThese interfaces clearly define the structure of notification state and instances, making the code more maintainable and self-documenting.
One observation: there appears to be potential redundancy between
$el
anddom
properties in the NotifyInstance interface, both representing HTML elements.Verify if both
$el
anddom
properties serve different purposes or if they could be consolidated.
51-51
: Properly typed array of notification instancesGood use of typing for the instances array, which improves type safety when working with notification instances.
60-65
: Well-typed duration mappingGood use of
Record<NotifyType, number>
to ensure type safety for both keys and values.
67-67
: Type-safe position listThe position list is correctly typed as an array of
NotifyPosition
, ensuring compile-time validation.
69-89
: Well-implemented debounce function with proper typingThe debounce function is properly typed and implements an async/await pattern with promises for cleaner asynchronous code. This is a good approach for handling debounced notifications.
91-99
: Type-safe notification creation with fallback valuesGood implementation of the notify function with proper type checking and fallbacks for unsupported values. The use of type assertions is appropriate given the optional nature of the properties.
102-103
: Safe handling of types in instance creationProper type assertions are used when working with the notification instance and its properties, ensuring type safety throughout the instance creation process.
Also applies to: 112-113, 128-129
139-147
: Clear return type declaration for Notify functionThe function signature clearly indicates that it can return either a notification instance directly or a function that returns a promise of a notification instance, accurately capturing the dual behavior.
149-153
: Improved type safety in close methodThe close method is now properly typed with optional callback, and the instance variable is correctly typed as potentially undefined.
169-169
: Safe DOM manipulation with optional chainingGood use of optional chaining (
?.
) when removing the element from its parent, which prevents errors if the parent node is null.
195-195
: Type-safe closeAll methodThe closeAll method is properly typed with a void return type, clearly indicating it doesn't return anything.
增强通知功能,添加类型定义和选项接口,优化代码结构
PR
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information
Summary by CodeRabbit