Skip to content

Commit

Permalink
Rename isProvisionalBlock action property to selectPrevious in remove…
Browse files Browse the repository at this point in the history
…Block and removeBlocks. (#5696)

selectPrevious better expresses the intent of the flag. Its value is only false when we are removing the provisional block.
  • Loading branch information
jorgefilipecosta authored Mar 20, 2018
1 parent bf81a76 commit ca723cc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
16 changes: 8 additions & 8 deletions editor/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,30 +381,30 @@ export function createUndoLevel() {
* Returns an action object used in signalling that the blocks
* corresponding to the specified UID set are to be removed.
*
* @param {string[]} uids Block UIDs.
* @param {boolean} isProvisionalBlock True if the action is being used to remove a provisional block.
* @param {string[]} uids Block UIDs.
* @param {boolean} selectPrevious True if the previous block should be selected when a block is removed.
*
* @return {Object} Action object.
*/
export function removeBlocks( uids, isProvisionalBlock = false ) {
export function removeBlocks( uids, selectPrevious = true ) {
return {
type: 'REMOVE_BLOCKS',
uids,
isProvisionalBlock,
selectPrevious,
};
}

/**
* Returns an action object used in signalling that the block with the
* specified UID is to be removed.
*
* @param {string} uid Block UID.
* @param {boolean} isProvisionalBlock True if the action is being used to remove a provisional block.
* @param {string} uid Block UID.
* @param {boolean} selectPrevious True if the previous block should be selected when a block is removed.
*
* @return {Object} Action object.
*/
export function removeBlock( uid, isProvisionalBlock = false ) {
return removeBlocks( [ uid ], isProvisionalBlock );
export function removeBlock( uid, selectPrevious = true ) {
return removeBlocks( [ uid ], selectPrevious );
}

/**
Expand Down
6 changes: 3 additions & 3 deletions editor/store/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export function removeProvisionalBlock( action, store ) {
const state = store.getState();
const provisionalBlockUID = getProvisionalBlockUID( state );
if ( provisionalBlockUID && ! isBlockSelected( state, provisionalBlockUID ) ) {
return removeBlock( provisionalBlockUID, true );
return removeBlock( provisionalBlockUID, false );
}
}

Expand Down Expand Up @@ -572,8 +572,8 @@ export default {
MULTI_SELECT: removeProvisionalBlock,

REMOVE_BLOCKS( action, { getState, dispatch } ) {
// if we are removing the provisional block don't do anything.
if ( action.isProvisionalBlock ) {
// if the action says previous block should not be selected don't do anything.
if ( ! action.selectPrevious ) {
return;
}

Expand Down
8 changes: 4 additions & 4 deletions editor/store/test/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ describe( 'actions', () => {
expect( removeBlocks( uids ) ).toEqual( {
type: 'REMOVE_BLOCKS',
uids,
isProvisionalBlock: false,
selectPrevious: true,
} );
} );
} );
Expand All @@ -314,14 +314,14 @@ describe( 'actions', () => {
uids: [
uid,
],
isProvisionalBlock: false,
selectPrevious: true,
} );
expect( removeBlock( uid, true ) ).toEqual( {
expect( removeBlock( uid, false ) ).toEqual( {
type: 'REMOVE_BLOCKS',
uids: [
uid,
],
isProvisionalBlock: true,
selectPrevious: false,
} );
} );
} );
Expand Down
2 changes: 1 addition & 1 deletion editor/store/test/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe( 'effects', () => {
selectors.isBlockSelected.mockImplementation( ( state, uid ) => uid === 'ribs' );
const action = removeProvisionalBlock( {}, store );

expect( action ).toEqual( removeBlock( 'chicken', true ) );
expect( action ).toEqual( removeBlock( 'chicken', false ) );
} );
} );

Expand Down

0 comments on commit ca723cc

Please sign in to comment.