Skip to content

Commit

Permalink
Improve typing performance (#23825)
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad authored Jul 9, 2020
1 parent 7569561 commit 587b018
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
12 changes: 4 additions & 8 deletions packages/block-editor/src/components/block-draggable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,17 @@ const BlockDraggable = ( {
onDragStart,
onDragEnd,
} ) => {
const { srcRootClientId, index, isDraggable } = useSelect(
const { srcRootClientId, isDraggable } = useSelect(
( select ) => {
const {
getBlockIndex,
getBlockRootClientId,
getTemplateLock,
} = select( 'core/block-editor' );
const { getBlockRootClientId, getTemplateLock } = select(
'core/block-editor'
);
const rootClientId = getBlockRootClientId( clientIds[ 0 ] );
const templateLock = rootClientId
? getTemplateLock( rootClientId )
: null;

return {
index: getBlockIndex( clientIds[ 0 ], rootClientId ),
srcRootClientId: rootClientId,
isDraggable: 'all' !== templateLock,
};
Expand Down Expand Up @@ -64,7 +61,6 @@ const BlockDraggable = ( {

const transferData = {
type: 'block',
srcIndex: index,
srcClientIds: clientIds,
srcRootClientId,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function SpacingPanelControl( { children, ...props } ) {
const isSpacingEnabled = useSelect( ( select ) => {
const { getSettings } = select( 'core/block-editor' );
return get( getSettings(), '__experimentalEnableCustomSpacing' );
} );
}, [] );

if ( ! isSpacingEnabled ) return null;

Expand Down
43 changes: 24 additions & 19 deletions packages/block-editor/src/components/use-block-drop-zone/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ function parseDropEvent( event ) {
let result = {
srcRootClientId: null,
srcClientIds: null,
srcIndex: null,
type: null,
};

Expand Down Expand Up @@ -176,28 +175,32 @@ export default function useBlockDropZone( {
} ) {
const [ targetBlockIndex, setTargetBlockIndex ] = useState( null );

function selector( select ) {
const {
getBlockListSettings,
getClientIdsOfDescendants,
getSettings,
getTemplateLock,
} = select( 'core/block-editor' );
return {
orientation: getBlockListSettings( targetRootClientId )
?.orientation,
getClientIdsOfDescendants,
hasUploadPermissions: !! getSettings().mediaUpload,
isLockedAll: getTemplateLock( targetRootClientId ) === 'all',
};
}

const {
getClientIdsOfDescendants,
getBlockIndex,
hasUploadPermissions,
isLockedAll,
orientation,
} = useSelect( selector, [ targetRootClientId ] );
} = useSelect(
( select ) => {
const {
getBlockListSettings,
getClientIdsOfDescendants: _getClientIdsOfDescendants,
getBlockIndex: _getBlockIndex,
getSettings,
getTemplateLock,
} = select( 'core/block-editor' );
return {
orientation: getBlockListSettings( targetRootClientId )
?.orientation,
getClientIdsOfDescendants: _getClientIdsOfDescendants,
getBlockIndex: _getBlockIndex,
hasUploadPermissions: !! getSettings().mediaUpload,
isLockedAll: getTemplateLock( targetRootClientId ) === 'all',
};
},
[ targetRootClientId ]
);
const {
insertBlocks,
updateBlockAttributes,
Expand Down Expand Up @@ -249,7 +252,6 @@ export default function useBlockDropZone( {
const {
srcRootClientId: sourceRootClientId,
srcClientIds: sourceClientIds,
srcIndex: sourceBlockIndex,
type: dropType,
} = parseDropEvent( event );

Expand All @@ -258,6 +260,8 @@ export default function useBlockDropZone( {
return;
}

const sourceBlockIndex = getBlockIndex( sourceClientIds[ 0 ] );

// If the user is dropping to the same position, return early.
if (
sourceRootClientId === targetRootClientId &&
Expand Down Expand Up @@ -299,6 +303,7 @@ export default function useBlockDropZone( {
},
[
getClientIdsOfDescendants,
getBlockIndex,
targetBlockIndex,
moveBlocksToPosition,
targetRootClientId,
Expand Down

0 comments on commit 587b018

Please sign in to comment.