[摘要]本篇文章给大家带来的内容是关于React-redux的源码分析(代码) ,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。Provider   //最后导出的是createProvid...
本篇文章给大家带来的内容是关于React-redux的源码分析(代码) ,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
Provider
   //最后导出的是createProvider()。所以一开始storeKey应该是以默认值‘store’传进去的
   function createProvider(storeKey = 'store', subKey) {
   const subscriptionKey = subKey    `${storeKey}Subscription`
   class Provider extends Component {
       //设置context,能让子组件拿到store
       //相当于返回 {store: this.store}
       getChildContext() {
         return { [storeKey]: this[storeKey], [subscriptionKey]: null }
       }
       constructor(props, context) {
         super(props, context)
         //this.store = props.store
         this[storeKey] = props.store;
       }
       render() {
         //只能有一个子组件
         return Children.only(this.props.children)
       }
   }
   
   //props和context类型验证
   Provider.propTypes = {
       store: storeShape.isRequired,
       children: PropTypes.element.isRequired,
   }
   Provider.childContextTypes = {