!103 [inulax] isSame比较方法问题修复

Merge pull request !103 from xuan/main
This commit is contained in:
openInula-robot 2023-12-07 01:23:58 +00:00 committed by Gitee
commit 75bed609fe
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 7 additions and 10 deletions

View File

@ -76,9 +76,10 @@ export function isSame(x: unknown, y: unknown): boolean {
if (typeof x !== typeof y) { if (typeof x !== typeof y) {
return false; return false;
} }
// 如果两个对象都是null或undefined直接返回true // 此时x和y类型一致若都为undefined或null返回true但也有可能此时为一个对象和null这种情况直接比较
// typeof null === 'object'
if (x == null || y == null) { if (x == null || y == null) {
return true; return x === y;
} }
// 如果两个对象都是基本类型,比较他们的值是否相等 // 如果两个对象都是基本类型,比较他们的值是否相等
if (typeof x !== 'object') { if (typeof x !== 'object') {

View File

@ -103,15 +103,11 @@ export function connect<StateProps, DispatchProps, OwnProps, MergedProps>(
dispatchProps, dispatchProps,
ownProps ownProps
): MergedProps => ({ ...stateProps, ...dispatchProps, ...ownProps } as unknown as MergedProps), ): MergedProps => ({ ...stateProps, ...dispatchProps, ...ownProps } as unknown as MergedProps),
options?: ConnectOption options: ConnectOption = {},
): Connector<OwnProps, MergedProps> { ): Connector<OwnProps, MergedProps> {
if (!options) {
options = {};
}
//this component should bear the type returned from mapping functions //this component should bear the type returned from mapping functions
return (Component: OriginalComponent<MergedProps>): WrappedComponent<OwnProps> => { 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 //this component should mimic original type of component used
const Wrapper: WrappedComponent<OwnProps> = (props: OwnProps) => { const Wrapper: WrappedComponent<OwnProps> = (props: OwnProps) => {
@ -131,7 +127,7 @@ export function connect<StateProps, DispatchProps, OwnProps, MergedProps>(
}); });
let mappedState: StateProps; let mappedState: StateProps;
if (options?.areStatesEqual) { if (options.areStatesEqual) {
if (options.areStatesEqual(previous.current.state, state)) { if (options.areStatesEqual(previous.current.state, state)) {
mappedState = previous.current.mappedState as StateProps; mappedState = previous.current.mappedState as StateProps;
} else { } else {
@ -168,7 +164,7 @@ export function connect<StateProps, DispatchProps, OwnProps, MergedProps>(
return createElement(Component, mergedProps); return createElement(Component, mergedProps);
}; };
if (options?.forwardRef) { if (options.forwardRef) {
const forwarded = forwardRef((props, ref) => { const forwarded = forwardRef((props, ref) => {
return Wrapper({ ...props, ref: ref }); return Wrapper({ ...props, ref: ref });
}); });