UNPKG

npmchenwei111

Version:

test1111

44 lines (32 loc) 958 B
/** * Created by chenwei on 2017/8/8. */ 'use strict' import React, { Component } from 'react' /** * 实现最简单的StaticContainer,控制子视图是否更新 */ class StaticContainer extends Component { static defaultProps: { shouldUpdate: undefined, observeData: undefined } constructor (props) { super(props) console.log('StaticContainer', this.props) } shouldComponentUpdate (nextProps) { if (typeof nextProps.shouldUpdate === 'function') { return nextProps.shouldUpdate(this.props.observeData, nextProps.observeData) } if (typeof nextProps.shouldUpdate === undefined && this.props.observeData && nextProps.observeData) { return JSON.stringify(nextProps.observeData) !== JSON.stringify(this.props.observeData) } return !!nextProps.shouldUpdate } render () { console.log('StaticContainer', 'render') return this.props.children } } export default StaticContainer