Skip to content
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

Block: combine store subscriptions #56994

Merged
merged 10 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Block: combine store subscriptions
  • Loading branch information
ellatrix committed Dec 12, 2023
commit d8c00b8f2b1b142a5e1223479a4d8932babee93b
2 changes: 0 additions & 2 deletions packages/block-editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -928,8 +928,6 @@ export default function Edit() {
_Parameters_

- _props_ `Object`: Optional. Props to pass to the element. Must contain the ref if one is defined.
- _options_ `Object`: Options for internal use only.
- _options.\_\_unstableIsHtml_ `boolean`:

_Returns_

Expand Down
65 changes: 3 additions & 62 deletions packages/block-editor/src/components/block-edit/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
/**
* WordPress dependencies
*/
import { useMemo } from '@wordpress/element';

import { hasBlockSupport } from '@wordpress/blocks';
/**
* Internal dependencies
*/
import Edit from './edit';
import {
BlockEditContextProvider,
useBlockEditContext,
mayDisplayControlsKey,
mayDisplayParentControlsKey,
} from './context';
import { useBlockEditContext } from './context';

/**
* The `useBlockEditContext` hook provides information about the block this hook is being used in.
Expand All @@ -25,54 +14,6 @@ import {
*/
export { useBlockEditContext };

export default function BlockEdit( {
mayDisplayControls,
mayDisplayParentControls,
// The remaining props are passed through the BlockEdit filters and are thus
// public API!
...props
} ) {
const {
name,
isSelected,
clientId,
attributes = {},
__unstableLayoutClassNames,
} = props;
const { layout = null } = attributes;
const layoutSupport =
hasBlockSupport( name, 'layout', false ) ||
hasBlockSupport( name, '__experimentalLayout', false );
return (
<BlockEditContextProvider
// It is important to return the same object if props haven't
// changed to avoid unnecessary rerenders.
// See https://reactjs.org/docs/context.html#caveats.
value={ useMemo(
() => ( {
name,
isSelected,
clientId,
layout: layoutSupport ? layout : null,
__unstableLayoutClassNames,
// We use symbols in favour of an __unstable prefix to avoid
// usage outside of the package (this context is exposed).
[ mayDisplayControlsKey ]: mayDisplayControls,
[ mayDisplayParentControlsKey ]: mayDisplayParentControls,
} ),
[
name,
isSelected,
clientId,
layoutSupport,
layout,
__unstableLayoutClassNames,
mayDisplayControls,
mayDisplayParentControls,
]
) }
>
<Edit { ...props } />
</BlockEditContextProvider>
);
export default function BlockEdit( props ) {
return <Edit { ...props } />;
}
Loading
Loading