Subscribe on changes!

isComputedRef(any)

avatar
Oct 27th 2022

What problem does this feature solve?

There is already isRef utility to check variable is Ref.. but as I am using refs in my composable as readonly, so I am supporting also computedRefs as input... pattern taken from docs:

if (isRef(url)) {
    // setup reactive re-fetch if input URL is a ref
    watchEffect(doFetch)
  } else {
    // otherwise, just fetch once
    // and avoid the overhead of a watcher
    doFetch()
  }

So I want to augment that not only if (isRef(url)) but also if (isComputedRef(url))`

What does the proposed API look like?

It can be either separate util: isComputedRef() or it could be parameter of isRef(url, true)

avatar
Oct 27th 2022

Also I don't see limitation, why unref() could not return value of ComputedRef instance 🤔

avatar
Oct 27th 2022

computed properties are refs. Consequently, isRef and unref already work with computed properties.