Skip to content

Commit

Permalink
Editor: Flatten Inserter mapSelectToProps to optimize rendering (#11028)
Browse files Browse the repository at this point in the history
* Editor: Flatten Inserter mapSelectToProps

* Inserter: Assign layout, index as undefined rootClientId fallback
  • Loading branch information
aduth authored Oct 26, 2018
1 parent a548961 commit 306cee8
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions packages/editor/src/components/inserter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,26 +92,30 @@ export default compose( [
getBlockInsertionPoint,
getSelectedBlock,
getInserterItems,
getBlockOrder,
} = select( 'core/editor' );
const insertionPoint = getBlockInsertionPoint();
const parentId = rootClientId || insertionPoint.rootClientId;

let index;
if ( rootClientId === undefined ) {
// Unless explicitly provided, the default insertion point provided
// by the store occurs immediately following the selected block.
// Otherwise, the default behavior for an undefined index is to
// append block to the end of the rootClientId context.
const insertionPoint = getBlockInsertionPoint();
( { rootClientId, layout, index } = insertionPoint );
}

return {
title: getEditedPostAttribute( 'title' ),
insertionPoint: {
rootClientId: parentId,
layout: rootClientId ? layout : insertionPoint.layout,
index: rootClientId ? getBlockOrder( rootClientId ).length : insertionPoint.index,
},
selectedBlock: getSelectedBlock(),
items: getInserterItems( parentId ),
rootClientId: parentId,
items: getInserterItems( rootClientId ),
layout,
index,
rootClientId,
};
} ),
withDispatch( ( dispatch, ownProps ) => ( {
onInsertBlock: ( item ) => {
const { selectedBlock, insertionPoint } = ownProps;
const { index, rootClientId, layout } = insertionPoint;
const { selectedBlock, index, rootClientId, layout } = ownProps;
const { name, initialAttributes } = item;
const insertedBlock = createBlock( name, { ...initialAttributes, layout } );
if ( selectedBlock && isUnmodifiedDefaultBlock( selectedBlock ) ) {
Expand Down

0 comments on commit 306cee8

Please sign in to comment.