@@ -5,11 +5,11 @@ import isPlainObject from '../utils/isPlainObject';
55import wrapActionCreators from '../utils/wrapActionCreators' ;
66import invariant from 'invariant' ;
77
8- const emptySelector = ( ) => ( { } ) ;
9- const defaultBinder = dispatch => ( { dispatch } ) ;
10- const identityMerge = ( slice , actionsCreators , props ) => ( {
8+ const defaultMapState = ( ) => ( { } ) ;
9+ const defaultMapDispatch = dispatch => ( { dispatch } ) ;
10+ const defaultMergeProps = ( stateSlice , actionsCreators , props ) => ( {
1111 ...props ,
12- ...slice ,
12+ ...stateSlice ,
1313 ...actionsCreators
1414} ) ;
1515
@@ -22,16 +22,14 @@ export default function createConnect(React) {
2222 const storeShape = createStoreShape ( PropTypes ) ;
2323
2424 return function connect (
25- select ,
26- dispatchBinder = defaultBinder ,
27- mergeHandler = identityMerge
25+ mapState = defaultMapState ,
26+ mapDispatchOrActionCreators = defaultMapDispatch ,
27+ mergeProps = defaultMergeProps
2828 ) {
29- const shouldSubscribe = select ? true : false ;
30- const selectState = select || emptySelector ;
31- const bindDispatch = isPlainObject ( dispatchBinder ) ?
32- wrapActionCreators ( dispatchBinder ) :
33- dispatchBinder ;
34- const merge = mergeHandler ;
29+ const shouldSubscribe = mapState !== defaultMapState ;
30+ const mapDispatch = isPlainObject ( mapDispatchOrActionCreators ) ?
31+ wrapActionCreators ( mapDispatchOrActionCreators ) :
32+ mapDispatchOrActionCreators ;
3533
3634 return DecoratedComponent => class ConnectDecorator extends Component {
3735 static displayName = `Connect(${ getDisplayName ( DecoratedComponent ) } )` ;
@@ -63,8 +61,8 @@ export default function createConnect(React) {
6361 super ( props , context ) ;
6462 this . setUnderlyingRef = ::this . setUnderlyingRef ;
6563 this . state = {
66- ...this . selectState ( props , context ) ,
67- ...this . bindDispatch ( context )
64+ ...this . mapState ( props , context ) ,
65+ ...this . mapDispatch ( context )
6866 } ;
6967 }
7068
@@ -82,32 +80,32 @@ export default function createConnect(React) {
8280 }
8381
8482 handleChange ( props = this . props ) {
85- const nextState = this . selectState ( props , this . context ) ;
83+ const nextState = this . mapState ( props , this . context ) ;
8684 if ( ! this . isSliceEqual ( this . state . slice , nextState . slice ) ) {
8785 this . setState ( nextState ) ;
8886 }
8987 }
9088
91- selectState ( props = this . props , context = this . context ) {
89+ mapState ( props = this . props , context = this . context ) {
9290 const state = context . store . getState ( ) ;
93- const slice = selectState ( state ) ;
91+ const slice = mapState ( state ) ;
9492
9593 invariant (
9694 isPlainObject ( slice ) ,
97- 'The return value of `select` prop must be an object. Instead received %s.' ,
95+ '`mapState` must return an object. Instead received %s.' ,
9896 slice
9997 ) ;
10098
10199 return { slice } ;
102100 }
103101
104- bindDispatch ( context = this . context ) {
102+ mapDispatch ( context = this . context ) {
105103 const { dispatch } = context . store ;
106- const actionCreators = bindDispatch ( dispatch ) ;
104+ const actionCreators = mapDispatch ( dispatch ) ;
107105
108106 invariant (
109107 isPlainObject ( actionCreators ) ,
110- 'The return value of `bindDispatch` prop must be an object. Instead received %s.' ,
108+ '`mapDispatch` must return an object. Instead received %s.' ,
111109 actionCreators
112110 ) ;
113111
@@ -116,11 +114,11 @@ export default function createConnect(React) {
116114
117115 merge ( props = this . props , state = this . state ) {
118116 const { slice, actionCreators } = state ;
119- const merged = merge ( slice , actionCreators , props ) ;
117+ const merged = mergeProps ( slice , actionCreators , props ) ;
120118
121119 invariant (
122120 isPlainObject ( merged ) ,
123- 'The return value of `merge` prop must be an object. Instead received %s.' ,
121+ '`mergeProps` must return an object. Instead received %s.' ,
124122 merged
125123 ) ;
126124
0 commit comments