commit
75bed609fe
|
@ -76,9 +76,10 @@ export function isSame(x: unknown, y: unknown): boolean {
|
|||
if (typeof x !== typeof y) {
|
||||
return false;
|
||||
}
|
||||
// 如果两个对象都是null或undefined,直接返回true
|
||||
// 此时x和y类型一致,若都为undefined或null返回true,但也有可能此时为一个对象和null,这种情况直接比较
|
||||
// typeof null === 'object'
|
||||
if (x == null || y == null) {
|
||||
return true;
|
||||
return x === y;
|
||||
}
|
||||
// 如果两个对象都是基本类型,比较他们的值是否相等
|
||||
if (typeof x !== 'object') {
|
||||
|
|
|
@ -103,15 +103,11 @@ export function connect<StateProps, DispatchProps, OwnProps, MergedProps>(
|
|||
dispatchProps,
|
||||
ownProps
|
||||
): MergedProps => ({ ...stateProps, ...dispatchProps, ...ownProps } as unknown as MergedProps),
|
||||
options?: ConnectOption
|
||||
options: ConnectOption = {},
|
||||
): Connector<OwnProps, MergedProps> {
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
|
||||
//this component should bear the type returned from mapping functions
|
||||
return (Component: OriginalComponent<MergedProps>): WrappedComponent<OwnProps> => {
|
||||
const useStore = createStoreHook(options?.context || DefaultContext);
|
||||
const useStore = createStoreHook(options.context || DefaultContext);
|
||||
|
||||
//this component should mimic original type of component used
|
||||
const Wrapper: WrappedComponent<OwnProps> = (props: OwnProps) => {
|
||||
|
@ -131,7 +127,7 @@ export function connect<StateProps, DispatchProps, OwnProps, MergedProps>(
|
|||
});
|
||||
|
||||
let mappedState: StateProps;
|
||||
if (options?.areStatesEqual) {
|
||||
if (options.areStatesEqual) {
|
||||
if (options.areStatesEqual(previous.current.state, state)) {
|
||||
mappedState = previous.current.mappedState as StateProps;
|
||||
} else {
|
||||
|
@ -168,7 +164,7 @@ export function connect<StateProps, DispatchProps, OwnProps, MergedProps>(
|
|||
return createElement(Component, mergedProps);
|
||||
};
|
||||
|
||||
if (options?.forwardRef) {
|
||||
if (options.forwardRef) {
|
||||
const forwarded = forwardRef((props, ref) => {
|
||||
return Wrapper({ ...props, ref: ref });
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue