Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor: Flatten Inserter mapSelectToProps to optimize rendering #11028

Merged
merged 2 commits into from
Oct 26, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions packages/editor/src/components/inserter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,24 +96,24 @@ export default compose( [
getInserterItems,
getBlockOrder,
} = select( 'core/editor' );

const insertionPoint = getBlockInsertionPoint();
const parentId = rootClientId || insertionPoint.rootClientId;
if ( rootClientId === undefined ) {
rootClientId = insertionPoint.rootClientId;
}

return {
title: getEditedPostAttribute( 'title' ),
insertionPoint: {
rootClientId: parentId,
layout: rootClientId ? layout : insertionPoint.layout,
index: rootClientId ? getBlockOrder( rootClientId ).length : insertionPoint.index,
},
layout: rootClientId ? layout : insertionPoint.layout,
index: rootClientId ? getBlockOrder( rootClientId ).length : insertionPoint.index,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The two lines above are different from what we had previously. As we were not assigning the insertionPoint.rootClientId before testing. Not sure if it's impactful.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you're totally right. I expect this is wrong as implemented. I'll plan to fix.

selectedBlock: getSelectedBlock(),
items: getInserterItems( parentId ),
rootClientId: parentId,
items: getInserterItems( rootClientId ),
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