-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
useSelect: normalise getting selectors for callbacks #31078
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,14 +23,8 @@ import { getPasteEventData } from '../../utils/get-paste-event-data'; | |
import { store as blockEditorStore } from '../../store'; | ||
|
||
export function useNotifyCopy() { | ||
const { getBlockName } = useSelect( | ||
( select ) => select( blockEditorStore ), | ||
[] | ||
); | ||
const { getBlockType } = useSelect( | ||
( select ) => select( blocksStore ), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here too. We're returning the entire selector list. |
||
[] | ||
); | ||
const { getBlockName } = useSelect( blockEditorStore ); | ||
const { getBlockType } = useSelect( blocksStore ); | ||
const { createSuccessNotice } = useDispatch( noticesStore ); | ||
|
||
return useCallback( ( eventType, selectedBlockClientIds ) => { | ||
|
@@ -84,7 +78,7 @@ export function useClipboardHandler() { | |
getSelectedBlockClientIds, | ||
hasMultiSelection, | ||
getSettings, | ||
} = useSelect( ( select ) => select( blockEditorStore ), [] ); | ||
} = useSelect( blockEditorStore ); | ||
const { flashBlock, removeBlocks, replaceBlocks } = useDispatch( | ||
blockEditorStore | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -212,27 +212,15 @@ export function onHTMLDrop( | |
* @return {Object} An object that contains the event handlers `onDrop`, `onFilesDrop` and `onHTMLDrop`. | ||
*/ | ||
export default function useOnBlockDrop( targetRootClientId, targetBlockIndex ) { | ||
const hasUploadPermissions = useSelect( | ||
( select ) => select( blockEditorStore ).getSettings().mediaUpload, | ||
[] | ||
); | ||
const { | ||
canInsertBlockType, | ||
getBlockIndex, | ||
getClientIdsOfDescendants, | ||
hasUploadPermissions, | ||
} = useSelect( ( select ) => { | ||
const { | ||
canInsertBlockType: _canInsertBlockType, | ||
getBlockIndex: _getBlockIndex, | ||
getClientIdsOfDescendants: _getClientIdsOfDescendants, | ||
getSettings, | ||
} = select( blockEditorStore ); | ||
|
||
return { | ||
canInsertBlockType: _canInsertBlockType, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To have the full picture, this could also be refactored as: return {
...pick( select( blockEditorStore ), [ 'canInsertBlockType, getBlockIndex, getClientIdsOfDescendants ),
hasUploadPermissions: getSettings().mediaUpload,
}; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's doesn't solve my main problem: it's awkward to return selector functions in a mapping. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, it's a workaround. I think for |
||
getBlockIndex: _getBlockIndex, | ||
getClientIdsOfDescendants: _getClientIdsOfDescendants, | ||
hasUploadPermissions: getSettings().mediaUpload, | ||
}; | ||
}, [] ); | ||
|
||
} = useSelect( blockEditorStore ); | ||
const { | ||
insertBlocks, | ||
moveBlocksToPosition, | ||
|
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.
Especially here, the benefits are clear.