Closed yisar closed 3 years ago
ref
or reactive
was a rather perplexing discovery
Using one function for both getter and setter will introduce a pattern which (IMO) not very common in Vue and also have mental burden.
This is not Vue
style. (using function
everywhere is disgusting to me)
Vue 3 is out. Ref is here to stay. And introducing another official way of handling their use case would be a disservice to the community.
While I see this could be nice for those that like it's style, the window for discussing such an alternative for core primitives such as ref()
has closed weeks or even months ago.
@yisar if you really like that style, though, you can trivally do it in your apps:
import { ref } from "vue"
function r(value) {
const data = ref(value)
return function () {
if (arguments.length === 0)
return data.value
else
data.value = arguments[0]
}
}
// Now you can do:
const count = r(0)
count() == 0
count(count() + 1)
count() == 1
@jods4
The mental burden of ref and reactive is too heavy, and its design is very bad
The apply hook is the only way to solve this problem
Its implementation is very simple, just need to integrate get and set into apply.
Please consider carefully, if you can, I will propose RFC and corresponding implementation.