core icon indicating copy to clipboard operation
core copied to clipboard

feat(apiWatch): support passing the `number` type for `deep` to control the watch depth

Open Alfred-Skyblue opened this issue 2 years ago • 6 comments

RFC: https://github.com/vuejs/rfcs/discussions/597

fixed #9916

Support passing watch deep option as a number type, indicating the depth to which the object should be monitored. This allows control over the depth of object access in the watch function. In scenarios with large datasets, this can significantly improve performance.

Alfred-Skyblue avatar Nov 08 '23 10:11 Alfred-Skyblue

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 95.4 kB (+5.24 kB) 36.4 kB (+1.82 kB) 32.7 kB (+1.6 kB)
vue.global.prod.js 153 kB (+6.21 kB) 56.1 kB (+2.09 kB) 50 kB (+1.94 kB)

Usages

Name Size Gzip Brotli
createApp 53 kB (+3.35 kB) 20.6 kB (+1.11 kB) 18.8 kB (+988 B)
createSSRApp 56.9 kB (+3.73 kB) 22.2 kB (+1.26 kB) 20.2 kB (+1.12 kB)
defineCustomElement 55.3 kB (+3.35 kB) 21.4 kB (+1.15 kB) 19.5 kB (+995 B)
overall 66.5 kB (+3.4 kB) 25.6 kB (+1.13 kB) 23.3 kB (+1.07 kB)

github-actions[bot] avatar Nov 08 '23 10:11 github-actions[bot]

Now have some conflicts after #9928

Also, I think it might be more concise to simply allow passing a number to deep, since the presence of depth implies deep: true:

// infinite depth
watch(src, () => {}, { deep: true })

// explicit depth
watch(src, () => {}, { deep: 1 })

yyx990803 avatar Dec 30 '23 10:12 yyx990803

Due to the consideration that users might have previously passed "deep" as a number in their usage, which was mistakenly treated as true in the previous implementation, if we now interpret "deep number" as referring to depth, the earlier practice of passing "deep" as a number would result in inconsistency. Of course, such usage was incorrect in the past. Should we take this into account? If we choose not to consider this, recognizing "deep" as referring to depth would be a more reasonable design approach.

Alfred-Skyblue avatar Dec 30 '23 12:12 Alfred-Skyblue

That's a good point. I think we can add a warning in a 3.4 patch that checks for deep with number values and warn users that it will be treated as depth in a future version.

yyx990803 avatar Dec 30 '23 13:12 yyx990803

Agreed. It's a good plan.

Alfred-Skyblue avatar Dec 30 '23 14:12 Alfred-Skyblue

This feature is very useful for me. awesome!

wjp980108 avatar May 14 '24 02:05 wjp980108

I don't want to annoy you guys, but I'm curious, since 3.5 already has some alpha releases.. is there still a chance this goes into 3.5? I'd love to use this feature 😀

hubdidub avatar Jul 29 '24 21:07 hubdidub