Skip to content

Commit

Permalink
Fix(with-select): Rename parameter from mapStateToProps to `mapSele…
Browse files Browse the repository at this point in the history
…ctToProps`. (#10116)

* Fix: with-select: Rename parameter to `mapSelectToProps`.

State isn't available here and the current parameter name
is confusing with Redux's parameter.
Moreover, in the guide it says `mapSelectToProps` ->
https://github.com/WordPress/gutenberg/blob/master/packages/data/README.md#withselect-mapselecttoprops-function--function

* Data: Rename test instances of mapStateToProps
  • Loading branch information
chinchang authored and aduth committed Sep 24, 2018
1 parent be0d523 commit 51f0174
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
10 changes: 5 additions & 5 deletions packages/data/src/components/with-select/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import { RegistryConsumer } from '../registry-provider';
* Higher-order component used to inject state-derived props using registered
* selectors.
*
* @param {Function} mapStateToProps Function called on every state change,
* @param {Function} mapSelectToProps Function called on every state change,
* expected to return object of props to
* merge with the component's own props.
*
* @return {Component} Enhanced component with merged state data props.
*/
const withSelect = ( mapStateToProps ) => createHigherOrderComponent( ( WrappedComponent ) => {
const withSelect = ( mapSelectToProps ) => createHigherOrderComponent( ( WrappedComponent ) => {
/**
* Default merge props. A constant value is used as the fallback since it
* can be more efficiently shallow compared in case component is repeatedly
Expand All @@ -31,15 +31,15 @@ const withSelect = ( mapStateToProps ) => createHigherOrderComponent( ( WrappedC
const DEFAULT_MERGE_PROPS = {};

/**
* Given a props object, returns the next merge props by mapStateToProps.
* Given a props object, returns the next merge props by mapSelectToProps.
*
* @param {Object} props Props to pass as argument to mapStateToProps.
* @param {Object} props Props to pass as argument to mapSelectToProps.
*
* @return {Object} Props to merge into rendered wrapped element.
*/
function getNextMergeProps( props ) {
return (
mapStateToProps( props.registry.select, props.ownProps ) ||
mapSelectToProps( props.registry.select, props.ownProps ) ||
DEFAULT_MERGE_PROPS
);
}
Expand Down
16 changes: 8 additions & 8 deletions packages/data/src/components/with-select/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,8 @@ describe( 'withSelect', () => {
},
} );

const childMapStateToProps = jest.fn();
const parentMapStateToProps = jest.fn().mockImplementation( ( _select ) => ( {
const childMapSelectToProps = jest.fn();
const parentMapSelectToProps = jest.fn().mockImplementation( ( _select ) => ( {
isRenderingChild: _select( 'childRender' ).getValue(),
} ) );

Expand All @@ -426,24 +426,24 @@ describe( 'withSelect', () => {
<div>{ props.isRenderingChild ? <Child /> : null }</div>
) );

const Child = withSelect( childMapStateToProps )( ChildOriginalComponent );
const Parent = withSelect( parentMapStateToProps )( ParentOriginalComponent );
const Child = withSelect( childMapSelectToProps )( ChildOriginalComponent );
const Parent = withSelect( parentMapSelectToProps )( ParentOriginalComponent );

TestRenderer.create(
<RegistryProvider value={ registry }>
<Parent />
</RegistryProvider>
);

expect( childMapStateToProps ).toHaveBeenCalledTimes( 1 );
expect( parentMapStateToProps ).toHaveBeenCalledTimes( 1 );
expect( childMapSelectToProps ).toHaveBeenCalledTimes( 1 );
expect( parentMapSelectToProps ).toHaveBeenCalledTimes( 1 );
expect( ChildOriginalComponent ).toHaveBeenCalledTimes( 1 );
expect( ParentOriginalComponent ).toHaveBeenCalledTimes( 1 );

registry.dispatch( 'childRender' ).toggleRender();

expect( childMapStateToProps ).toHaveBeenCalledTimes( 1 );
expect( parentMapStateToProps ).toHaveBeenCalledTimes( 2 );
expect( childMapSelectToProps ).toHaveBeenCalledTimes( 1 );
expect( parentMapSelectToProps ).toHaveBeenCalledTimes( 2 );
expect( ChildOriginalComponent ).toHaveBeenCalledTimes( 1 );
expect( ParentOriginalComponent ).toHaveBeenCalledTimes( 2 );
} );
Expand Down

0 comments on commit 51f0174

Please sign in to comment.