Subscribe on changes!

Computed refactor

avatar
Apr 27th 2023

What problem does this feature solve?

Computed property gets too hard too intuitviely identify what reactives it depends on when there is too much login in

What does the proposed API look like?

create a second arugent to identify its dependencies just like react does, e.g computed(()=>, [denpendencies])

avatar
Apr 27th 2023

Just FYI for anyone else interested in this functionality, there is a composable in VueUse that does the same thing - computedWithControl.

Example from the docs:

import { computedWithControl } from '@vueuse/core'

const source = ref('foo')
const counter = ref(0)

const computedRef = computedWithControl(
  () => source.value, // watch source, same as `watch`
  () => counter.value, // computed getter, same as `computed`
)
avatar
Apr 30th 2023

Vue's computed properties will always work this way - tracking reactive dependencies automatically. Vue's reactivity at its heart is precisely about automatic dependency tracking. And as there are existing solutions in the ecosystem to solve this edge case, I can say that we don't see a need to make this a part of Vue core.