From 955b2cb5740fa4431081c64897e5a54e83f53366 Mon Sep 17 00:00:00 2001 From: huangxuan Date: Wed, 6 Dec 2023 16:01:07 +0800 Subject: [PATCH] =?UTF-8?q?[inulax]=20isSame=E6=AF=94=E8=BE=83=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/inula/src/inulax/CommonUtils.ts | 5 +++-- packages/inula/src/inulax/adapters/reduxReact.ts | 12 ++++-------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/packages/inula/src/inulax/CommonUtils.ts b/packages/inula/src/inulax/CommonUtils.ts index ccbb182f..5e309ca4 100644 --- a/packages/inula/src/inulax/CommonUtils.ts +++ b/packages/inula/src/inulax/CommonUtils.ts @@ -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') { diff --git a/packages/inula/src/inulax/adapters/reduxReact.ts b/packages/inula/src/inulax/adapters/reduxReact.ts index 32eff8d0..2b5a9dae 100644 --- a/packages/inula/src/inulax/adapters/reduxReact.ts +++ b/packages/inula/src/inulax/adapters/reduxReact.ts @@ -103,15 +103,11 @@ export function connect( dispatchProps, ownProps ): MergedProps => ({ ...stateProps, ...dispatchProps, ...ownProps } as unknown as MergedProps), - options?: ConnectOption + options: ConnectOption = {}, ): Connector { - if (!options) { - options = {}; - } - //this component should bear the type returned from mapping functions return (Component: OriginalComponent): WrappedComponent => { - const useStore = createStoreHook(options?.context || DefaultContext); + const useStore = createStoreHook(options.context || DefaultContext); //this component should mimic original type of component used const Wrapper: WrappedComponent = (props: OwnProps) => { @@ -131,7 +127,7 @@ export function connect( }); 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( return createElement(Component, mergedProps); }; - if (options?.forwardRef) { + if (options.forwardRef) { const forwarded = forwardRef((props, ref) => { return Wrapper({ ...props, ref: ref }); });