From dd50f37761f2551e8ce29f59e31b376c1fbe5622 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Mon, 11 Mar 2019 12:27:47 +0100 Subject: [PATCH] Add withRegistry HigherOrderComponent --- .../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 a8073ace46c5d..fd788477a0d6d 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 0000000000000..32d1c8e1a40fd --- /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 06f074bec1541..b87a42b608f2b 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';