-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Reactivity: add and expose a shallow function #674
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm working on this one now. |
I'm really wishing for a Typical use case is to store immutable/non-reactive (big) arrays or (deep) objects (for perf). E.g. if you want to display a large list and plan on setting the ref to a new array to avoid watching all array indexes (ties in with your comments about my fast mutable array). Of course, it's trivial to build one out of |
This commit adds a new function called `ref` to the core of the codebase. The `ref` function allows developers to create reactive ref objects, which include a `value` property and a `reset` method. Internally, the `ref` function utilizes the existing `reactive` function to create the reactive object. This change addresses the need for an easier way to create reactive ref objects. Previously, developers had to manually implement this functionality, leading to code duplication and potential errors. With the `ref` function, creating reactive ref objects becomes simpler and more consistent. Details: - Define the `ref` function to create reactive ref objects - Include a `value` property in the ref object - Implement the `reset` method to reset the value property to its initial value Footer: - Closes: vuejs#674
What problem does this feature solve?
In addition to
reactive
,readonly
andshallowReadonly
, add the missingshallow
method and export it.If one desires to a have reactive object, whose contents are not reactive (as an optimization or for explicitness), one has to call
markNonReactive
on every value set on areactive
object.This is ok when initializing the object, but becomes a lot of effort when it has to be put at any place where a property is set to a new value.
The code to implement
shallow
already exists, ascreateGetter
andcreateSetter
accept two argumentsisReadonly
andshallow
(consistency: why notisShallow
?). In fact it's the only combination of flags out of the four possible that is missing.What does the proposed API look like?
shallow
method, makes a reactive object likereactive
,readonly
andshallowReadonly
but doesn't make values returned byget
reactive.The text was updated successfully, but these errors were encountered: