1 | ;
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
4 | Object.defineProperty(exports, "__esModule", {
|
5 | value: true
|
6 | });
|
7 | exports.default = void 0;
|
8 | var _isEqual = _interopRequireDefault(require("./isEqual"));
|
9 | /**
|
10 | * Copyright 2013-present, Facebook, Inc.
|
11 | * All rights reserved.
|
12 | *
|
13 | * This source code is licensed under the BSD-style license found in the
|
14 | * LICENSE file in the root directory of this source tree. An additional grant
|
15 | * of patent rights can be found in the PATENTS file in the same directory.
|
16 | *
|
17 | * @providesModule ReactComponentWithPureRenderMixin
|
18 | */
|
19 |
|
20 | function shallowCompare(instance, nextProps, nextState) {
|
21 | return !(0, _isEqual.default)(instance.props, nextProps, true) || !(0, _isEqual.default)(instance.state, nextState, true);
|
22 | }
|
23 |
|
24 | /**
|
25 | * If your React component's render function is "pure", e.g. it will render the
|
26 | * same result given the same props and state, provide this mixin for a
|
27 | * considerable performance boost.
|
28 | *
|
29 | * Most React components have pure render functions.
|
30 | *
|
31 | * Example:
|
32 | *
|
33 | * var ReactComponentWithPureRenderMixin =
|
34 | * require('ReactComponentWithPureRenderMixin');
|
35 | * React.createClass({
|
36 | * mixins: [ReactComponentWithPureRenderMixin],
|
37 | *
|
38 | * render: function() {
|
39 | * return <div className={this.props.className}>foo</div>;
|
40 | * }
|
41 | * });
|
42 | *
|
43 | * Note: This only checks shallow equality for props and state. If these contain
|
44 | * complex data structures this mixin may have false-negatives for deeper
|
45 | * differences. Only mixin to components which have simple props and state, or
|
46 | * use `forceUpdate()` when you know deep data structures have changed.
|
47 | *
|
48 | * See https://facebook.github.io/react/docs/pure-render-mixin.html
|
49 | */
|
50 | var ReactComponentWithPureRenderMixin = {
|
51 | shouldComponentUpdate: function shouldComponentUpdate(nextProps, nextState) {
|
52 | return shallowCompare(this, nextProps, nextState);
|
53 | }
|
54 | };
|
55 | var _default = exports.default = ReactComponentWithPureRenderMixin; |
\ | No newline at end of file |