Skip to content

Commit aefb480

Browse files
committed
feat: injectKeepAlive add props
1 parent 9e5f6d6 commit aefb480

File tree

4 files changed

+11232
-11
lines changed

4 files changed

+11232
-11
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
},
6161
"dependencies": {
6262
"@babel/runtime": "^7.11.2",
63-
"@planjs/utils": "^1.0.7",
63+
"@planjs/utils": "^1.5.1",
6464
"hoist-non-react-statics": "^3.3.2",
6565
"js-md5": "^0.7.3"
6666
},
@@ -74,7 +74,7 @@
7474
"@babel/preset-typescript": "^7.10.4",
7575
"@commitlint/cli": "^9.1.2",
7676
"@commitlint/config-conventional": "^11.0.0",
77-
"@planjs/fabric": "^0.0.5",
77+
"@planjs/fabric": "^0.0.73",
7878
"@testing-library/react": "^10.4.9",
7979
"@types/hoist-non-react-statics": "^3.3.1",
8080
"@types/jest": "^26.0.10",
@@ -93,7 +93,7 @@
9393
"react": "16.13.1",
9494
"react-dom": "16.13.1",
9595
"rimraf": "^3.0.2",
96-
"stan-builder": "^0.4.2",
96+
"stan-builder": "^0.9.9",
9797
"standard-version": "^9.0.0",
9898
"ts-jest": "^26.3.0",
9999
"typescript": "^4.1.2"

src/KeepAlive.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import { START_MOUNTING_DOM, LIFECYCLE } from './Provider';
44
import keepAlive, { COMMAND } from './utils/keepAliveDecorator';
55
import changePositionByComment from './utils/changePositionByComment';
66

7-
export interface KeepAliveProps {
7+
export interface KeepAliveProps<P = any> {
88
key?: string;
99
name?: string;
1010
disabled?: boolean;
1111
extra?: any;
12+
dynamicPros?: (componentProps: P, keepAliveProps: KeepAliveProps) => KeepAliveProps;
1213
}
1314

1415
interface IKeepAliveInnerProps extends KeepAliveProps {

src/injectKeepAlive.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import React from 'react';
22
import KeepAlive, { KeepAliveProps } from './KeepAlive';
33

4-
export default function injectKeepAlive(opt: KeepAliveProps) {
5-
return function <P = {}>(Component: React.ComponentType<P>) {
6-
return (props: P) => (
7-
<KeepAlive {...opt}>
8-
<Component {...props} />
9-
</KeepAlive>
10-
);
4+
export default function injectKeepAlive<P = {}>(opt: KeepAliveProps<P>) {
5+
return function (Component: React.ComponentType<P>) {
6+
return (props: P) => {
7+
return (
8+
<KeepAlive {...(opt?.dynamicPros?.(props, opt) || opt)}>
9+
<Component {...props} />
10+
</KeepAlive>
11+
);
12+
};
1113
};
1214
}

0 commit comments

Comments
 (0)