Skip to content

Commit

Permalink
Use blockTree to clarify selector name
Browse files Browse the repository at this point in the history
  • Loading branch information
noahtallen committed Aug 28, 2020
1 parent d402159 commit 1ffddc7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ export default compose(
const {
getSelectedBlockClientId,
getBlockHierarchyRootClientId,
__unstableGetBlockWithControlledInnerBlocks,
__unstableGetBlocksWithControlledInnerBlocks,
__unstableGetBlockWithBlockTree,
__unstableGetBlockTree,
} = select( 'core/block-editor' );
const selectedBlockClientId = getSelectedBlockClientId();
return {
rootBlocks: __unstableGetBlocksWithControlledInnerBlocks( '' ),
rootBlocks: __unstableGetBlockTree( '' ),
rootBlock: selectedBlockClientId
? __unstableGetBlockWithControlledInnerBlocks(
? __unstableGetBlockWithBlockTree(
getBlockHierarchyRootClientId( selectedBlockClientId )
)
: null,
Expand Down
25 changes: 12 additions & 13 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,16 @@ export const getBlocks = createSelector(
);

/**
* Same as getBlock, except it will include controlled inner blocks which would
* normally be excluded.
* Similar to getBlock, except it will include the entire nested block tree as
* inner blocks. The normal getBlock selector will exclude sections of the block
* tree which belong to different entities.
*
* @param {Object} state Editor state.
* @param {string} clientId Client ID of the block to get.
*
* @return {Object} The block.
* @return {Object} The block with all
*/
export const __unstableGetBlockWithControlledInnerBlocks = createSelector(
export const __unstableGetBlockWithBlockTree = createSelector(
( state, clientId ) => {
const block = state.blocks.byClientId[ clientId ];
if ( ! block ) {
Expand All @@ -229,28 +230,26 @@ export const __unstableGetBlockWithControlledInnerBlocks = createSelector(
return {
...block,
attributes: getBlockAttributes( state, clientId ),
innerBlocks: __unstableGetBlocksWithControlledInnerBlocks(
state,
clientId
),
innerBlocks: __unstableGetBlockTree( state, clientId ),
};
},
( state, clientId ) => [ state.blocks.cache[ clientId ] ]
);

/**
* Same as getBlocks, except it will include controlled inner blocks which would
* normally be excluded.
* Similar to getBlocks, except this selector returns the entire block tree
* represented in the block-editor store from the given root regardless of any
* inner block controllers.
*
* @param {Object} state Editor state.
* @param {?string} rootClientId Optional root client ID of block list.
*
* @return {Object[]} Post blocks.
*/
export const __unstableGetBlocksWithControlledInnerBlocks = createSelector(
( state, rootClientId ) =>
export const __unstableGetBlockTree = createSelector(
( state, rootClientId = '' ) =>
map( getBlockOrder( state, rootClientId ), ( clientId ) =>
__unstableGetBlockWithControlledInnerBlocks( state, clientId )
__unstableGetBlockWithBlockTree( state, clientId )
),
( state ) => [
state.blocks.byClientId,
Expand Down

0 comments on commit 1ffddc7

Please sign in to comment.