Skip to content

Commit

Permalink
Remove unnecessary unlock()s
Browse files Browse the repository at this point in the history
  • Loading branch information
noisysocks committed Aug 9, 2023
1 parent a05bfe9 commit bc79a32
Show file tree
Hide file tree
Showing 12 changed files with 17 additions and 39 deletions.
10 changes: 3 additions & 7 deletions packages/block-editor/src/components/block-editing-mode/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { useContext, useEffect } from '@wordpress/element';
* Internal dependencies
*/
import { store as blockEditorStore } from '../../store';
import { unlock } from '../../lock-unlock';
import { BlockListBlockContext } from '../block-list/block-list-block-context';

/**
Expand Down Expand Up @@ -49,14 +48,11 @@ export function useBlockEditingMode( mode ) {
const { clientId = '' } = useContext( BlockListBlockContext ) ?? {};
const blockEditingMode = useSelect(
( select ) =>
unlock( select( blockEditorStore ) ).getBlockEditingMode(
clientId
),
select( blockEditorStore ).getBlockEditingMode( clientId ),
[ clientId ]
);
const { setBlockEditingMode, unsetBlockEditingMode } = unlock(
useDispatch( blockEditorStore )
);
const { setBlockEditingMode, unsetBlockEditingMode } =
useDispatch( blockEditorStore );
useEffect( () => {
if ( mode ) {
setBlockEditingMode( clientId, mode );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import PositionControls from '../inspector-controls-tabs/position-controls-panel
import useBlockInspectorAnimationSettings from './useBlockInspectorAnimationSettings';
import BlockInfo from '../block-info-slot-fill';
import BlockQuickNavigation from '../block-quick-navigation';
import { unlock } from '../../lock-unlock';

function BlockInspectorLockedBlocks( { topLevelLockedBlock } ) {
const contentClientIds = useSelect(
Expand All @@ -39,7 +38,7 @@ function BlockInspectorLockedBlocks( { topLevelLockedBlock } ) {
getClientIdsOfDescendants,
getBlockName,
getBlockEditingMode,
} = unlock( select( blockEditorStore ) );
} = select( blockEditorStore );
return getClientIdsOfDescendants( [ topLevelLockedBlock ] ).filter(
( clientId ) =>
getBlockName( clientId ) !== 'core/list-item' &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { getDefaultBlockName } from '@wordpress/blocks';
import DefaultBlockAppender from '../default-block-appender';
import ButtonBlockAppender from '../button-block-appender';
import { store as blockEditorStore } from '../../store';
import { unlock } from '../../lock-unlock';

function DefaultAppender( { rootClientId } ) {
const canInsertDefaultBlock = useSelect( ( select ) =>
Expand Down Expand Up @@ -48,7 +47,7 @@ function useAppender( rootClientId, CustomAppender ) {
getSelectedBlockClientId,
__unstableGetEditorMode,
getBlockEditingMode,
} = unlock( select( blockEditorStore ) );
} = select( blockEditorStore );

if ( CustomAppender === false ) {
return false;
Expand Down
3 changes: 1 addition & 2 deletions packages/block-editor/src/components/block-list/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import BlockHtml from './block-html';
import { useBlockProps } from './use-block-props';
import { store as blockEditorStore } from '../../store';
import { useLayout } from './layout';
import { unlock } from '../../lock-unlock';
import { BlockListBlockContext } from './block-list-block-context';

/**
Expand Down Expand Up @@ -102,7 +101,7 @@ function BlockListBlock( {
getSettings,
__unstableGetTemporarilyEditingAsBlocks,
getBlockEditingMode,
} = unlock( select( blockEditorStore ) );
} = select( blockEditorStore );
return {
themeSupportsLayout: getSettings().supportsLayout,
isTemporarilyEditingAsBlocks:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { isRTL } from '@wordpress/i18n';
*/
import { store as blockEditorStore } from '../../store';
import { InsertionPointOpenRef } from '../block-tools/insertion-point';
import { unlock } from '../../lock-unlock';

export function useInBetweenInserter() {
const openRef = useContext( InsertionPointOpenRef );
Expand All @@ -29,7 +28,7 @@ export function useInBetweenInserter() {
getTemplateLock,
__unstableIsWithinBlockOverlay,
getBlockEditingMode,
} = unlock( useSelect( blockEditorStore ) );
} = useSelect( blockEditorStore );
const { showInsertionPoint, hideInsertionPoint } =
useDispatch( blockEditorStore );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import useBlockDisplayInformation from '../use-block-display-information';
import BlockIcon from '../block-icon';
import { useShowHoveredOrFocusedGestures } from '../block-toolbar/utils';
import { store as blockEditorStore } from '../../store';
import { unlock } from '../../lock-unlock';

/**
* Block parent selector component, displaying the hierarchy of the
Expand All @@ -30,7 +29,7 @@ export default function BlockParentSelector() {
getBlockParents,
getSelectedBlockClientId,
getBlockEditingMode,
} = unlock( select( blockEditorStore ) );
} = select( blockEditorStore );
const { hasBlockSupport } = select( blocksStore );
const selectedBlockClientId = getSelectedBlockClientId();
const parents = getBlockParents( selectedBlockClientId );
Expand Down
3 changes: 1 addition & 2 deletions packages/block-editor/src/components/block-toolbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import BlockEditVisuallyButton from '../block-edit-visually-button';
import { useShowHoveredOrFocusedGestures } from './utils';
import { store as blockEditorStore } from '../../store';
import __unstableBlockNameContext from './block-name-context';
import { unlock } from '../../lock-unlock';

const BlockToolbar = ( { hideDragHandle } ) => {
const { blockClientIds, blockType, isValid, isVisual, blockEditingMode } =
Expand All @@ -44,7 +43,7 @@ const BlockToolbar = ( { hideDragHandle } ) => {
isBlockValid,
getBlockRootClientId,
getBlockEditingMode,
} = unlock( select( blockEditorStore ) );
} = select( blockEditorStore );
const selectedBlockClientIds = getSelectedBlockClientIds();
const selectedBlockClientId = selectedBlockClientIds[ 0 ];
const blockRootClientId = getBlockRootClientId(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { useViewportMatch } from '@wordpress/compose';
import NavigableToolbar from '../navigable-toolbar';
import BlockToolbar from '../block-toolbar';
import { store as blockEditorStore } from '../../store';
import { unlock } from '../../lock-unlock';
import { useHasAnyBlockControls } from '../block-controls/use-has-block-controls';

function BlockContextualToolbar( { focusOnMount, isFixed, ...props } ) {
Expand All @@ -45,7 +44,7 @@ function BlockContextualToolbar( { focusOnMount, isFixed, ...props } ) {
getBlockParents,
getSelectedBlockClientIds,
getBlockEditingMode,
} = unlock( select( blockEditorStore ) );
} = select( blockEditorStore );
const { getBlockType } = select( blocksStore );
const selectedBlockClientIds = getSelectedBlockClientIds();
const _selectedBlockClientId = selectedBlockClientIds[ 0 ];
Expand Down
5 changes: 1 addition & 4 deletions packages/block-editor/src/components/list-view/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import { getBlockPositionDescription } from './utils';
import { store as blockEditorStore } from '../../store';
import useBlockDisplayInformation from '../use-block-display-information';
import { useBlockLock } from '../block-lock';
import { unlock } from '../../lock-unlock';
import AriaReferencedText from './aria-referenced-text';

function ListViewBlock( {
Expand Down Expand Up @@ -84,9 +83,7 @@ function ListViewBlock( {
);
const blockEditingMode = useSelect(
( select ) =>
unlock( select( blockEditorStore ) ).getBlockEditingMode(
clientId
),
select( blockEditorStore ).getBlockEditingMode( clientId ),
[ clientId ]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
isPointContainedByRect,
} from '../../utils/math';
import { store as blockEditorStore } from '../../store';
import { unlock } from '../../lock-unlock';

/** @typedef {import('../../utils/math').WPPoint} WPPoint */
/** @typedef {import('../use-on-block-drop/types').WPDropOperation} WPDropOperation */
Expand Down Expand Up @@ -155,7 +154,7 @@ export default function useBlockDropZone( {
__unstableIsWithinBlockOverlay,
__unstableHasActiveBlockOverlayActive,
getBlockEditingMode,
} = unlock( select( blockEditorStore ) );
} = select( blockEditorStore );
const blockEditingMode = getBlockEditingMode( targetRootClientId );
return (
blockEditingMode !== 'default' ||
Expand Down
12 changes: 3 additions & 9 deletions packages/block-library/src/pattern/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ import {
useBlockProps,
} from '@wordpress/block-editor';

/**
* Internal dependencies
*/
import { unlock } from '../lock-unlock';

const PatternEdit = ( { attributes, clientId } ) => {
const selectedPattern = useSelect(
( select ) =>
Expand All @@ -25,10 +20,9 @@ const PatternEdit = ( { attributes, clientId } ) => {

const { replaceBlocks, __unstableMarkNextChangeAsNotPersistent } =
useDispatch( blockEditorStore );
const { setBlockEditingMode } = unlock( useDispatch( blockEditorStore ) );
const { getBlockRootClientId, getBlockEditingMode } = unlock(
useSelect( blockEditorStore )
);
const { setBlockEditingMode } = useDispatch( blockEditorStore );
const { getBlockRootClientId, getBlockEditingMode } =
useSelect( blockEditorStore );

// Run this effect when the component loads.
// This adds the Pattern's contents to the post.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ export default function NavigationBlockEditorProvider( { children } ) {
};
}, [] );

const { selectBlock, setBlockEditingMode, unsetBlockEditingMode } = unlock(
useDispatch( blockEditorStore )
);
const { selectBlock, setBlockEditingMode, unsetBlockEditingMode } =
useDispatch( blockEditorStore );

const navigationBlockClientId = blocks && blocks[ 0 ]?.clientId;

Expand Down

0 comments on commit bc79a32

Please sign in to comment.