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

How to destroy a reference? #419

Open
gbcreation opened this issue Feb 28, 2022 · 4 comments
Open

How to destroy a reference? #419

gbcreation opened this issue Feb 28, 2022 · 4 comments
Labels
❔ question General question

Comments

@gbcreation
Copy link
Contributor

It seems that just creating a new reference to a tree node is enough for getRefsResolvingTo() to return a Set with one Ref pointing to this tree node. My question is how can we destroy this ref?

In the Todo List example from the documentation about References, the reference to the selected Todo is somehow destroyed by setting selectedRef to undefined. But how to do that if the created Ref is not attached to a prop<Ref<Todo>> of an other model? It is possible to destroy directly the Ref itself?

@xaviergonz
Copy link
Owner

you mean a root ref or a custom one? if custom, how does it work?

@xaviergonz xaviergonz added the ❔ question General question label Mar 6, 2022
@gbcreation
Copy link
Contributor Author

It is a custom ref that uses a context in resolve() to resolve the reference to the target model. This latter is in model store (a simple list of models).

@xaviergonz
Copy link
Owner

In theory, as soon as the custom reference resolve function stops returning a resolved model (returns undefined) it should automatically be removed from the getRefsResolvingTo list.

Maybe you could add a blacklist in the context, make the custom ref return undefined when it is blacklisted and push something to that context blacklist when you want a ref to get "invalidated"?

@gbcreation
Copy link
Contributor Author

Thank you for the explanations and the suggestion.

as soon as the custom reference resolve function stops returning a resolved model (returns undefined) it should automatically be removed from the getRefsResolvingTo list.

This is the important point to know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
❔ question General question
Projects
None yet
Development

No branches or pull requests

2 participants