Skip to content

Commit

Permalink
Code Style: Change name of accumulated variables when using reduce fu…
Browse files Browse the repository at this point in the history
…nction (#17893)

* Fix issue-7378 - change name of accumulated variables when using reduce function

* fix issue-7378 - update variables names

* fix issue-7378 - update variables names
  • Loading branch information
lozinska authored and gziolo committed Oct 15, 2019
1 parent 090b89e commit 5051d6a
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 46 deletions.
4 changes: 2 additions & 2 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ export const getGlobalBlockCount = createSelector(
if ( ! blockName ) {
return clientIds.length;
}
return reduce( clientIds, ( count, clientId ) => {
return reduce( clientIds, ( accumulator, clientId ) => {
const block = state.blocks.byClientId[ clientId ];
return block.name === blockName ? count + 1 : count;
return block.name === blockName ? accumulator + 1 : accumulator;
}, 0 );
},
( state ) => [
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( ( accumulator, innerBlock ) => {
const { originalContent } = innerBlock;

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

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

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

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

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( ( accumulator, block ) => {
const width = getEffectiveColumnWidth( block, totalBlockCount );
return Object.assign( result, { [ block.clientId ]: width } );
return Object.assign( accumulator, { [ 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( ( accumulator, block ) => {
const { align } = block.attributes;
return alignments.indexOf( align ) > alignments.indexOf( result ) ? align : result;
return alignments.indexOf( align ) > alignments.indexOf( accumulator ) ? align : accumulator;
}, 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 @@ -96,9 +96,9 @@ export const coreBlocks = [
textColumns,
verse,
video,
].reduce( ( memo, block ) => {
memo[ block.name ] = block;
return memo;
].reduce( ( accumulator, block ) => {
accumulator[ block.name ] = block;
return accumulator;
}, {} );

/**
Expand Down
16 changes: 8 additions & 8 deletions packages/blocks/src/api/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,26 @@ 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 sanitizedAttributes = reduce( blockType.attributes, ( accumulator, schema, key ) => {
const value = attributes[ key ];

if ( undefined !== value ) {
result[ key ] = value;
accumulator[ key ] = value;
} else if ( schema.hasOwnProperty( 'default' ) ) {
result[ key ] = schema.default;
accumulator[ key ] = schema.default;
}

if ( [ 'node', 'children' ].indexOf( schema.source ) !== -1 ) {
// Ensure value passed is always an array, which we're expecting in
// the RichText component to handle the deprecated value.
if ( typeof result[ key ] === 'string' ) {
result[ key ] = [ result[ key ] ];
} else if ( ! Array.isArray( result[ key ] ) ) {
result[ key ] = [];
if ( typeof accumulator[ key ] === 'string' ) {
accumulator[ key ] = [ accumulator[ key ] ];
} else if ( ! Array.isArray( accumulator[ key ] ) ) {
accumulator[ key ] = [];
}
}

return result;
return accumulator;
}, {} );

const clientId = uuid();
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( ( accumulator, blockNode ) => {
const block = createBlockWithFallback( blockNode );
if ( block ) {
memo.push( block );
accumulator.push( block );
}
return memo;
return accumulator;
}, [] );

/**
Expand Down
13 changes: 6 additions & 7 deletions packages/blocks/src/api/serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,28 +150,27 @@ 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 ) => {
return reduce( blockType.attributes, ( accumulator, attributeSchema, key ) => {
const value = attributes[ key ];

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

// 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 accumulator;
}

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

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

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( ( accumulator, key ) => Object.assign( accumulator, {
[ key ]: ( state, action ) => action.nextState[ key ],
} ), {} );

Expand Down
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( ( accumulator, termId ) => {
const termObject = find( this.state.availableTerms, ( term ) => term.id === termId );
if ( termObject ) {
result.push( termObject.name );
accumulator.push( termObject.name );
}

return result;
return accumulator;
}, [] );
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( ( accumulator, children, i ) => {
Children.forEach( children, ( child, j ) => {
if ( child && 'string' !== typeof child ) {
child = cloneElement( child, {
key: [ i, j ].join(),
} );
}

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

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

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

0 comments on commit 5051d6a

Please sign in to comment.