exportfunctioncreateConnect({connectHOC=connectAdvanced,mapStateToPropsFactories=defaultMapStateToPropsFactories,mapDispatchToPropsFactories=defaultMapDispatchToPropsFactories,mergePropsFactories=defaultMergePropsFactories,selectorFactory=defaultSelectorFactory}={}){returnfunctionconnect(mapStateToProps,mapDispatchToProps,mergeProps,{pure=true,areStatesEqual=strictEqual,areOwnPropsEqual=shallowEqual,areStatePropsEqual=shallowEqual,areMergedPropsEqual=shallowEqual,...extraOptions}={}){constinitMapStateToProps=match(mapStateToProps,mapStateToPropsFactories,'mapStateToProps')constinitMapDispatchToProps=match(mapDispatchToProps,mapDispatchToPropsFactories,'mapDispatchToProps')constinitMergeProps=match(mergeProps,mergePropsFactories,'mergeProps')returnconnectHOC(selectorFactory,{ // used in error messagesmethodName:'connect', // used to compute Connect's displayName from the wrapped component's displayName.getDisplayName:name=>`Connect(${name})`, // if mapStateToProps is falsy, the Connect component doesn't subscribe to store state changesshouldHandleStateChanges:Boolean(mapStateToProps), // passed through to selectorFactoryinitMapStateToProps,initMapDispatchToProps,initMergeProps,pure,areStatesEqual,areOwnPropsEqual,areStatePropsEqual,areMergedPropsEqual, // any extra options args can override defaults of connect or connectAdvanced...extraOptions})}}
// If pure is true, the selector returned by selectorFactory will memoize its results,
// allowing connectAdvanced's shouldComponentUpdate to return false if final
// props have not changed. If false, the selector will always return a new
// object and shouldComponentUpdate will always return true.
componentDidMount() {
if (!shouldHandleStateChanges) return
// componentWillMount fires during server side rendering, but componentDidMount and
// componentWillUnmount do not. Because of this, trySubscribe happens during ...didMount.
// Otherwise, unsubscription would never take place during SSR, causing a memory leak.
// To handle the case where a child component may have triggered a state change by
// dispatching an action in its componentWillMount, we have to re-run the select and maybe
// re-render.
this.subscription.trySubscribe()
this.selector.run(this.props)
if (this.selector.shouldComponentUpdate) this.forceUpdate()
}