Skip to content

Add useRefs hook#17

Open
rimuy wants to merge 6 commits into
matter-ecs:mainfrom
HylianBasement:userefs-hook
Open

Add useRefs hook#17
rimuy wants to merge 6 commits into
matter-ecs:mainfrom
HylianBasement:userefs-hook

Conversation

@rimuy

@rimuy rimuy commented Feb 10, 2024

Copy link
Copy Markdown
Contributor

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

@Ukendio Ukendio left a comment

Copy link
Copy Markdown
Member

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

@LastTalon LastTalon left a comment

Copy link
Copy Markdown
Member

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?

Comment thread src/Runtime.lua Outdated
@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