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

Fix(with-select): Rename parameter from mapStateToProps to mapSelectToProps. #10116

Merged
merged 2 commits into from Sep 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/data/src/components/with-select/index.js
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
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