Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | 1x 1x 112766x 1341575x 112766x 54279x 58487x 679362x 4189x 54298x 662213x 54298x 60995x 60995x 60995x 60995x | import { Component } from 'react'; import PropTypes from 'prop-types/prop-types'; // Check to see whether two `prop` or `state` objects are roughly equal to each // other, enough so that we don't need to re-render a node if that's all that // changed. function vaguelyEqual(x, y) { const ignoreProps = ["location", "children", "ast", "hash"]; function ignoreProp(object, prop) { // There _shouldn't_ be any relevant differences between functions in `props`. // We hope, we hope. return ignoreProps.includes(prop) || typeof object[prop] === "function"; } if (x === y) { return true; } for (let prop in x) { if (Object.prototype.hasOwnProperty.call(x,prop) && !ignoreProp(x, prop) && x[prop] !== y[prop]) { return false; } } for (let prop in y) { Iif (Object.prototype.hasOwnProperty.call(y,prop) && !ignoreProp(y, prop) && y[prop] !== x[prop]) { return false; } } return true; } export default class BlockComponent extends Component { static propTypes = { node: PropTypes.object } shouldComponentUpdate(props, state) { // NOTE: don't care about the node since the patching algorithm will deal // with the update already const {node: newValue, ...newProps} = props; const {node: oldValue, ...oldProps} = this.props; const shouldUpdate = ( (newValue && oldValue && newValue.hash !== oldValue.hash) || !vaguelyEqual(newProps, oldProps) || !vaguelyEqual(state, this.state) ); return shouldUpdate; } } |