Skip to content

Commit

Permalink
style: 用回 lodash-es
Browse files Browse the repository at this point in the history
  • Loading branch information
yyz945947732 committed Aug 28, 2023
1 parent aedea98 commit 300a7ea
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 44 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
],
"dependencies": {
"@alifd/next": "^1.26.22",
"lodash-es": "^4.17.21",
"moment": "^2.29.4",
"react-router-dom6": "npm:react-router-dom@^6.14.2",
"tree-lodash": "^0.3.1"
Expand Down Expand Up @@ -77,6 +78,7 @@
"@testing-library/jest-dom": "^6.0.0",
"@testing-library/react": "^14.0.0",
"@types/jest": "^29.5.3",
"@types/lodash-es": "^4.17.8",
"@types/node": "^16.18.39",
"@types/react": "^18.2.18",
"@types/react-dom": "^18.2.7",
Expand Down
12 changes: 3 additions & 9 deletions src/core/hooks/useAuthData.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { defaults, omit } from "lodash-es";
import { useContext } from "react";
import { filter, map } from "tree-lodash";

import { ProviderContext } from "../components/Provider";
import { ProxyContext } from "../components/Proxy";
import { ValidatorContext } from "../components/Validator";
import { omit } from "../utils";
import { isMatchAuth } from "../utils";

/** 配置项 */
Expand All @@ -31,13 +31,7 @@ export function useAuthData(data?: any[], options?: Options) {
if (!Array.isArray(data)) {
return data;
}
const combineOptions: Required<Options> = {
isTree: options?.isTree ?? defaultOptions.isTree,
childrenKey: options?.childrenKey ?? defaultOptions.childrenKey,
authKey: options?.authKey ?? defaultOptions.authKey,
isPreserveAuthKey:
options?.isPreserveAuthKey ?? defaultOptions.isPreserveAuthKey,
};
const combineOptions = defaults(options, defaultOptions);
const { auth, disabled } = useContext(ProviderContext);
const { authProxy } = useContext(ProxyContext);
const { validator } = useContext(ValidatorContext);
Expand All @@ -56,7 +50,7 @@ export function useAuthData(data?: any[], options?: Options) {
}

function mapFn(item: any) {
return omit(item, [combineOptions.authKey]);
return omit(item, combineOptions.authKey);
}

const authorizedData = combineOptions?.isTree
Expand Down
2 changes: 1 addition & 1 deletion src/core/hooks/useDetect.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { has } from "lodash-es";
import { useContext } from "react";

import { ProviderContext } from "../components/Provider";
import { has } from "../utils";

/** 检测组件使用是否合法 */
export function useDetect(componentName: string) {
Expand Down
8 changes: 0 additions & 8 deletions src/core/utils/has.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/core/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
export { has } from "./has";
export { isMatchAuth } from "./isMatchAuth";
export { omit } from "./omit";
3 changes: 2 additions & 1 deletion src/core/utils/isMatchAuth.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { isRegExp } from "lodash-es";

import type { ProviderProps } from "../index";
import { isRegExp } from "./isRegExp";

interface Options extends Omit<ProviderProps, "children"> {
/** 权限代理 */
Expand Down
4 changes: 0 additions & 4 deletions src/core/utils/isRegExp.ts

This file was deleted.

18 changes: 0 additions & 18 deletions src/core/utils/omit.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/test/useAuthData.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ describe("useAuthData", () => {
);
expect(result.current).toEqual(EXPECT_DATA_FOR_TEST_4);
});
test("Check if auth should be preserve if isPreserveAuthKey is false", () => {
test("Check if auth should not be preserve if isPreserveAuthKey is false", () => {
const { result } = renderHook(
() => useAuthData(MOCK_AUTH_DATA, { isPreserveAuthKey: false }),
{
Expand Down

0 comments on commit 300a7ea

Please sign in to comment.