Propose store-specific useSelect and useDispatch#26723
Closed
adamziel wants to merge 2 commits into
Closed
Conversation
|
Size Change: +1.08 kB (0%) Total Size: 1.21 MB
ℹ️ View Unchanged
|
Contributor
Author
|
Probably just a micro-optimization that may not be worth pursuing at this point but I just had this idea so I'll drop it here: A declarative shorthand notation would make it possible keep track of all the nullary selectors that are currently listened to. This means we could recompute them only once on every store change instead of once per |
Contributor
Author
|
I just turned this back into a draft, let's see if we can get alignment around #26692 first |
Contributor
Author
|
Closing for now, see #26692 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
🚧 Proof of Concept for discussion purposes! 🚧 some tests are expected to fail for now 🚧
This proposal is building on top of the ideas from #26692.
Just to reiterate:
useSelectscoped to an entire registry means a lot of unnecessary dirty-checking, the more granular we can get the faster things can get.useDispatchalready requires a store argument, why not makeuseSelectAPI consistent with that?This PR proposes the following API change:
Before
After
That's still kind of repetitive so I thought, why not have a shorthand?
After, but using a shorthand notation
Also, to keep things consistent, useDispatch would also be package-specific like this:
Notes
At the moment, every module exports a member called
useSelect. How about exporting a module-specific name such asuseEditPostSelect? This would enable IDEs to automatically import these.Shorthand notation accepts a list of strings. That is okay but potentially prone to typos:
Shorthand notation returns an array ordered in the same way as input. That could contribute to some off-by-1 indexing errors down the road. Now I think about it more, it could easily return an object keyed by selector names like this: