I found x in obj
dependencies will always trigger once the property is change, are there some reasons for it and can we do better?
#6050
StephenChips
started this conversation in
General Discussions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Example Code
Vue's version:
3.2.36
You can paste the code to CodeSandbox or any other online IDE to see the result.
Acutal result
Printed
true
on the console constantly.What does I expect
The true will be printed only once (when the watchEffect ran the effect function).
Reason
The
in
operator test if a property is in the object (and its prototype chain), it will only have two result:true
andfalse
. IMHO, I thinkeffect functions should only be run when the reactive properties' change cause watched expression to produce a new different result. Updating a existing property will not make a existed property disappear, and the result of the
in
expression itself will not change, so I think I may be it is not necessary to trigger the effect.Of course this is just my rough idea, if their are something I didn't consider yet, please leave your comment below.
Beta Was this translation helpful? Give feedback.
All reactions