Skip to content

Commit

Permalink
Move reducer to blocks state slice
Browse files Browse the repository at this point in the history
  • Loading branch information
noahtallen committed Apr 3, 2020
1 parent 2ce490c commit 05dbcbe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 27 deletions.
39 changes: 13 additions & 26 deletions packages/block-editor/src/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,19 @@ export const blocks = flow(

return state;
},

controlledInnerBlocks(
state = {},
{ type, clientId, hasControlledInnerBlocks }
) {
if ( type === 'SET_HAS_CONTROLLED_INNER_BLOCKS' ) {
return {
...state,
[ clientId ]: hasControlledInnerBlocks,
};
}
return state;
},
} );

/**
Expand Down Expand Up @@ -1472,31 +1485,6 @@ export function highlightedBlock( state, action ) {
return state;
}

/**
* Reducer returning the blocks whose inner blocks are controlled. Maps a block
* clientId to a boolean. If true, the block's inner blocks are controlled by
* the block itself. For example, a template part uses an entity provider to
* control its blocks.
*
* @param {boolean} state Current blocks which have controlled inner blocks.
* @param {Object} action Dispatched action.
*
* @return {string} Updated state.
*/
export function controlledInnerBlocks(
state = {},
{ type, clientId, hasControlledInnerBlocks }
) {
if ( type === 'SET_HAS_CONTROLLED_INNER_BLOCKS' ) {
return {
...state,
[ clientId ]: hasControlledInnerBlocks,
};
}

return state;
}

export default combineReducers( {
blocks,
isTyping,
Expand All @@ -1517,5 +1505,4 @@ export default combineReducers( {
isNavigationMode,
automaticChangeStatus,
highlightedBlock,
controlledInnerBlocks,
} );
2 changes: 1 addition & 1 deletion packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1645,5 +1645,5 @@ export function isBlockHighlighted( state, clientId ) {
* @return {boolean} True if the block has controlled inner blocks.
*/
export function areInnerBlocksControlled( state, clientId ) {
return !! state.controlledInnerBlocks[ clientId ];
return !! state.blocks.controlledInnerBlocks[ clientId ];
}

0 comments on commit 05dbcbe

Please sign in to comment.