-
-
Notifications
You must be signed in to change notification settings - Fork 364
feat(Toast): support async update content use same option #6037
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9e833de
doc: 重构代码
ArgoZhang 6345ef9
doc: 更新参数说明文档
ArgoZhang 2a3528f
refactor: 移除不使用的服务
ArgoZhang 0098044
doc: 增加线程阻塞通知示例
ArgoZhang 364d875
feat: 增加 Toast 更新脚本
ArgoZhang 616e7c4
refactor: 代码优化
ArgoZhang ddf2d4c
refactor: 支持内容动态更新逻辑
ArgoZhang 2c378a3
doc: 增加多语言支持
ArgoZhang 7d14803
refactor: 修复示例
ArgoZhang 9951283
doc: 更新示例代码
ArgoZhang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,7 @@ export function init(id, invoke, callback) { | |
| return toast.toast._config.autohide | ||
| } | ||
|
Contributor
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. issue (bug_risk): Event handler for 'transitionend' may be attached multiple times. Attaching a new listener on each update can cause duplicate handlers, triggering toast.hide() repeatedly and leaking memory. Consider removing existing handlers or using a one-time listener. |
||
| } | ||
| Data.set(id, toast) | ||
| Data.set(id, toast); | ||
|
|
||
| if (toast.showProgress()) { | ||
| toast.progressElement = toast.element.querySelector('.toast-progress') | ||
|
|
@@ -31,6 +31,25 @@ export function init(id, invoke, callback) { | |
| toast.toast.show() | ||
| } | ||
|
|
||
| export function update(id) { | ||
| const t = Data.get(id); | ||
| const { element, toast } = t; | ||
| const autoHide = element.getAttribute('data-bs-autohide') !== 'false'; | ||
| if(autoHide) { | ||
| const delay = parseInt(element.getAttribute('data-bs-delay')); | ||
| const progressElement = element.querySelector('.toast-progress'); | ||
|
|
||
| toast._config.autohide = autoHide; | ||
| toast._config.delay = delay; | ||
|
|
||
| progressElement.style.width = '100%'; | ||
| progressElement.style.transition = `width linear ${delay / 1000}s`; | ||
| EventHandler.on(progressElement, 'transitionend', e => { | ||
| toast.hide(); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| export function dispose(id) { | ||
| const toast = Data.get(id) | ||
| Data.remove(id) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 creating a new ToastOption instance for each toast step instead of reusing and mutating a shared field.
Consider avoiding the shared, mutable
_optionand instead build a freshToastOptionfor each step (or extract a small factory helper). This keeps each toast’s state isolated and makes the flow easier to follow.For example, you can extract a helper:
Then rewrite
OnAsyncClickwithout mutating a field:This removes the mutable
_optionand makes each toast instantiation self-contained.