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

refactor: simplify traverse() for deep watchers #10795

Merged
merged 1 commit into from Apr 29, 2024

Conversation

skirtles-code
Copy link
Contributor

This PR simplifies the logic in traverse(). It should also shave a few bytes off the bundle.

The current implementation of traverse() takes two numbers, the depth and the currentDepth. The function calls itself recursively, incrementing currentDepth at each stage and then comparing that to depth.

But there's no need to use two numbers. Just one is enough. Each recursion can just decrement depth and then check whether it is still greater than 0.

For deep: true, a depth value of Infinity can be used, rather than trying to handle it specially.

The current depth logic was originally introduced in #9928, partly in preparation for adding #9572. While my proposed changes will introduce small conflicts with that second PR, I believe they are easily fixable, just by treating deep: true as deep: Infinity.

Copy link

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 90.7 kB (-30 B) 34.5 kB (-12 B) 31.1 kB (+7 B)
vue.global.prod.js 148 kB (-30 B) 53.8 kB (-11 B) 48.1 kB (+16 B)

Usages

Name Size Gzip Brotli
createApp 50.7 kB (-30 B) 19.8 kB (-11 B) 18.1 kB (-15 B)
createSSRApp 54.1 kB (-30 B) 21.2 kB (-9 B) 19.3 kB (-19 B)
defineCustomElement 53 kB (-30 B) 20.6 kB (-8 B) 18.8 kB (-26 B)
overall 64.4 kB (-30 B) 24.9 kB (-6 B) 22.6 kB (-4 B)

@yyx990803 yyx990803 merged commit 2d56816 into vuejs:main Apr 29, 2024
11 checks passed
yangmingshan added a commit to vue-mini/vue-mini that referenced this pull request Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants