From af4288e0dde26771d5fbd9fd2111654007a58a8b Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Tue, 12 Mar 2019 08:20:26 +0100 Subject: [PATCH] Add withRegistry HigherOrderComponent (#14370) --- .../src/components/provider/index.js | 26 ++------------- .../src/components/with-registry/index.js | 33 +++++++++++++++++++ packages/data/src/index.js | 1 + 3 files changed, 36 insertions(+), 24 deletions(-) create mode 100644 packages/data/src/components/with-registry/index.js diff --git a/packages/block-editor/src/components/provider/index.js b/packages/block-editor/src/components/provider/index.js index a8073ace46c5d4..fd788477a0d6d1 100644 --- a/packages/block-editor/src/components/provider/index.js +++ b/packages/block-editor/src/components/provider/index.js @@ -3,30 +3,8 @@ */ import { Component } from '@wordpress/element'; import { DropZoneProvider, SlotFillProvider } from '@wordpress/components'; -import { withDispatch, RegistryConsumer } from '@wordpress/data'; -import { createHigherOrderComponent, compose } from '@wordpress/compose'; - -/** - * Higher-order component which renders the original component with the current - * registry context passed as its `registry` prop. - * - * @param {WPComponent} OriginalComponent Original component. - * - * @return {WPComponent} Enhanced component. - */ -const withRegistry = createHigherOrderComponent( - ( OriginalComponent ) => ( props ) => ( - - { ( registry ) => ( - - ) } - - ), - 'withRegistry' -); +import { withDispatch, withRegistry } from '@wordpress/data'; +import { compose } from '@wordpress/compose'; class BlockEditorProvider extends Component { componentDidMount() { diff --git a/packages/data/src/components/with-registry/index.js b/packages/data/src/components/with-registry/index.js new file mode 100644 index 00000000000000..32d1c8e1a40fd5 --- /dev/null +++ b/packages/data/src/components/with-registry/index.js @@ -0,0 +1,33 @@ +/** + * WordPress dependencies + */ +import { createHigherOrderComponent } from '@wordpress/compose'; + +/** + * Internal dependencies + */ +import { RegistryConsumer } from '../registry-provider'; + +/** + * Higher-order component which renders the original component with the current + * registry context passed as its `registry` prop. + * + * @param {WPComponent} OriginalComponent Original component. + * + * @return {WPComponent} Enhanced component. + */ +const withRegistry = createHigherOrderComponent( + ( OriginalComponent ) => ( props ) => ( + + { ( registry ) => ( + + ) } + + ), + 'withRegistry' +); + +export default withRegistry; diff --git a/packages/data/src/index.js b/packages/data/src/index.js index 06f074bec1541f..b87a42b608f2b4 100644 --- a/packages/data/src/index.js +++ b/packages/data/src/index.js @@ -11,6 +11,7 @@ import * as plugins from './plugins'; export { default as withSelect } from './components/with-select'; export { default as withDispatch } from './components/with-dispatch'; +export { default as withRegistry } from './components/with-registry'; export { default as RegistryProvider, RegistryConsumer } from './components/registry-provider'; export { default as __experimentalAsyncModeProvider } from './components/async-mode-provider'; export { createRegistry } from './registry';