ReactPureComponent模块用于创建PureComponent纯组件,特别,当继承ReactPureComponent的组件构造函数没有shouldComponentUpdate原型方法时,在ReactCompositeComponent模块中将使用shallowCompare浅比较React组件是否重绘。
'use strict'; var _assign = require('object-assign'); var ReactComponent = require('./ReactComponent'); var ReactNoopUpdateQueue = require('./ReactNoopUpdateQueue'); var emptyObject = require('fbjs/lib/emptyObject'); function ReactPureComponent(props, context, updater) { this.props = props; this.context = context; this.refs = emptyObject; this.updater = updater || ReactNoopUpdateQueue; } // 继承ReactComponent模块setState、forceUpdate方法重绘组件 function ComponentDummy() {} ComponentDummy.prototype = ReactComponent.prototype; ReactPureComponent.prototype = new ComponentDummy(); ReactPureComponent.prototype.constructor = ReactPureComponent; _assign(ReactPureComponent.prototype, ReactComponent.prototype); // PureComponent组件标识,“react-dom”包下的ReactCompositeComponent模块中用于区别组件 // 特别,当继承ReactPureComponent的组件构造函数没有shouldComponentUpdate原型方法时 // ReactCompositeComponent模块中将使用shallowCompare浅比较React组件是否重绘 ReactPureComponent.prototype.isPureReactComponent = true; module.exports = ReactPureComponent;