From 79f7a6eb6d0b0a95232f7caf36745a4d48c8756d Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Tue, 16 Apr 2019 09:53:21 +0100 Subject: [PATCH] Move setAttributes handler to the withDispatch HoC --- .../src/components/block-list/block.js | 51 +++++++++---------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/packages/block-editor/src/components/block-list/block.js b/packages/block-editor/src/components/block-list/block.js index 48a296ed2ad9a..c2e9c537433ba 100644 --- a/packages/block-editor/src/components/block-list/block.js +++ b/packages/block-editor/src/components/block-list/block.js @@ -87,9 +87,8 @@ function BlockListBlock( { attributes, initialPosition, wrapperProps, - onMetaChange, + setAttributes, onReplace, - onChange, onInsertBlocksAfter, onMerge, onSelect, @@ -254,25 +253,6 @@ function BlockListBlock( { }, [ isFirstMultiSelected ] ); // Other event handlers ----------------------------------------------------- - const setAttributes = ( newAttributes ) => { - const type = getBlockType( name ); - onChange( clientId, newAttributes ); - const metaAttributes = reduce( - newAttributes, - ( result, value, key ) => { - if ( get( type, [ 'attributes', key, 'source' ] ) === 'meta' ) { - result[ type.attributes[ key ].meta ] = value; - } - - return result; - }, - {} - ); - - if ( size( metaAttributes ) ) { - onMetaChange( metaAttributes ); - } - }; /** * Marks the block as selected when focused and not already selected. This @@ -675,11 +655,31 @@ const applyWithDispatch = withDispatch( ( dispatch, ownProps, { select } ) => { mergeBlocks, replaceBlocks, toggleSelection, + } = dispatch( 'core/block-editor' ); return { - onChange( clientId, attributes ) { - updateBlockAttributes( clientId, attributes ); + setAttributes( newAttributes ) { + const { name, clientId } = ownProps; + const type = getBlockType( name ); + updateBlockAttributes( clientId, newAttributes ); + const metaAttributes = reduce( + newAttributes, + ( result, value, key ) => { + if ( get( type, [ 'attributes', key, 'source' ] ) === 'meta' ) { + result[ type.attributes[ key ].meta ] = value; + } + + return result; + }, + {} + ); + + if ( size( metaAttributes ) ) { + const { getSettings } = select( 'core/block-editor' ); + const onChangeMeta = getSettings().__experimentalMetaSource.onChange; + onChangeMeta( metaAttributes ); + } }, onSelect( clientId = ownProps.clientId, initialPosition ) { selectBlock( clientId, initialPosition ); @@ -729,11 +729,6 @@ const applyWithDispatch = withDispatch( ( dispatch, ownProps, { select } ) => { onReplace( blocks ) { replaceBlocks( [ ownProps.clientId ], blocks ); }, - onMetaChange( updatedMeta ) { - const { getSettings } = select( 'core/block-editor' ); - const onChangeMeta = getSettings().__experimentalMetaSource.onChange; - onChangeMeta( updatedMeta ); - }, onShiftSelection() { if ( ! ownProps.isSelectionEnabled ) { return;