Skip to content

Commit

Permalink
Adopt lock-unlock.js and private-apis.js convention (#51322)
Browse files Browse the repository at this point in the history
* Always put lock and unlock functions in a file called lock-unlock.js

* Rename lockUnlock.js to lock-unlock.js
  • Loading branch information
noisysocks authored Jun 9, 2023
1 parent 2b02ff3 commit f9e405e
Show file tree
Hide file tree
Showing 98 changed files with 107 additions and 107 deletions.
16 changes: 8 additions & 8 deletions docs/contributors/code/coding-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ import { privateHasContentRoleAttribute, ...selectors } from './selectors';
import { privateToggleFeature, ...actions } from './selectors';
// The `lock` function is exported from the internal private-apis.js file where
// the opt-in function was called.
import { lock, unlock } from './private-apis';
import { lock, unlock } from './lock-unlock';

export const store = registerStore(/* ... */);
// Attach a private action to the exported store:
Expand All @@ -230,7 +230,7 @@ import { store } from '@wordpress/package1';
import { useSelect } from '@wordpress/data';
// The `unlock` function is exported from the internal private-apis.js file where
// the opt-in function was called.
import { unlock } from './private-apis';
import { unlock } from './lock-unlock';

function MyComponent() {
const hasRole = useSelect( ( select ) => (
Expand All @@ -251,7 +251,7 @@ function MyComponent() {

```js
// In packages/package1/index.js:
import { lock } from './private-apis';
import { lock } from './lock-unlock';

export const privateApis = {};
/* Attach private data to the exported object */
Expand All @@ -266,7 +266,7 @@ lock( privateApis, {

// In packages/package2/index.js:
import { privateApis } from '@wordpress/package1';
import { unlock } from './private-apis';
import { unlock } from './lock-unlock';

const {
privateCallback,
Expand Down Expand Up @@ -314,7 +314,7 @@ inside it:

```js
// In @wordpress/package1/index.js:
import { lock } from './private-apis';
import { lock } from './lock-unlock';

// A private function contains all the logic
function privateValidateBlocks( formula, privateIsStrict ) {
Expand All @@ -339,7 +339,7 @@ lock( privateApis, { privateValidateBlocks } );

// In @wordpress/package2/index.js:
import { privateApis as package1PrivateApis } from '@wordpress/package1';
import { unlock } from './private-apis';
import { unlock } from './lock-unlock';

// The private function may be "unlocked" given the stable function:
const { privateValidateBlocks } = unlock( package1PrivateApis );
Expand All @@ -355,7 +355,7 @@ inside it:

```js
// In @wordpress/package1/index.js:
import { lock } from './private-apis';
import { lock } from './lock-unlock';

// The private component contains all the logic
const PrivateMyButton = ( { title, privateShowIcon = true } ) => {
Expand All @@ -379,7 +379,7 @@ lock( privateApis, { PrivateMyButton } );

// In @wordpress/package2/index.js:
import { privateApis } from '@wordpress/package1';
import { unlock } from './private-apis';
import { unlock } from './lock-unlock';

// The private component may be "unlocked" given the stable component:
const { PrivateMyButton } = unlock(privateApis);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
/**
* Internal dependencies
*/
import { unlock } from '../../private-apis';
import { unlock } from '../../lock-unlock';

const RESIZABLE_BOX_ENABLE_OPTION = {
top: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/cover/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
* Internal dependencies
*/
import { IMAGE_BACKGROUND_TYPE, VIDEO_BACKGROUND_TYPE } from './shared';
import { unlock } from '../private-apis';
import { unlock } from '../lock-unlock';

const { cleanEmptyObject } = unlock( blockEditorPrivateApis );

Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { store as noticesStore } from '@wordpress/notices';
* Internal dependencies
*/
import Image from './image';
import { unlock } from '../private-apis';
import { unlock } from '../lock-unlock';

/**
* Module constants
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/block-library/src/media-text/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import {
LINK_DESTINATION_ATTACHMENT,
TEMPLATE,
} from './constants';
import { unlock } from '../private-apis';
import { unlock } from '../lock-unlock';

const { useBlockEditingMode } = unlock( blockEditorPrivateApis );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { __, sprintf } from '@wordpress/i18n';
* Internal dependencies
*/
import NavigationMenuSelector from './navigation-menu-selector';
import { unlock } from '../../private-apis';
import { unlock } from '../../lock-unlock';
import DeletedNavigationWarning from './deleted-navigation-warning';
import useNavigationMenu from '../use-navigation-menu';
import LeafMoreMenu from './leaf-more-menu';
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/post-title/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { useEntityProp } from '@wordpress/core-data';
*/
import HeadingLevelDropdown from '../heading/heading-level-dropdown';
import { useCanEditEntity } from '../utils/hooks';
import { unlock } from '../private-apis';
import { unlock } from '../lock-unlock';

const { useBlockEditingMode } = unlock( blockEditorPrivateApis );

Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/query/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
/**
* Internal dependencies
*/
import { unlock } from '../private-apis';
import { unlock } from '../lock-unlock';

const { cleanEmptyObject } = unlock( blockEditorPrivateApis );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import ParentControl from './parent-control';
import { TaxonomyControls } from './taxonomy-controls';
import StickyControl from './sticky-control';
import CreateNewPostLink from './create-new-post-link';
import { unlock } from '../../../private-apis';
import { unlock } from '../../../lock-unlock';
import {
usePostTypes,
useIsPostTypeHierarchical,
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/utils/migrate-font-family.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
/**
* Internal dependencies
*/
import { unlock } from '../private-apis';
import { unlock } from '../lock-unlock';

const { cleanEmptyObject } = unlock( blockEditorPrivateApis );

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/blocks/src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as selectors from './selectors';
import * as privateSelectors from './private-selectors';
import * as actions from './actions';
import { STORE_NAME } from './constants';
import { unlock } from '../private-apis';
import { unlock } from '../lock-unlock';

/**
* Store definition for the blocks namespace.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
import useSidebarBlockEditor from './use-sidebar-block-editor';
import useBlocksFocusControl from '../focus-control/use-blocks-focus-control';

import { unlock } from '../../private-apis';
import { unlock } from '../../lock-unlock';

const { ExperimentalBlockEditorProvider } = unlock( blockEditorPrivateApis );

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/data/src/redux-store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { compose } from '@wordpress/compose';
* Internal dependencies
*/
import { builtinControls } from '../controls';
import { lock } from '../private-apis';
import { lock } from '../lock-unlock';
import promise from '../promise-middleware';
import createResolversCacheMiddleware from '../resolvers-cache-middleware';
import createThunkMiddleware from './thunk-middleware';
Expand Down
2 changes: 1 addition & 1 deletion packages/data/src/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import deprecated from '@wordpress/deprecated';
import createReduxStore from './redux-store';
import coreDataStore from './store';
import { createEmitter } from './utils/emitter';
import { lock, unlock } from './private-apis';
import { lock, unlock } from './lock-unlock';

/** @typedef {import('./types').StoreDescriptor} StoreDescriptor */

Expand Down
2 changes: 1 addition & 1 deletion packages/data/src/test/privateAPIs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import { createRegistry } from '../registry';
import createReduxStore from '../redux-store';
import { unlock } from '../private-apis';
import { unlock } from '../lock-unlock';
import { createRegistrySelector } from '../factory';

describe( 'Private data APIs', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
* Internal dependencies
*/
import { store as editPostStore } from '../../../store';
import { unlock } from '../../../private-apis';
import { unlock } from '../../../lock-unlock';

const { useShouldContextualToolbarShow } = unlock( blockEditorPrivateApis );

Expand Down
2 changes: 1 addition & 1 deletion packages/edit-post/src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { privateApis as coreCommandsPrivateApis } from '@wordpress/core-commands
import Layout from './components/layout';
import EditorInitialization from './components/editor-initialization';
import { store as editPostStore } from './store';
import { unlock } from './private-apis';
import { unlock } from './lock-unlock';

const { ExperimentalEditorProvider } = unlock( editorPrivateApis );
const { useCommands } = unlock( coreCommandsPrivateApis );
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
getUniqueTemplatePartTitle,
getCleanTemplatePartSlug,
} from '../../utils/template-part-create';
import { unlock } from '../../private-apis';
import { unlock } from '../../lock-unlock';

const { useHistory } = unlock( routerPrivateApis );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
import AddCustomGenericTemplateModalContent from './add-custom-generic-template-modal-content';
import TemplateActionsLoadingScreen from './template-actions-loading-screen';
import { store as editSiteStore } from '../../store';
import { unlock } from '../../private-apis';
import { unlock } from '../../lock-unlock';

const { useHistory } = unlock( routerPrivateApis );

Expand Down
2 changes: 1 addition & 1 deletion packages/edit-site/src/components/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { privateApis as routerPrivateApis } from '@wordpress/router';
*/
import Layout from '../layout';
import { GlobalStylesProvider } from '../global-styles/global-styles-provider';
import { unlock } from '../../private-apis';
import { unlock } from '../../lock-unlock';

const { RouterProvider } = unlock( routerPrivateApis );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { privateApis as routerPrivateApis } from '@wordpress/router';
/**
* Internal dependencies
*/
import { unlock } from '../../private-apis';
import { unlock } from '../../lock-unlock';

const { useLocation, useHistory } = unlock( routerPrivateApis );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import { unlock } from '../../private-apis';
import { unlock } from '../../lock-unlock';
import { store as editSiteStore } from '../../store';

function EditorCanvas( { enableResizing, settings, children, ...props } ) {
Expand Down
2 changes: 1 addition & 1 deletion packages/edit-site/src/components/block-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { store as editSiteStore } from '../../store';
import BackButton from './back-button';
import ResizableEditor from './resizable-editor';
import EditorCanvas from './editor-canvas';
import { unlock } from '../../private-apis';
import { unlock } from '../../lock-unlock';
import EditorCanvasContainer from '../editor-canvas-container';
import {
DisableNonPageContentBlocks,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { useFocusOnMount, useFocusReturn } from '@wordpress/compose';
/**
* Internal dependencies
*/
import { unlock } from '../../private-apis';
import { unlock } from '../../lock-unlock';
import { store as editSiteStore } from '../../store';
import ResizableEditor from '../block-editor/resizable-editor';

Expand Down
2 changes: 1 addition & 1 deletion packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { store as editSiteStore } from '../../store';
import { GlobalStylesRenderer } from '../global-styles-renderer';
import useTitle from '../routes/use-title';
import CanvasSpinner from '../canvas-spinner';
import { unlock } from '../../private-apis';
import { unlock } from '../../lock-unlock';
import useEditedEntityRecord from '../use-edited-entity-record';
import { SidebarFixedBottomSlot } from '../sidebar-edit-mode/sidebar-fixed-bottom';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
* Internal dependencies
*/
import { store as editSiteStore } from '../../store';
import { unlock } from '../../private-apis';
import { unlock } from '../../lock-unlock';

const { useGlobalStylesOutput } = unlock( blockEditorPrivateApis );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
/**
* Internal dependencies
*/
import { unlock } from '../../private-apis';
import { unlock } from '../../lock-unlock';

const { useGlobalSetting } = unlock( blockEditorPrivateApis );
const mobilePopoverProps = { placement: 'bottom-start', offset: 8 };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useMemo } from '@wordpress/element';
/**
* Internal dependencies
*/
import { unlock } from '../../private-apis';
import { unlock } from '../../lock-unlock';

const {
useGlobalStyle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
* Internal dependencies
*/
import CanvasSpinner from '../canvas-spinner';
import { unlock } from '../../private-apis';
import { unlock } from '../../lock-unlock';

const { GlobalStylesContext, cleanEmptyObject } = unlock(
blockEditorPrivateApis
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
* Internal dependencies
*/
import Subtitle from './subtitle';
import { unlock } from '../../private-apis';
import { unlock } from '../../lock-unlock';

const { useGlobalSetting } = unlock( blockEditorPrivateApis );
const mobilePopoverProps = { placement: 'bottom-start', offset: 8 };
Expand Down
2 changes: 1 addition & 1 deletion packages/edit-site/src/components/global-styles/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
/**
* Internal dependencies
*/
import { unlock } from '../../private-apis';
import { unlock } from '../../lock-unlock';
import { useSelect } from '@wordpress/data';

const { useGlobalSetting } = unlock( blockEditorPrivateApis );
Expand Down
2 changes: 1 addition & 1 deletion packages/edit-site/src/components/global-styles/palette.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Subtitle from './subtitle';
import { NavigationButtonAsItem } from './navigation-button';
import { useColorRandomizer } from './hooks';
import ColorIndicatorWrapper from './color-indicator-wrapper';
import { unlock } from '../../private-apis';
import { unlock } from '../../lock-unlock';

const { useGlobalSetting } = unlock( blockEditorPrivateApis );

Expand Down
2 changes: 1 addition & 1 deletion packages/edit-site/src/components/global-styles/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { useState, useMemo } from '@wordpress/element';
/**
* Internal dependencies
*/
import { unlock } from '../../private-apis';
import { unlock } from '../../lock-unlock';

const { useGlobalSetting, useGlobalStyle, useGlobalStylesOutput } = unlock(
blockEditorPrivateApis
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
* Internal dependencies
*/
import { NavigationButtonAsItem } from './navigation-button';
import { unlock } from '../../private-apis';
import { unlock } from '../../lock-unlock';

const {
useHasDimensionsPanel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { speak } from '@wordpress/a11y';
import { useBlockVariations } from './variations-panel';
import ScreenHeader from './header';
import { NavigationButtonAsItem } from './navigation-button';
import { unlock } from '../../private-apis';
import { unlock } from '../../lock-unlock';

const {
useHasDimensionsPanel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { __, sprintf } from '@wordpress/i18n';
*/
import ScreenHeader from './header';
import BlockPreviewPanel from './block-preview-panel';
import { unlock } from '../../private-apis';
import { unlock } from '../../lock-unlock';
import Subtitle from './subtitle';
import { useBlockVariations, VariationsPanel } from './variations-panel';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
import ScreenHeader from './header';
import Palette from './palette';
import BlockPreviewPanel from './block-preview-panel';
import { unlock } from '../../private-apis';
import { unlock } from '../../lock-unlock';

const {
useGlobalStyle,
Expand Down
Loading

0 comments on commit f9e405e

Please sign in to comment.