Skip to content

Commit 02f25e5

Browse files
committed
refactor code
1 parent 5c72bb5 commit 02f25e5

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/utils/strategyUtil.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ export function formatStrategyValues(
1717
): SafeKey[] {
1818
const valueSet = new Set(values);
1919

20-
if (strategy === SHOW_CHILD) {
21-
return values.filter(key => {
20+
const strategyHandlers = {
21+
[SHOW_CHILD]: (key: SafeKey) => {
2222
const entity = keyEntities[key];
2323
return (
2424
!entity ||
@@ -28,14 +28,14 @@ export function formatStrategyValues(
2828
({ node }) => isCheckDisabled(node) || valueSet.has(node[fieldNames.value]),
2929
)
3030
);
31-
});
32-
}
33-
if (strategy === SHOW_PARENT) {
34-
return values.filter(key => {
31+
},
32+
[SHOW_PARENT]: (key: SafeKey) => {
3533
const entity = keyEntities[key];
36-
const parent = entity ? entity.parent : null;
34+
const parent = entity?.parent;
3735
return !parent || isCheckDisabled(parent.node) || !valueSet.has(parent.key);
38-
});
39-
}
40-
return values;
36+
},
37+
[SHOW_ALL]: () => true,
38+
};
39+
40+
return values.filter(strategyHandlers[strategy] || strategyHandlers[SHOW_ALL]);
4141
}

0 commit comments

Comments
 (0)