@lemon-fe/hooks 0.0.5 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/index.d.ts +3 -7
- package/es/index.js +3 -57
- package/es/useAsyncEffect/index.d.ts +3 -0
- package/es/useAsyncEffect/index.js +13 -0
- package/es/useDebounce/index.d.ts +1 -0
- package/es/useDebounce/index.js +9 -0
- package/es/useInterval/index.d.ts +1 -0
- package/es/useInterval/index.js +22 -0
- package/es/useThrottle/index.d.ts +2 -0
- package/es/useThrottle/index.js +17 -0
- package/package.json +2 -2
package/es/index.d.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
cancelled: boolean;
|
|
5
|
-
}) => Promise<any>, deps?: any[]): void;
|
|
6
|
-
export declare function useDebounce<T extends (...args: any[]) => any>(cb: T, duration: number): import("lodash").DebouncedFunc<T>;
|
|
7
|
-
export declare function useThrottle<T extends (...args: any[]) => any>(cb: T, duration: number, options?: ThrottleSettings): import("lodash").DebouncedFunc<T>;
|
|
1
|
+
export { default as useDebounce } from './useDebounce';
|
|
2
|
+
export { default as useThrottle } from './useThrottle';
|
|
3
|
+
export { default as useInterval } from './useInterval';
|
|
8
4
|
export { default as usePrimaryColor } from './usePrimaryColor';
|
|
9
5
|
export { default as useRequest } from './useRequest';
|
package/es/index.js
CHANGED
|
@@ -1,59 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
-
|
|
7
|
-
import { useRef, useEffect, useCallback } from 'react';
|
|
8
|
-
import { debounce, throttle } from 'lodash';
|
|
9
|
-
|
|
10
|
-
var noop = function noop() {};
|
|
11
|
-
|
|
12
|
-
export function useInterval(callback, delay) {
|
|
13
|
-
var savedCallback = useRef(callback);
|
|
14
|
-
useEffect(function () {
|
|
15
|
-
savedCallback.current = callback;
|
|
16
|
-
}, [callback]);
|
|
17
|
-
useEffect(function () {
|
|
18
|
-
if (delay !== null) {
|
|
19
|
-
var id = setInterval(function () {
|
|
20
|
-
savedCallback.current();
|
|
21
|
-
}, delay);
|
|
22
|
-
return function () {
|
|
23
|
-
return clearInterval(id);
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return noop;
|
|
28
|
-
}, [delay]);
|
|
29
|
-
}
|
|
30
|
-
export function useAsyncEffect(cb) {
|
|
31
|
-
var deps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
32
|
-
useEffect(function () {
|
|
33
|
-
var flag = {
|
|
34
|
-
cancelled: false
|
|
35
|
-
};
|
|
36
|
-
cb(flag);
|
|
37
|
-
return function () {
|
|
38
|
-
flag.cancelled = true;
|
|
39
|
-
};
|
|
40
|
-
}, deps);
|
|
41
|
-
}
|
|
42
|
-
export function useDebounce(cb, duration) {
|
|
43
|
-
var ref = useRef(cb);
|
|
44
|
-
ref.current = cb;
|
|
45
|
-
return useCallback(debounce(function () {
|
|
46
|
-
return ref.current.apply(ref, arguments);
|
|
47
|
-
}, duration), []);
|
|
48
|
-
}
|
|
49
|
-
export function useThrottle(cb, duration, options) {
|
|
50
|
-
var ref = useRef(cb);
|
|
51
|
-
ref.current = cb;
|
|
52
|
-
return useCallback(throttle(function () {
|
|
53
|
-
return ref.current.apply(ref, arguments);
|
|
54
|
-
}, duration, _objectSpread({
|
|
55
|
-
trailing: false
|
|
56
|
-
}, options)), []);
|
|
57
|
-
}
|
|
1
|
+
export { default as useDebounce } from './useDebounce';
|
|
2
|
+
export { default as useThrottle } from './useThrottle';
|
|
3
|
+
export { default as useInterval } from './useInterval';
|
|
58
4
|
export { default as usePrimaryColor } from './usePrimaryColor';
|
|
59
5
|
export { default as useRequest } from './useRequest';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
export default function useAsyncEffect(cb) {
|
|
3
|
+
var deps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
4
|
+
useEffect(function () {
|
|
5
|
+
var flag = {
|
|
6
|
+
cancelled: false
|
|
7
|
+
};
|
|
8
|
+
cb(flag);
|
|
9
|
+
return function () {
|
|
10
|
+
flag.cancelled = true;
|
|
11
|
+
};
|
|
12
|
+
}, deps);
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function useDebounce<T extends (...args: any[]) => any>(cb: T, duration: number): import("lodash").DebouncedFunc<T>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { useRef, useCallback } from 'react';
|
|
2
|
+
import { debounce } from 'lodash';
|
|
3
|
+
export default function useDebounce(cb, duration) {
|
|
4
|
+
var ref = useRef(cb);
|
|
5
|
+
ref.current = cb;
|
|
6
|
+
return useCallback(debounce(function () {
|
|
7
|
+
return ref.current.apply(ref, arguments);
|
|
8
|
+
}, duration), []);
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function useInterval(callback: () => void, delay: number | null): void;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useRef, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
var noop = function noop() {};
|
|
4
|
+
|
|
5
|
+
export default function useInterval(callback, delay) {
|
|
6
|
+
var savedCallback = useRef(callback);
|
|
7
|
+
useEffect(function () {
|
|
8
|
+
savedCallback.current = callback;
|
|
9
|
+
}, [callback]);
|
|
10
|
+
useEffect(function () {
|
|
11
|
+
if (delay !== null) {
|
|
12
|
+
var id = setInterval(function () {
|
|
13
|
+
savedCallback.current();
|
|
14
|
+
}, delay);
|
|
15
|
+
return function () {
|
|
16
|
+
return clearInterval(id);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return noop;
|
|
21
|
+
}, [delay]);
|
|
22
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
+
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
+
|
|
5
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
+
|
|
7
|
+
import { useRef, useCallback } from 'react';
|
|
8
|
+
import { throttle } from 'lodash';
|
|
9
|
+
export default function useThrottle(cb, duration, options) {
|
|
10
|
+
var ref = useRef(cb);
|
|
11
|
+
ref.current = cb;
|
|
12
|
+
return useCallback(throttle(function () {
|
|
13
|
+
return ref.current.apply(ref, arguments);
|
|
14
|
+
}, duration, _objectSpread({
|
|
15
|
+
trailing: false
|
|
16
|
+
}, options)), []);
|
|
17
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lemon-fe/hooks",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "鲁盛杰 <lusj@cnlemon.net>",
|
|
6
6
|
"homepage": "",
|
|
@@ -25,5 +25,5 @@
|
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@types/color-string": "^1.5.2"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "cd8c8e854c16f5605657b3b92fb2deecd1a116e8"
|
|
29
29
|
}
|