@@ -6,10 +6,12 @@ import wrapActionCreators from '../utils/wrapActionCreators';
66import invariant from 'invariant' ;
77
88const emptySelector = ( ) => ( { } ) ;
9-
109const emptyBinder = ( ) => ( { } ) ;
11-
12- const identityMerge = ( slice , actionsCreators , props ) => ( { ...props , ...slice , ...actionsCreators } ) ;
10+ const identityMerge = ( slice , actionsCreators , props ) => ( {
11+ ...props ,
12+ ...slice ,
13+ ...actionsCreators
14+ } ) ;
1315
1416function getDisplayName ( Component ) {
1517 return Component . displayName || Component . name || 'Component' ;
@@ -19,11 +21,17 @@ export default function createConnect(React) {
1921 const { Component, PropTypes } = React ;
2022 const storeShape = createStoreShape ( PropTypes ) ;
2123
22- return function connect ( select , dispatchBinder = emptyBinder , mergeHandler = identityMerge ) {
23-
24- const subscribing = select ? true : false ;
24+ return function connect (
25+ select ,
26+ dispatchBinder = emptyBinder ,
27+ mergeHandler = identityMerge
28+ ) {
29+ const shouldSubscribe = select ? true : false ;
2530 const selectState = select || emptySelector ;
26- const bindDispatch = isPlainObject ( dispatchBinder ) ? wrapActionCreators ( dispatchBinder ) : dispatchBinder ;
31+ const bindDispatch = isPlainObject ( dispatchBinder ) ?
32+ wrapActionCreators ( dispatchBinder ) :
33+ dispatchBinder ;
34+
2735 const merge = mergeHandler ;
2836
2937 return DecoratedComponent => class ConnectDecorator extends Component {
@@ -41,31 +49,35 @@ export default function createConnect(React) {
4149
4250 isSliceEqual ( slice , nextSlice ) {
4351 const isRefEqual = slice === nextSlice ;
44- if ( isRefEqual ) {
45- return true ;
46- } else if ( typeof slice !== 'object' || typeof nextSlice !== 'object' ) {
52+ if (
53+ isRefEqual ||
54+ typeof slice !== 'object' ||
55+ typeof nextSlice !== 'object'
56+ ) {
4757 return isRefEqual ;
4858 }
59+
4960 return shallowEqual ( slice , nextSlice ) ;
5061 }
5162
5263 constructor ( props , context ) {
5364 super ( props , context ) ;
65+ this . setUnderlyingRef = ::this . setUnderlyingRef ;
5466 this . state = {
5567 ...this . selectState ( props , context ) ,
5668 ...this . bindDispatch ( context )
5769 } ;
5870 }
5971
6072 componentDidMount ( ) {
61- if ( subscribing ) {
73+ if ( shouldSubscribe ) {
6274 this . subscribed = true ;
6375 this . unsubscribe = this . context . store . subscribe ( ::this . handleChange ) ;
6476 }
6577 }
6678
6779 componentWillUnmount ( ) {
68- if ( subscribing ) {
80+ if ( shouldSubscribe ) {
6981 this . unsubscribe ( ) ;
7082 }
7183 }
@@ -120,8 +132,15 @@ export default function createConnect(React) {
120132 return this . underlyingRef ;
121133 }
122134
135+ setUnderlyingRef ( instance ) {
136+ this . underlyingRef = instance ;
137+ }
138+
123139 render ( ) {
124- return < DecoratedComponent ref = { component => ( this . underlyingRef = component ) } { ...this . merge ( ) } /> ;
140+ return (
141+ < DecoratedComponent ref = { this . setUnderlyingRef }
142+ { ...this . merge ( ) } />
143+ ) ;
125144 }
126145 } ;
127146 } ;
0 commit comments