-
Notifications
You must be signed in to change notification settings - Fork 190
refactor(BubbleList): 重构布局与自动滚动逻辑 #284
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
base: sender-test
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -38,9 +38,20 @@ console.log('Hello, world!'); | |||||||||||||||||||||||||||||||||||||||
| avatar: isUser ? avatar1 : avatar2, | ||||||||||||||||||||||||||||||||||||||||
| avatarSize: '32px' | ||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| bubbleItems.value.push(obj as MessageItem); | ||||||||||||||||||||||||||||||||||||||||
| bubbleListRef.value.scrollToBottom(); | ||||||||||||||||||||||||||||||||||||||||
| ElMessage.success(`条数:${bubbleItems.value.length}`); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| let num = 50; | ||||||||||||||||||||||||||||||||||||||||
| const T = setInterval(() => { | ||||||||||||||||||||||||||||||||||||||||
| if (num < 1) { | ||||||||||||||||||||||||||||||||||||||||
| clearInterval(T); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| bubbleItems.value[bubbleItems.value.length - 1].content += | ||||||||||||||||||||||||||||||||||||||||
| '欢迎使用 Element Plus X .'; | ||||||||||||||||||||||||||||||||||||||||
| num--; | ||||||||||||||||||||||||||||||||||||||||
| }, 100); | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+46
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Variable shadowing and potential performance issues. The local variable Consider these improvements: - let num = 50;
- const T = setInterval(() => {
- if (num < 1) {
- clearInterval(T);
+ let counter = 50;
+ const intervalId = setInterval(() => {
+ if (counter < 1 || bubbleItems.value.length === 0) {
+ clearInterval(intervalId);
+ return;
}
bubbleItems.value[bubbleItems.value.length - 1].content +=
'欢迎使用 Element Plus X .';
- num--;
+ counter--;
}, 100);This addresses variable shadowing, follows naming conventions, and adds a safety check for empty arrays. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| function handleOnComplete(_self: unknown) { | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
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.
Potential memory leak with IntersectionObserver.
The global
intersectionObservervariable could lead to memory leaks if multiple observers are created without proper cleanup.Consider this improvement:
Also consider adding a cleanup in
onBeforeUnmountto ensure any active observer is disconnected.📝 Committable suggestion
🧰 Tools
🪛 ESLint
[error] 119-119: Expect newline after if
(antfu/if-newline)
[error] 133-133: Closing curly brace appears on the same line as the subsequent block.
(style/brace-style)
🤖 Prompt for AI Agents