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

Code Style: Change name of accumulated variables when using reduce function #17893

Merged
merged 4 commits into from
Oct 15, 2019
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,11 @@ export const getClientIdsWithDescendants = createSelector(
*/
export const getGlobalBlockCount = createSelector(
( state, blockName ) => {
const clientIds = getClientIdsWithDescendants( state );
const clientIdsAccumulator = getClientIdsWithDescendants( state );
if ( ! blockName ) {
return clientIds.length;
return clientIdsAccumulator.length;
}
return reduce( clientIds, ( count, clientId ) => {
return reduce( clientIdsAccumulator, ( count, clientId ) => {
const block = state.blocks.byClientId[ clientId ];
return block.name === blockName ? count + 1 : count;
}, 0 );
Expand Down
2 changes: 1 addition & 1 deletion packages/block-editor/src/store/test/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1425,7 +1425,7 @@ describe( 'state', () => {
],
},
];
const original = deepFreeze( actions.reduce( blocks, undefined ) );
const original = deepFreeze( actions.reduce( blocksAccumulator, undefined ) );

const state = blocks( original, {
type: 'RESET_BLOCKS',
Expand Down
10 changes: 5 additions & 5 deletions packages/block-library/src/columns/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,21 @@ export default [
) );
},
migrate( attributes, innerBlocks ) {
const columns = innerBlocks.reduce( ( result, innerBlock ) => {
const columns = innerBlocks.reduce( ( resultAccumulator, innerBlock ) => {
Copy link
Member

Choose a reason for hiding this comment

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

It seems like resultAccumulator could be simplified to just accumulator. They result prefix doesn't sound like it brings additional context here.

const { originalContent } = innerBlock;

let columnIndex = getDeprecatedLayoutColumn( originalContent );
if ( columnIndex === undefined ) {
columnIndex = 0;
}

if ( ! result[ columnIndex ] ) {
result[ columnIndex ] = [];
if ( ! resultAccumulator[ columnIndex ] ) {
resultAccumulator[ columnIndex ] = [];
}

result[ columnIndex ].push( innerBlock );
resultAccumulator[ columnIndex ].push( innerBlock );

return result;
return resultAccumulator;
}, [] );

const migratedInnerBlocks = columns.map( ( columnBlocks ) => (
Expand Down
4 changes: 2 additions & 2 deletions packages/block-library/src/columns/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ export function getTotalColumnsWidth( blocks, totalBlockCount = blocks.length )
* @return {Object<string,number>} Column widths.
*/
export function getColumnWidths( blocks, totalBlockCount = blocks.length ) {
return blocks.reduce( ( result, block ) => {
return blocks.reduce( ( resultAccumulator, block ) => {
const width = getEffectiveColumnWidth( block, totalBlockCount );
return Object.assign( result, { [ block.clientId ]: width } );
return Object.assign( resultAccumulator, { [ block.clientId ]: width } );
}, {} );
}

Expand Down
4 changes: 2 additions & 2 deletions packages/block-library/src/group/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ export const settings = {
const alignments = [ 'wide', 'full' ];

// Determine the widest setting of all the blocks to be grouped
const widestAlignment = blocks.reduce( ( result, block ) => {
const widestAlignment = blocks.reduce( ( resultAccumulator, block ) => {
const { align } = block.attributes;
return alignments.indexOf( align ) > alignments.indexOf( result ) ? align : result;
return alignments.indexOf( align ) > alignments.indexOf( resultAccumulator ) ? align : resultAccumulator;
}, undefined );

// Clone the Blocks to be Grouped
Expand Down
6 changes: 3 additions & 3 deletions packages/block-library/src/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ export const coreBlocks = [
textColumns,
verse,
video,
].reduce( ( memo, block ) => {
memo[ block.name ] = block;
return memo;
].reduce( ( memoAccumulator, block ) => {
Copy link
Member

Choose a reason for hiding this comment

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

A similar note here. It feels like memoAccumulator could be shortened to accumulator and it will read well enough.

memoAccumulator[ block.name ] = block;
return memoAccumulator;
}, {} );

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/blocks/src/api/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ export function createBlock( name, attributes = {}, innerBlocks = [] ) {

// Ensure attributes contains only values defined by block type, and merge
// default values for missing attributes.
const sanitizedAttributes = reduce( blockType.attributes, ( result, schema, key ) => {
const accumulator=blockType.attributes
const sanitizedAttributes = reduce(accumulator , ( result, schema, key ) => {
const value = attributes[ key ];

if ( undefined !== value ) {
Expand Down
6 changes: 3 additions & 3 deletions packages/blocks/src/api/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -565,12 +565,12 @@ export function serializeBlockNode( blockNode, options = {} ) {
* @return {Function} An implementation which parses the post content.
*/
const createParse = ( parseImplementation ) =>
( content ) => parseImplementation( content ).reduce( ( memo, blockNode ) => {
( content ) => parseImplementation( content ).reduce( ( memoAccumulator, blockNode ) => {
const block = createBlockWithFallback( blockNode );
if ( block ) {
memo.push( block );
memoAccumulator.push( block );
}
return memo;
return memoAccumulator;
}, [] );

/**
Expand Down
14 changes: 7 additions & 7 deletions packages/blocks/src/api/serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,28 +150,28 @@ export function getSaveContent( blockTypeOrName, attributes, innerBlocks ) {
* @return {Object<string,*>} Subset of attributes for comment serialization.
*/
export function getCommentAttributes( blockType, attributes ) {
return reduce( blockType.attributes, ( result, attributeSchema, key ) => {
const accumulator=blockType.attributes
return reduce( accumulator, ( result, attributeSchema, key ) => {
const value = attributes[ key ];

// Ignore undefined values.
if ( undefined === value ) {
return result;
return resultAccumulator;
}

// Ignore all attributes but the ones with an "undefined" source
// "undefined" source refers to attributes saved in the block comment.
if ( attributeSchema.source !== undefined ) {
return result;
return resultAccumulator;
}

// Ignore default value.
if ( 'default' in attributeSchema && attributeSchema.default === value ) {
return result;
return resultAccumulator;
}

// Otherwise, include in comment set.
result[ key ] = value;
return result;
resultAccumulator[ key ] = value;
return resultAccumulator;
}, {} );
}

Expand Down
6 changes: 3 additions & 3 deletions packages/core-data/src/queried-data/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ function items( state = {}, action ) {
const key = action.key || DEFAULT_ENTITY_KEY;
return {
...state,
...action.items.reduce( ( acc, value ) => {
...action.items.reduce( ( accumulator, value ) => {
const itemId = value[ key ];
acc[ itemId ] = conservativeMapItem( state[ itemId ], value );
return acc;
accumulator[ itemId ] = conservativeMapItem( state[ itemId ], value );
return accumulator;
}, {} ),
};
}
Expand Down
6 changes: 3 additions & 3 deletions packages/core-data/src/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ export const getRawEntityRecord = createSelector(
const record = getEntityRecord( state, kind, name, key );
return (
record &&
Object.keys( record ).reduce( ( acc, _key ) => {
Object.keys( record ).reduce( ( accumulator, _key ) => {
// Because edits are the "raw" attribute values,
// we return those from record selectors to make rendering,
// comparisons, and joins with edits easier.
acc[ _key ] = get( record[ _key ], 'raw', record[ _key ] );
return acc;
accumulator[ _key ] = get( record[ _key ], 'raw', record[ _key ] );
return accumulator;
}, {} )
);
},
Expand Down
2 changes: 1 addition & 1 deletion packages/data/src/plugins/persistence/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ const persistencePlugin = function( registry, pluginOptions ) {
// to leverage its behavior of returning the same object when none
// of the property values changes. This allows a strict reference
// equality to bypass a persistence set on an unchanging state.
const reducers = keys.reduce( ( result, key ) => Object.assign( result, {
const reducers = keys.reduce( ( resultAccumulator, key ) => Object.assign( resultAccumulator, {
[ key ]: ( state, action ) => action.nextState[ key ],
} ), {} );

Expand Down
3 changes: 2 additions & 1 deletion packages/dom/src/tabbable.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,11 @@ function compareObjectTabbables( a, b ) {
}

export function find( context ) {
const accumulator=createStatefulCollapseRadioGroup()
return findFocusable( context )
.filter( isTabbableIndex )
.map( mapElementToObjectTabbable )
.sort( compareObjectTabbables )
.map( mapObjectTabbableToElement )
.reduce( createStatefulCollapseRadioGroup(), [] );
.reduce( accumulator, [] );
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ class FlatTermSelector extends Component {
}

updateSelectedTerms( terms = [] ) {
const selectedTerms = terms.reduce( ( result, termId ) => {
const selectedTerms = terms.reduce( ( resultAccumulator, termId ) => {
const termObject = find( this.state.availableTerms, ( term ) => term.id === termId );
if ( termObject ) {
result.push( termObject.name );
resultAccumulator.push( termObject.name );
}

return result;
return resultAccumulator;
}, [] );
this.setState( {
selectedTerms,
Expand Down
6 changes: 3 additions & 3 deletions packages/element/src/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,18 +185,18 @@ export { Suspense };
* @return {Array} The concatenated value.
*/
export function concatChildren( ...childrenArguments ) {
return childrenArguments.reduce( ( result, children, i ) => {
return childrenArguments.reduce( ( resultAccumulator, children, i ) => {
Children.forEach( children, ( child, j ) => {
if ( child && 'string' !== typeof child ) {
child = cloneElement( child, {
key: [ i, j ].join(),
} );
}

result.push( child );
resultAccumulator.push( child );
} );

return result;
return resultAccumulator;
}, [] );
}

Expand Down
2 changes: 1 addition & 1 deletion packages/rich-text/src/test/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { ZWNBSP } from '../../special-characters';

export function getSparseArrayLength( array ) {
return array.reduce( ( i ) => i + 1, 0 );
return array.reduce( ( accumulator ) => accumulator + 1, 0 );
}

const em = { type: 'em' };
Expand Down