Skip to content

Commit ffbc5d1

Browse files
committed
refactor: remove lodash dependency #44
1 parent ce233ca commit ffbc5d1

File tree

5 files changed

+16
-22
lines changed

5 files changed

+16
-22
lines changed

package.json

-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
"@rollup/plugin-commonjs": "^16.0.0",
6868
"@rollup/plugin-node-resolve": "^10.0.0",
6969
"@types/jest": "^26.0.15",
70-
"@types/lodash": "^4.14.165",
7170
"@types/mockjs": "^1.0.3",
7271
"@typescript-eslint/eslint-plugin": "^4.8.2",
7372
"@typescript-eslint/parser": "^4.8.2",
@@ -87,7 +86,6 @@
8786
"jest": "^26.6.0",
8887
"jest-environment-jsdom-global": "^2.0.4",
8988
"lint-staged": "^10.5.2",
90-
"lodash": "^4.17.20",
9189
"mockjs": "^1.1.0",
9290
"node-fetch": "^2.6.1",
9391
"np": "^7.0.0",

src/core/createQuery.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import debounce from 'lodash/debounce';
2-
import throttle from 'lodash/throttle';
1+
import { debounce, throttle } from './utils/lodash';
32
import { computed, Ref, ref } from 'vue';
43
import { Config } from './config';
54
import { Queries } from './useAsyncQuery';
@@ -251,9 +250,13 @@ const createQuery = <R, P extends unknown[]>(
251250
};
252251

253252
const debouncedRun =
254-
!isNil(debounceInterval) && debounce(_run, debounceInterval);
253+
!isNil(debounceInterval) && debounce(_run, debounceInterval!);
255254
const throttledRun =
256-
!isNil(throttleInterval) && throttle(_run, throttleInterval);
255+
!isNil(throttleInterval) &&
256+
throttle(_run, throttleInterval!, {
257+
leading: true,
258+
trailing: true,
259+
});
257260

258261
const run = (...args: P) => {
259262
clearAllTimer();

src/useLoadMore.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ import {
88
GLOBAL_OPTIONS_PROVIDE_KEY,
99
} from './core/config';
1010
import useAsyncQuery, { BaseResult } from './core/useAsyncQuery';
11-
import get from 'lodash/get';
1211
import generateService from './core/utils/generateService';
13-
import { isFunction } from './core/utils';
1412
import { ServiceParams } from './core/utils/types';
15-
import omit from 'lodash/omit';
13+
import { omit, get, isFunction } from './core/utils';
1614

1715
export interface LoadMoreResult<R, P extends unknown[], LR extends unknown[]>
1816
extends Omit<BaseResult<R, P>, 'queries' | 'refresh' | 'mutate'> {
@@ -151,7 +149,7 @@ function useLoadMore<R, P extends unknown[], FR, LR extends unknown[]>(
151149
const dataList = computed(() => {
152150
let list: any[] = [];
153151
Object.values(queries).forEach(h => {
154-
const dataList = get(h.data, listKey);
152+
const dataList = get(h.data!, listKey);
155153
if (dataList && Array.isArray(dataList)) {
156154
list = list.concat(dataList);
157155
}

src/usePagination.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import {
88
GLOBAL_OPTIONS_PROVIDE_KEY,
99
} from './core/config';
1010
import useAsyncQuery, { BaseResult } from './core/useAsyncQuery';
11-
import merge from 'lodash/merge';
12-
import get from 'lodash/get';
11+
import { merge } from './core/utils/lodash';
12+
import { get } from './core/utils';
1313
import generateService from './core/utils/generateService';
1414
import { IService } from './core/utils/types';
1515

@@ -87,7 +87,7 @@ function usePagination<R, P extends unknown[], FR>(
8787
{ pagination: getGlobalOptions().pagination ?? {} },
8888
{ pagination: injectedGlobalOptions.pagination ?? {} },
8989
options ?? ({} as any),
90-
);
90+
) as any;
9191

9292
if (queryKey) {
9393
throw new Error('usePagination does not support concurrent request');
@@ -103,7 +103,7 @@ function usePagination<R, P extends unknown[], FR>(
103103
],
104104
},
105105
restOptions,
106-
);
106+
) as any;
107107

108108
const { data, params, queries, run, reset, ...rest } = useAsyncQuery<
109109
R,
@@ -147,7 +147,7 @@ function usePagination<R, P extends unknown[], FR>(
147147
}
148148
};
149149

150-
const total = computed<number>(() => get(data.value, totalKey, 0));
150+
const total = computed<number>(() => get(data.value!, totalKey, 0));
151151
const current = computed({
152152
get: () =>
153153
(params.value[0] as Record<string, number>)?.[currentKey] ??
@@ -165,7 +165,7 @@ function usePagination<R, P extends unknown[], FR>(
165165
},
166166
});
167167
const totalPage = computed<number>(() =>
168-
get(data.value, totalPageKey, Math.ceil(total.value / pageSize.value)),
168+
get(data.value!, totalPageKey, Math.ceil(total.value / pageSize.value)),
169169
);
170170

171171
return {

yarn.lock

+1-6
Original file line numberDiff line numberDiff line change
@@ -1475,11 +1475,6 @@
14751475
dependencies:
14761476
"@types/node" "*"
14771477

1478-
"@types/lodash@^4.14.165":
1479-
version "4.14.168"
1480-
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.168.tgz#fe24632e79b7ade3f132891afff86caa5e5ce008"
1481-
integrity sha512-oVfRvqHV/V6D1yifJbVRU3TMp8OT6o6BG+U9MkwuJ3U8/CsDHvalRpsxBqivn71ztOFZBTfJMvETbqHiaNSj7Q==
1482-
14831478
"@types/minimist@^1.2.0":
14841479
version "1.2.1"
14851480
resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.1.tgz#283f669ff76d7b8260df8ab7a4262cc83d988256"
@@ -5507,7 +5502,7 @@ lodash.zip@^4.2.0:
55075502
resolved "https://registry.yarnpkg.com/lodash.zip/-/lodash.zip-4.2.0.tgz#ec6662e4896408ed4ab6c542a3990b72cc080020"
55085503
integrity sha1-7GZi5IlkCO1KtsVCo5kLcswIACA=
55095504

5510-
[email protected], lodash@^4.17.12, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.20, lodash@^4.17.21, lodash@^4.7.0:
5505+
[email protected], lodash@^4.17.12, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.21, lodash@^4.7.0:
55115506
version "4.17.21"
55125507
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
55135508
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==

0 commit comments

Comments
 (0)