Add signal API Design to reactivity #747
Replies: 2 comments 2 replies
-
Someone has created a discussion dedicated to I've commented there that Vue provides the primitives to create that function today if you want to, and I agree it would be a nice addition to Vue core (and more efficient). When it comes to Signal-like apis (pairs of getter/setter functions), I feel like this is a matter of style, different frameworks have taken different approaches -- and none is strictly better in all aspects. Thing is, Vue is a mature framework with many users, and large projects in production. So refs are not going anywhere. |
Beta Was this translation helpful? Give feedback.
-
@jods4 In my opinion, the current api provokes passing refs as parameters, instead of explicitly declaring methods for receiving and updating. An example from the documentation on working with reactivity https://vuejs.org/guide/components/provide-inject.html#working-with-reactivity VueUse It seems to me that this is one of the reasons for the complex
https://pinia-colada.esm.dev/cookbook/migration-tvq.html#Using-ref-and-computed-in-queryKey It's a little disappointing that initially the update/get methods existed, but for some reason they were hidden in get/set. You say that many users like to use the current api. Perhaps they just didn't have the opportunity to compare other options))). I don't see an advantage in writing
For me, on the contrary, it's reducing the number of options from MaybeRefOrGetter to MaybeGetter or Getter. My suggestion is to fix the problem in the kernel, rather than additional utilities that increase complexity. |
Beta Was this translation helpful? Give feedback.
-
Untrack
When used inside a watchEffect or computed, any state read inside fn will not be treated as a dependency.
Like solid, svelte, preact, angular
Signal
It would be very useful to see a signals API similar to the implementation in solid.
Or implement explicit methods for inserting and getting the value
const [count, setCount] = createSignal(0)
The Problem
Readonly signal
Many libraries were forced to use
readonly()
, which hurts performance, or find other ways. Explicitly separating getters and setters fixes this complexity.Example: TanStack query discussions
More flexible signal update
When updating a signal based on its previous value, the code for getting it is called first, then the new value is set. In this case, the signal is added to the effect's dependency list.
Better Dx for writing composables
Often, passing and updating reactive variables in composables requires additionally wrapping them in functions.
If such methods were initially available, this would not be necessary
Simplifying MaybeRefOrGetter
Currently, it is a popular practice to process 3 different parameters: Ref, Function, non-ref variable.
For this, the helpers
type MaybeRefOrGetter
andtoValue
have been added.Example vueuse
Thanks to the signals API, we have two types of data for options in composable objects.
a new api could popularize this method
Beta Was this translation helpful? Give feedback.
All reactions