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 }); });