-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Data: Expose registered selectors as functions #5007
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
Conversation
|
Added upgrade path for deprecated usage in 338e5a8. |
atimmer
left a comment
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 really like this. Makes it much more discoverable. In a similar version I explored in #4421 I had all selectors exposed at wp.data.selectors. Did you also consider this?
Anyhow, looks good to me.
|
This is how I always wanted to have it shaped 💯 |
mcsf
left a comment
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.
A worthwhile change for me. 👌
| selectors[ reducerKey ] = newSelectors; | ||
| const store = stores[ reducerKey ]; | ||
| const createStateSelector = ( selector ) => ( ...args ) => selector( store.getState(), ...args ); | ||
| selectors[ reducerKey ] = mapValues( newSelectors, createStateSelector ); |
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.
Initially, I wanted to avoid having to create a wrapper for each selector but I do see the DevX benefits from this new API
e306914 to
08a47de
Compare
08a47de to
0cbecd1
Compare
Related: #4105
This pull request seeks to update the data module selector pattern to expose selectors as functions directly, not invoke via named string arguments.
Before:
After:
Implementation notes:
Since this was included in 2.1.0 of the plugin, do we need to include a deprecation upgrade path?Added in 338e5a8.Testing instructions:
Ensure unit tests pass:
Verify there are no regressions in the current usage of data module
select.