Replies: 1 comment 1 reply
-
It is an interesting idea -- and one that is present in older frameworks like ko. It will be tricky for computed but also for CustomRefFor customRef the framework has zero control over how the ref works internally. ComputedIf the cached value is not dirty, extracting it is fast and nice. If it's dirty, I think returning an invalid cached value is a bad thing and will most likely lead to bugs. Notice there are 2 different tracking scopes going on here:
IMHO the 2nd scope is unrelated to the 1st and I don't think the computed object should be immutable. If you need to evaluate a computed bypassing its cache (so not tracking its own dependencies) it sounds like another new API to me. This is something KO didn't have, I'm curious if you have a use-case for that? API ideasIf we look at Knockout for prior art, it offers a Additionally, it provides an computed(() => {
// These are the dependencies (reads) that invalidate the computed
let id = person.id;
// The rest of the computation is not tracked, even if person is a reactive object with plenty of properties
return ignoreDependencies(() => {
return { name, age } = person;
});
}); Alternatives
|
Beta Was this translation helpful? Give feedback.
-
Objective
toRaw() should return the encapsulated raw value for other reactive types (ref,computed,etc) without triggering reactivity or causing side effects.
Currently
toRaw(value)
only supportreactive
object, and return thevalue
as is for anything else.What does the proposed API look like?
toRaw(obj: Reactive|Ref|Computed|... )
for Ref
extending logic for ref should be as simple as
for computed
there is an added complexity due to lazy evaluation and dirty state tracking,
there are few possible approaches :
for CustomRef ( feedback from: @jods4 )
Beta Was this translation helpful? Give feedback.
All reactions