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 8ba55a9
Showing 1 changed file with 13 additions and 4 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

0 comments on commit 8ba55a9

Please sign in to comment.