Reactivity Transform Unification #413
Replies: 4 comments 11 replies
-
Curious what the implementation you have in mind, as the two transforms are quite different? |
Beta Was this translation helpful? Give feedback.
-
This is nice as these methods are used super-often. If you define some common ref-generating helpers in your project -- or from a lib -- it'd be nice to be able to reduce the calls nesting by applying a similar treatment to them. I'm thinking of stuff like What if any undefined function call whose name starts with
Example: import { debounceRef } from "utils"
// Compiled the same way as $(debounceRef("", 300))
const search = $debounceRef("", 300) |
Beta Was this translation helpful? Give feedback.
-
This looks great, I like the removal of |
Beta Was this translation helpful? Give feedback.
-
This has now been revised into the original ref sugar v2 discussion #369 . |
Beta Was this translation helpful? Give feedback.
-
Reactivity Transform Unification
We have went through quite a few iterations on the ref transform (latest at #369), and recently also implemented the props transform (also experimental). Based on the feedback, it seems to be better to unify both proposals under a single concept. I'm calling it "Vue Reactivity Transform".
The main concerns we heard for the ref sugar transform is the idea of
$ref
being the shorthand of$(ref())
. Some users seem to think the latter is completely unnecessary, while some think having shorthands for only a subset the API is inconsistent.I believe these are minor conceptual hurdles and the underlying mental model is solid. But we do need to find the best way to introduce the transform's mental model to new users. Here I am proposing some final tweaks, mostly on how the transform should be explained / documented:
Every ref-creating API method will have a
$
-prefixed equivalent, which creates reactive variables. These methods include:ref
computed
shallowRef
customRef
toRef
Definition: a reactive variable is a variable that can be used like a normal variable while retaining reactivity in the current function scope. It will be tracked when referenced, and can trigger reactive effects (re-render and watcher callbacks) when assigned. They are compile-time sugar and backed by actual refs under the hood.
$()
is a utility macro that can be used to:$()
also works ondefineProps
:When used on
defineProps
, destructure default values will be compiled into runtime prop default values:This allows declaring props default values even when using pure-TS props declarations, and allows us to get rid of
withDefaults
.$$()
is the reverse of$()
which converts reactive variables into raw refs.toRef
call on the props object:Note: this is not a new proposal - it's an amendment / alternative explanation of #369 + props destructure transform. Please make sure to read #369 before posting a comment.
Beta Was this translation helpful? Give feedback.
All reactions