-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Merge selector-binding code (except resolvers) into a new bindSelector function #51176
Conversation
Size Change: -10 B (0%) Total Size: 1.39 MB
ℹ️ View Unchanged
|
Flaky tests detected in cbf35aa. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5146430407
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice cleanup overall 👍
I've left a suggestion about abstracting the remaining repetition, let me know what you think.
const boundSelector = ( ...args ) => { | ||
const state = store.__unstableOriginalGetState(); | ||
return selector( state.root, ...args ); | ||
}; | ||
boundSelector.hasResolver = false; | ||
return boundSelector; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that this part is the same as bindMetadataSelector()
, the only difference being where the selector reads state from, I wonder if we could further abstract this fragment into a separate function that receives the state tree name. Then we could reuse that in both bindSelector
and bindMetadataSelector
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I originally did this, if you look at the implementation in #51051, there are calls bindSelector( 'root' )
and bindSelector( 'metadata' )
.
But now I plan to diverge the two versions even more. The metadata selectors only need the binding, we cal remove the hasResolver
part. And when binding the classic selector, I would like to try merging the resolver fulfillment also into bindSelector
. So that there is only one wrapper and when in debugger, you step into a call like:
registry.select( 'core/block-editor' ).getBlocks();
you are just one step away from the actual implementation of getBlocks
. Until recently, you'd have to step through several layers of wrappers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚀 Thanks!
Counterpart of #51161, which did a similar refactor for actions. This one is for selectors.
The
mapSelectors
function is removed in favor of callingmapValues( selectors, bindSelector )
directly. And in the private selector proxy, we map only the one selector that the getter is requesting, not all of them.This will be useful in #51051 to create stable selector references returned from
registry.select
.Also, after this PR a selector (without a resolver) is mapped just once to produce the result returned by
registry.select
. That makes selectors better debuggable, when stepping into selectors, we get into the implementation code faster, with less wrapper boilerplate.