-
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
useSettings: extract selector #58354
Conversation
...paths | ||
), | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
[ clientId, ...paths ] |
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.
Whether we spread the dependencies here or in useMemo
, it should be the same.
@@ -26,7 +26,7 @@ import { shadow as shadowIcon, Icon, check } from '@wordpress/icons'; | |||
/** | |||
* Internal dependencies | |||
*/ | |||
import { mergeOrigins } from '../use-settings'; | |||
import { mergeOrigins } from '../../store/private-selectors/get-inherited-settings'; |
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.
Maybe this should be moved to a utils file, but I left it for now, there's only two uses.
Size Change: +108 B (0%) Total Size: 1.7 MB
ℹ️ View Unchanged
|
0232d06
to
0ae33ce
Compare
356ad35
to
34c2821
Compare
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.
Another nice idea 👍
); | ||
} | ||
|
||
export function getInheritedSettings( state, clientId, ...paths ) { |
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 don't like the name very much, getBlockSettings
is probably better. But it doesn't matter that much for a private API.
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.
Changed it
What?
This PR splits out the selector from
useSettings
, so it can be combined with otheruseSelect
selectors in a single subscription.Why?
There's a use case for inner blocks, reducing the blockEditor store subscriptions from 2 to 1, but there's also used cases in some blocks.
First run -10% type.
ALSO, the useSettings hook cannot be called conditionally, but the selector can. So you can do:
I've seen a few places where that could be useful to avoid even more subscriptions.
How?
I created a new
getBlockSettings
private selector. Not sure if the naming is correct.Testing Instructions
E2e tests should pass.
Testing Instructions for Keyboard
Screenshots or screencast