Subscribe on changes!

toRaw - should cover all reactive objects ( ref, reactive,computed, etc)

avatar
Jul 29th 2021

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.

avatar
Jul 30th 2021

It's toRaw(aRef.value) or toRaw(unref(aRef.value)).

avatar
Jul 30th 2021

@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.

avatar
Jul 30th 2021

That would be a breaking change though. That kind of feature request should go through an RFC in the rfcs repo anyway

avatar
Jul 30th 2021

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.

avatar
Jul 30th 2021

created a discussion in the rfc repo https://github.com/vuejs/rfcs/discussions/366