Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

refactor(vOnClickOutside): use weakMap for stop function instead of mutating element #4755

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 2 commits into from
May 16, 2025

Conversation

jiangsongyang
Copy link
Contributor

Description

optimize the vOnClickOutside method , remove handler form element and save handle to weak map.

This can prevent external operations on the methods mounted on the element, thereby avoiding some unexpected behaviors

@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. directive labels May 15, 2025
},
unmounted(el) {
(el as any).__onClickOutside_stop()
const stop = stopClickOutsideMap.get(el)
if (stop && typeof stop === 'function') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

if it isn't a function, it means controls was true, right?

so we should just call stop() on it I think:

if (typeof stop === 'function') {
  stop();
} else {
  stop.stop(); // but call the variable something better
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thx for your reply!

Yes, you're right. I overlooked this logic branch and I will add this new logic

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added this logic. thx you for your guidance!

@antfu antfu changed the title refactor: optimize the vOnClickOutside method , remove handler form element and save handle to weak map. refactor(vOnClickOutside): use weakMap for stop function instead of patching attr May 16, 2025
@antfu antfu changed the title refactor(vOnClickOutside): use weakMap for stop function instead of patching attr refactor(vOnClickOutside): use weakMap for stop function instead of mutating element May 16, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label May 16, 2025
@antfu antfu added this pull request to the merge queue May 16, 2025
Merged via the queue into vueuse:main with commit 6f88000 May 16, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
directive lgtm This PR has been approved by a maintainer size:S This PR changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.