mergeProps.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import _extends from "@babel/runtime/helpers/esm/extends";
  2. import verifyPlainObject from '../utils/verifyPlainObject';
  3. export function defaultMergeProps(stateProps, dispatchProps, ownProps) {
  4. return _extends({}, ownProps, stateProps, dispatchProps);
  5. }
  6. export function wrapMergePropsFunc(mergeProps) {
  7. return function initMergePropsProxy(dispatch, _ref) {
  8. var displayName = _ref.displayName,
  9. pure = _ref.pure,
  10. areMergedPropsEqual = _ref.areMergedPropsEqual;
  11. var hasRunOnce = false;
  12. var mergedProps;
  13. return function mergePropsProxy(stateProps, dispatchProps, ownProps) {
  14. var nextMergedProps = mergeProps(stateProps, dispatchProps, ownProps);
  15. if (hasRunOnce) {
  16. if (!pure || !areMergedPropsEqual(nextMergedProps, mergedProps)) mergedProps = nextMergedProps;
  17. } else {
  18. hasRunOnce = true;
  19. mergedProps = nextMergedProps;
  20. if (process.env.NODE_ENV !== 'production') verifyPlainObject(mergedProps, displayName, 'mergeProps');
  21. }
  22. return mergedProps;
  23. };
  24. };
  25. }
  26. export function whenMergePropsIsFunction(mergeProps) {
  27. return typeof mergeProps === 'function' ? wrapMergePropsFunc(mergeProps) : undefined;
  28. }
  29. export function whenMergePropsIsOmitted(mergeProps) {
  30. return !mergeProps ? function () {
  31. return defaultMergeProps;
  32. } : undefined;
  33. }
  34. export default [whenMergePropsIsFunction, whenMergePropsIsOmitted];