Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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