Subscribe on changes!

watch: there's no type error when pass through a getter function with primitive value(not the prop of reactive object)

avatar
Dec 8th 2020

Version

Reproduction link

https://codesandbox.io/s/watch-getter-forked-9t0js?file=/src/App.vue

Steps to reproduce

  • click the button , it invoke the increment function
  • apparently , it won't trigger the watch callback and it's expectable

What is expected?

when we pass a getter function with just primitive value (not a prop of a reactive object which is also a primitive type ), it would be better to have a type error

What is actually happening?

we can also pass the getter function like : let a = 1 watch(()=>a, ....)

we know it doesn't , but there's not type error


I've watched the source code, it seems no way to note the value whether from a reactive object or just an ordinary value. maybe we create a new string tag in GET HANDLER, but I don't think it worth the cost because it seems an edge case Am I overreact about this issue?

avatar
Dec 8th 2020

This is a feature: the point is to read from reactive data and return a value, but the value returned could be a primitive like:

watch(
      () => 'n:' + obj.count + `(${count})`,
      (countSentence, oldCountSentence) => {
        console.log(countSentence);
      }
    );

Yet this will trigger whenever obj.count changes