Skip to content
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

Export RefImpl #2025

Closed
SebastianSpeitel opened this issue Sep 1, 2020 · 5 comments
Closed

Export RefImpl #2025

SebastianSpeitel opened this issue Sep 1, 2020 · 5 comments

Comments

@SebastianSpeitel
Copy link

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.

@SebastianSpeitel
Copy link
Author

I just found out I can use track and trigger to get everything I need to create a custom reactive class.

@leopiccionia
Copy link
Contributor

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.

@posva
Copy link
Member

posva commented Sep 1, 2020

Closing since track and trigger solve the original problem

@posva posva closed this as completed Sep 1, 2020
@yyx990803
Copy link
Member

This is intentional. The only reason class being used internally is performance. It's not meant to be extended. Use customRef.

@SebastianSpeitel
Copy link
Author

The best solution I found is to create a customRef<void> in the constructor and store the given track and trigger callbacks as instance properties, so I can use them whenever I want.

Storing the returned Ref<void> as a property gives me the ability to do watch(myinstance.ref).

@github-actions github-actions bot locked and limited conversation to collaborators Nov 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants