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

Add useRefs hook #17

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

rimuy
Copy link
Contributor

@rimuy rimuy commented Feb 10, 2024

Proposed changes

As your game UI grows, it becomes really difficult to track the instances you want to filter the references - If I had a tree of functions that returns instances, and want to capture one of its descendants, I'd have to pass my ref table all the way down the tree just so I could set the reference to be that one instance.

The proposed new hook called useRefs, eliminates this issue by grabbing the ref table in the current useInstance call. This can only be used inside useInstance and will error if done otherwise.

Additional comments

  • Adds the missing parameter type for useInstance's callback.
  • Freezes the ref table after useCallback is done executing as it shouldn't be mutated anyways. (New hook's behavior also depends on this)

@rimuy rimuy changed the title Userefs hook Add useRefs hook Feb 10, 2024
Copy link
Member

@Ukendio Ukendio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It needs some tests, primarily because it is new and unproven API but also want to see examples of how it would be used in several scenarios.

@rimuy rimuy requested a review from Ukendio February 10, 2024 18:57
Copy link
Member

@LastTalon LastTalon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you link this to an issue to discuss the actual use case of this hook?

src/Runtime.lua Outdated Show resolved Hide resolved
@rimuy rimuy mentioned this pull request Feb 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants