Export RefImpl
What problem does this feature solve?
I would like to extend RefImpl
to create a Ref
which can hold more state.
Currently I would have to use customRef
because I can't create a valid Ref
object by myself without knowing RefSymbol
, which is not exported either.
// Use the provided getters/setters
class MyRef<T> extends RefImpl<T>{
get value(){
//... do stuff
return super.value;
}
//...
}
// Override the tracking
class MyRef2<T> extends RefImpl<T>{
get value(){
track(toRaw(this), "get" /* GET */, 'value');
//... do stuff
return this._value;
}
//...
}
What does the proposed API look like?
Just export the class and maybe look into setting properties as private or protected.
I just found out I can use track
and trigger
to get everything I need to create a custom reactive class.
For now, RefImpl
is an implementation detail, and this implementation can change in future. In fact, refs weren't implemented as class instances until RC.7.
It seems like it's not being leaked to public API intentionally.
This is intentional. The only reason class being used internally is performance. It's not meant to be extended. Use customRef
.