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

RFC: meta information on which facet triggered re-run of hook #109

Closed
Shenato opened this issue Jan 11, 2023 · 1 comment
Closed

RFC: meta information on which facet triggered re-run of hook #109

Shenato opened this issue Jan 11, 2023 · 1 comment

Comments

@Shenato
Copy link
Contributor

Shenato commented Jan 11, 2023

The Problem

In some scenarios you need to keep track of more than one facet in one hook like useFacetEffect(), however the downside is you never really know which one of them triggered the current run of the effect, one option is is to split the effect, but sometimes that's not feasible depending on if the logic actually depends on more than one facet at the same time and they're not unrelated.

Proposed API change

The hook could accept a callback function overload whereby if the callback function has one more parameter than the facets passed to the hook it would keep track of the values and give you a perhaps meta object (name pending) with simple booleans for the facet's position in the dependency array which indicate which facet changed this run.

This should be an opt-in approach (by expecting an extra parameter in a X facet dependency hook), so we don't have to pay that cost in normal scenarios which are the abundant use-case for those hooks.

Example code below of how it can be used:

	useFacetEffect(
		(firstFacetValue, secondFacetValue, meta) => {
		        if(meta.changed[0]) {
		           // Do something if firstFacetValue is the facet that changed triggering this effect
		        }
	
	                if(meta.changed[1]) {
		           // Do something if secondFacetValue is the facet that changed triggering this effect
		        }
		},
		[],
		[firstFacet, secondFacet],
	)
@pirelenito
Copy link
Member

Closing this in favor of #122 . Feel free to re-open if that solution is not suficient.

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

No branches or pull requests

2 participants