Skip to content

Commit

Permalink
Blocks: Simplify BlockContent context HOC implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed Aug 9, 2018
1 parent 5659085 commit fc4997d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
14 changes: 5 additions & 9 deletions packages/blocks/src/block-content-provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,25 @@ const BlockContentProvider = ( { children, innerBlocks } ) => {
};

return (
<Provider value={ { BlockContent } }>
<Provider value={ BlockContent }>
{ children }
</Provider>
);
};

/**
* A Higher Order Component used to inject BlockContent context to the
* A Higher Order Component used to inject BlockContent using context to the
* wrapped component.
*
* @param {Function} mapContextToProps Function called on every context change,
* expected to return object of props to
* merge with the component's own props.
*
* @return {Component} Enhanced component with injected context as props.
* @return {Component} Enhanced component with injected BlockContent as prop.
*/
export const withBlockContentContext = ( mapContextToProps ) => createHigherOrderComponent( ( OriginalComponent ) => {
export const withBlockContentContext = createHigherOrderComponent( ( OriginalComponent ) => {
return ( props ) => (
<Consumer>
{ ( context ) => (
<OriginalComponent
{ ...props }
{ ...mapContextToProps( context, props ) }
BlockContent={ context }
/>
) }
</Consumer>
Expand Down
4 changes: 1 addition & 3 deletions packages/editor/src/components/inner-blocks/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { pick, identity, isEqual, map } from 'lodash';
import { pick, isEqual, map } from 'lodash';
import classnames from 'classnames';

/**
Expand Down Expand Up @@ -149,8 +149,6 @@ InnerBlocks = compose( [
] )( InnerBlocks );

InnerBlocks.Content = withBlockContentContext(
identity
)(
( { BlockContent } ) => <BlockContent />
);

Expand Down

0 comments on commit fc4997d

Please sign in to comment.