toRaw - should cover all reactive objects ( ref, reactive,computed, etc)
What problem does this feature solve?
toRaw()
allow for an "escape hatch" to access the raw value of reactive
proxy , however there is no equivalent support for other "reactive" objects such as ref
or computed
.
ref and reactive are already mingled internally
let refThatActuallyWrapsReactiveObject = ref({a:1})
supporting a common way to access raw values of any of the supported *reactive envelopes types will improve the framework abilities to work with reactive objects and allow for greater control for developers.
What does the proposed API look like?
toRaw(obj: Reactive|Ref|Computed|... )
ref should be straight forward implementation
isRef(obj) {
return obj._rawValue
}
computed
is lazily evaluated, and toRaw should probably be as transparent as possible and should not trigger any effects or possibly the evaluation of the getter.
@posva I might not have been too clear, but this was not a question on how to get the raw value for a ref or computed it was a proposal to make toRaw work consistently whether you pass ref/computed/reactive object. as to extract the raw value and not trigger reactivity.
The ref wrapping a reactive object was just an example to show that ref and reactive are too close together, and yet they are treated differently by the toRaw
method.
I wonder was this issue closed, because my issue was misunderstood as question, or this proposal was considered and deemed not viable or useful.
That would be a breaking change though. That kind of feature request should go through an RFC in the rfcs repo anyway
ok, thanks for the feedback,
my rational was that toRaw at current state is used to bypass the reactivity tracking not sure what is the likelihood of someone passing a ref or computed into toRaw for giggles and expecting it not to be raw.
also if rfcs are the appropriate and recommended way to request features, then perhaps we should remove the options to post feature requests in the wizard of this repo.
created a discussion in the rfc repo https://github.com/vuejs/rfcs/discussions/366