From 9865efbcf6819fe8a519a235321f3e3c844b1d3e Mon Sep 17 00:00:00 2001 From: CJY Date: Fri, 10 May 2024 17:47:32 +0800 Subject: [PATCH] feat: add autoFreeze prop --- index.d.ts | 2 ++ src/components/CacheRoute.js | 6 ++++-- src/components/CacheSwitch.js | 4 ++-- src/core/Updatable/index.js | 4 ++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/index.d.ts b/index.d.ts index 2b50387..e534801 100644 --- a/index.d.ts +++ b/index.d.ts @@ -11,6 +11,7 @@ export interface CacheRouteProps extends RouteProps { unmount?: boolean saveScrollPosition?: boolean multiple?: boolean | number + autoFreeze?: boolean } export declare class CacheRoute extends React.Component {} @@ -18,6 +19,7 @@ export default CacheRoute export interface CacheSwitchProps extends SwitchProps { which?: (element: React.ElementType) => boolean + autoFreeze?: boolean } export declare class CacheSwitch extends React.Component {} diff --git a/src/components/CacheRoute.js b/src/components/CacheRoute.js index 1cbeb65..469416d 100644 --- a/src/components/CacheRoute.js +++ b/src/components/CacheRoute.js @@ -17,7 +17,8 @@ export default class CacheRoute extends Component { render: PropTypes.func, children: PropTypes.oneOfType([PropTypes.func, PropTypes.node]), computedMatchForCacheRoute: PropTypes.object, - multiple: PropTypes.oneOfType([PropTypes.bool, PropTypes.number]) + multiple: PropTypes.oneOfType([PropTypes.bool, PropTypes.number]), + autoFreeze: PropTypes.bool } static defaultProps = { @@ -39,6 +40,7 @@ export default class CacheRoute extends Component { saveScrollPosition, computedMatchForCacheRoute, multiple, + autoFreeze, ...restProps } = this.props @@ -87,7 +89,7 @@ export default class CacheRoute extends Component { const renderSingle = props => ( {cacheLifecycles => ( - + {() => { Object.assign(props, { cacheLifecycles }) diff --git a/src/components/CacheSwitch.js b/src/components/CacheSwitch.js index d8e1f07..58bd605 100644 --- a/src/components/CacheSwitch.js +++ b/src/components/CacheSwitch.js @@ -33,13 +33,13 @@ class CacheSwitch extends Switch { } render() { - const { children, which } = this.props + const { children, which, autoFreeze } = this.props const { location, match: contextMatch } = this.getContext() let __matchedAlready = false return ( - + {() => ( {React.Children.map(children, element => { diff --git a/src/core/Updatable/index.js b/src/core/Updatable/index.js index 2bf3d19..db8a2a9 100644 --- a/src/core/Updatable/index.js +++ b/src/core/Updatable/index.js @@ -52,8 +52,8 @@ class Updatable extends Component { shouldComponentUpdate = ({ when }) => when } -export default (props) => ( - +export default ({ autoFreeze = true, ...props }) => ( + )