mergeProps.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
  3. exports.__esModule = true;
  4. exports["default"] = void 0;
  5. exports.defaultMergeProps = defaultMergeProps;
  6. exports.whenMergePropsIsFunction = whenMergePropsIsFunction;
  7. exports.whenMergePropsIsOmitted = whenMergePropsIsOmitted;
  8. exports.wrapMergePropsFunc = wrapMergePropsFunc;
  9. var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
  10. var _verifyPlainObject = _interopRequireDefault(require("../utils/verifyPlainObject"));
  11. function defaultMergeProps(stateProps, dispatchProps, ownProps) {
  12. return (0, _extends2["default"])({}, ownProps, stateProps, dispatchProps);
  13. }
  14. function wrapMergePropsFunc(mergeProps) {
  15. return function initMergePropsProxy(dispatch, _ref) {
  16. var displayName = _ref.displayName,
  17. pure = _ref.pure,
  18. areMergedPropsEqual = _ref.areMergedPropsEqual;
  19. var hasRunOnce = false;
  20. var mergedProps;
  21. return function mergePropsProxy(stateProps, dispatchProps, ownProps) {
  22. var nextMergedProps = mergeProps(stateProps, dispatchProps, ownProps);
  23. if (hasRunOnce) {
  24. if (!pure || !areMergedPropsEqual(nextMergedProps, mergedProps)) mergedProps = nextMergedProps;
  25. } else {
  26. hasRunOnce = true;
  27. mergedProps = nextMergedProps;
  28. if (process.env.NODE_ENV !== 'production') (0, _verifyPlainObject["default"])(mergedProps, displayName, 'mergeProps');
  29. }
  30. return mergedProps;
  31. };
  32. };
  33. }
  34. function whenMergePropsIsFunction(mergeProps) {
  35. return typeof mergeProps === 'function' ? wrapMergePropsFunc(mergeProps) : undefined;
  36. }
  37. function whenMergePropsIsOmitted(mergeProps) {
  38. return !mergeProps ? function () {
  39. return defaultMergeProps;
  40. } : undefined;
  41. }
  42. var _default = [whenMergePropsIsFunction, whenMergePropsIsOmitted];
  43. exports["default"] = _default;