amis-rpc-design/node_modules/react-redux/es/connect/mergeProps.js
2023-10-07 19:42:30 +08:00

32 lines
1.2 KiB
JavaScript

import _extends from "@babel/runtime/helpers/esm/extends";
import verifyPlainObject from '../utils/verifyPlainObject';
import { createInvalidArgFactory } from './invalidArgFactory';
export function defaultMergeProps(stateProps, dispatchProps, ownProps) {
// @ts-ignore
return _extends({}, ownProps, stateProps, dispatchProps);
}
export function wrapMergePropsFunc(mergeProps) {
return function initMergePropsProxy(dispatch, {
displayName,
areMergedPropsEqual
}) {
let hasRunOnce = false;
let mergedProps;
return function mergePropsProxy(stateProps, dispatchProps, ownProps) {
const nextMergedProps = mergeProps(stateProps, dispatchProps, ownProps);
if (hasRunOnce) {
if (!areMergedPropsEqual(nextMergedProps, mergedProps)) mergedProps = nextMergedProps;
} else {
hasRunOnce = true;
mergedProps = nextMergedProps;
if (process.env.NODE_ENV !== 'production') verifyPlainObject(mergedProps, displayName, 'mergeProps');
}
return mergedProps;
};
};
}
export function mergePropsFactory(mergeProps) {
return !mergeProps ? () => defaultMergeProps : typeof mergeProps === 'function' ? wrapMergePropsFunc(mergeProps) : createInvalidArgFactory(mergeProps, 'mergeProps');
}