Skip to content

Commit

Permalink
Rename emptyArray to EMPTY_ARRAY
Browse files Browse the repository at this point in the history
  • Loading branch information
atimmer committed Nov 21, 2018
1 parent 254cf33 commit 2fc48e9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
17 changes: 13 additions & 4 deletions packages/annotations/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@
import createSelector from 'rememo';
import { get, flatMap } from 'lodash';

const emptyArray = [];
/**
* Shared reference to an empty array for cases where it is important to avoid
* returning a new array reference on every invocation, as in a connected or
* other pure component which performs `shouldComponentUpdate` check on props.
* This should be used as a last resort, since the normalized data should be
* maintained by the reducer result in state.
*
* @type {Array}
*/
const EMPTY_ARRAY = [];

/**
* Returns the annotations for a specific client ID.
Expand All @@ -21,12 +30,12 @@ export const __experimentalGetAnnotationsForBlock = createSelector(
} );
},
( state, blockClientId ) => [
get( state, blockClientId, emptyArray ),
get( state, blockClientId, EMPTY_ARRAY ),
]
);

export const __experimentalGetAllAnnotationsForBlock = function( state, blockClientId ) {
return get( state, blockClientId, [] );
return get( state, blockClientId, EMPTY_ARRAY );
};

/**
Expand Down Expand Up @@ -56,7 +65,7 @@ export const __experimentalGetAnnotationsForRichText = createSelector(
} );
},
( state, blockClientId ) => [
get( state, blockClientId, emptyArray ),
get( state, blockClientId, EMPTY_ARRAY ),
]
);

Expand Down
14 changes: 12 additions & 2 deletions packages/rich-text/src/register-format-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ import { select, dispatch, withSelect, withDispatch } from '@wordpress/data';
import { addFilter } from '@wordpress/hooks';
import { compose } from '@wordpress/compose';

/**
* Shared reference to an empty array for cases where it is important to avoid
* returning a new array reference on every invocation, as in a connected or
* other pure component which performs `shouldComponentUpdate` check on props.
* This should be used as a last resort, since the normalized data should be
* maintained by the reducer result in state.
*
* @type {Array}
*/
const EMPTY_ARRAY = [];

/**
* Registers a new format provided a unique name and an object defining its
* behavior.
Expand Down Expand Up @@ -120,8 +131,7 @@ export function registerFormatType( name, settings ) {

dispatch( 'core/rich-text' ).addFormatTypes( settings );

const emptyArray = [];
const getFunctionStackMemoized = memize( ( previousStack = emptyArray, newFunction ) => {
const getFunctionStackMemoized = memize( ( previousStack = EMPTY_ARRAY, newFunction ) => {
return [
...previousStack,
newFunction,
Expand Down

0 comments on commit 2fc48e9

Please sign in to comment.