[inulax] history参数异常问题修复

This commit is contained in:
wangxinrong 2023-11-01 21:56:49 +08:00
parent 628e09fe20
commit 8c0372803c
2 changed files with 7 additions and 19 deletions

View File

@ -20,14 +20,13 @@ import RouterContext from './context';
function withRouter<C extends ComponentType>(Component: C) { function withRouter<C extends ComponentType>(Component: C) {
function ComponentWithRouterProp(props: any) { function ComponentWithRouterProp(props: any) {
const { wrappedComponentRef, ...rest } = props;
const { history, location, match } = useContext(RouterContext); const { history, location, match } = useContext(RouterContext);
const routeProps = { history: history, location: location, match: match }; const routeProps = { history: history, location: location, match: match };
return <Component {...routeProps} {...rest} ref={wrappedComponentRef} />; return <Component {...props} {...routeProps} />;
} }
return ComponentWithRouterProp; return ComponentWithRouterProp;
} }
export default withRouter; export default withRouter;

View File

@ -17,7 +17,6 @@ import { useState, useContext, useEffect, useRef } from '../../renderer/hooks/Ho
import { createContext } from '../../renderer/components/context/CreateContext'; import { createContext } from '../../renderer/components/context/CreateContext';
import { createElement } from '../../external/JSXElement'; import { createElement } from '../../external/JSXElement';
import type { ReduxStoreHandler, ReduxAction, BoundActionCreator } from './redux'; import type { ReduxStoreHandler, ReduxAction, BoundActionCreator } from './redux';
import { forwardRef } from '../../renderer/components/ForwardRef';
const DefaultContext = createContext(null); const DefaultContext = createContext(null);
type Context = typeof DefaultContext; type Context = typeof DefaultContext;
@ -91,11 +90,6 @@ type MergePropsP<StateProps, DispatchProps, OwnProps, MergedProps> = (
type WrappedComponent<OwnProps> = (props: OwnProps) => ReturnType<typeof createElement>; type WrappedComponent<OwnProps> = (props: OwnProps) => ReturnType<typeof createElement>;
type OriginalComponent<MergedProps> = (props: MergedProps) => ReturnType<typeof createElement>; type OriginalComponent<MergedProps> = (props: MergedProps) => ReturnType<typeof createElement>;
type Connector<OwnProps, MergedProps> = (Component: OriginalComponent<MergedProps>) => WrappedComponent<OwnProps>; type Connector<OwnProps, MergedProps> = (Component: OriginalComponent<MergedProps>) => WrappedComponent<OwnProps>;
type ConnectOption<State = any> = {
areStatesEqual?: (oldState: State, newState: State) => boolean;
context?: Context;
forwardRef?: boolean
}
export function connect<StateProps, DispatchProps, OwnProps, MergedProps>( export function connect<StateProps, DispatchProps, OwnProps, MergedProps>(
mapStateToProps: MapStateToPropsP<StateProps, OwnProps> = () => ({} as StateProps), mapStateToProps: MapStateToPropsP<StateProps, OwnProps> = () => ({} as StateProps),
@ -103,9 +97,12 @@ export function connect<StateProps, DispatchProps, OwnProps, MergedProps>(
mergeProps: MergePropsP<StateProps, DispatchProps, OwnProps, MergedProps> = ( mergeProps: MergePropsP<StateProps, DispatchProps, OwnProps, MergedProps> = (
stateProps, stateProps,
dispatchProps, dispatchProps,
ownProps, ownProps
): MergedProps => ({ ...stateProps, ...dispatchProps, ...ownProps } as unknown as MergedProps), ): MergedProps => ({ ...stateProps, ...dispatchProps, ...ownProps } as unknown as MergedProps),
options: ConnectOption, options?: {
areStatesEqual?: (oldState: any, newState: any) => boolean;
context?: Context;
}
): Connector<OwnProps, MergedProps> { ): Connector<OwnProps, MergedProps> {
if (!options) { if (!options) {
options = {}; options = {};
@ -162,7 +159,6 @@ export function connect<StateProps, DispatchProps, OwnProps, MergedProps>(
mappedDispatch = mapDispatchToProps(store.dispatch, props); mappedDispatch = mapDispatchToProps(store.dispatch, props);
} }
} }
mappedDispatch = Object.assign({}, mappedDispatch, { dispatch: store.dispatch });
const mergedProps = ( const mergedProps = (
mergeProps || mergeProps ||
((state, dispatch, originalProps) => { ((state, dispatch, originalProps) => {
@ -176,13 +172,6 @@ export function connect<StateProps, DispatchProps, OwnProps, MergedProps>(
return node; return node;
}; };
if (options.forwardRef) {
const forwarded = forwardRef(function (props, ref) {
return Wrapper({ ...props, ref: ref });
});
return forwarded as WrappedComponent<OwnProps>;
}
return Wrapper; return Wrapper;
}; };
} }