reshow-hooks
Advanced tools
Comparing version 0.17.55 to 0.17.56
"use strict"; | ||
var _interopRequireDefault = require("reshow-runtime/helpers/interopRequireDefault"); | ||
var _interopRequireWildcard = require("reshow-runtime/helpers/interopRequireWildcard"); | ||
exports.__esModule = true; | ||
exports["default"] = void 0; | ||
var _callFunc = require("call-func"); | ||
var _callFunc = _interopRequireWildcard(require("call-func")); | ||
var _react = require("react"); | ||
@@ -16,22 +17,53 @@ var _useSyncChange = _interopRequireDefault(require("./useSyncChange.js")); | ||
/** | ||
* @template T | ||
* @typedef {import("reshow-constant").useState<T>} useState | ||
*/ | ||
/** | ||
* @param {Function} func | ||
* @param {number=} defaultDelay | ||
* @param {number=} delay | ||
* @param {any=} scope | ||
* @returns {Function} | ||
*/ | ||
var useDebounce = function useDebounce(func, defaultDelay, scope) { | ||
var useDebounce = function useDebounce(func, delay, scope) { | ||
/** | ||
* @type {React.MutableRefObject<DebounceExecutor|undefined>} | ||
* @type {React.MutableRefObject<any>} | ||
*/ | ||
var _debounce = (0, _react.useRef)(); | ||
(0, _useSyncChange["default"])(func, function (nextFunc) { | ||
_debounce.current = (0, _callFunc.debounce)(nextFunc, defaultDelay); | ||
var lastProps = (0, _react.useRef)(); | ||
/** | ||
* @type {useState<DebounceExecutor>} | ||
*/ | ||
var _useState = (0, _react.useState)(function () { | ||
lastProps.current = { | ||
func: func, | ||
delay: delay, | ||
scope: scope | ||
}; | ||
return (0, _callFunc.debounce)(function () { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
(0, _callFunc["default"])(lastProps.current.func, [args], lastProps.current.scope); | ||
}, delay); | ||
}), | ||
_debounce = _useState[0]; | ||
(0, _useSyncChange["default"])(func, function (v) { | ||
lastProps.current.func = v; | ||
}, function () { | ||
return lastProps.current.func; | ||
}); | ||
(0, _useSyncChange["default"])(scope, function (v) { | ||
lastProps.current.scope = v; | ||
}, lastProps.current.scope); | ||
(0, _useSyncChange["default"])(delay, function (v) { | ||
lastProps.current.delay = v; | ||
}, lastProps.current.delay); | ||
return function () { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
return _debounce.current && _debounce.current({ | ||
scope: scope, | ||
args: args | ||
return _debounce({ | ||
args: args, | ||
delay: lastProps.current.delay | ||
}); | ||
@@ -38,0 +70,0 @@ }; |
{ | ||
"version": "0.17.55", | ||
"version": "0.17.56", | ||
"name": "reshow-hooks", | ||
@@ -4,0 +4,0 @@ "repository": { |
export default useDebounce; | ||
export type DebounceExecutor = import("call-func").DebounceExecutor; | ||
export type useState<T> = import("reshow-constant").useState<T>; | ||
/** | ||
@@ -7,7 +8,11 @@ * @typedef {import("call-func").DebounceExecutor} DebounceExecutor | ||
/** | ||
* @template T | ||
* @typedef {import("reshow-constant").useState<T>} useState | ||
*/ | ||
/** | ||
* @param {Function} func | ||
* @param {number=} defaultDelay | ||
* @param {number=} delay | ||
* @param {any=} scope | ||
* @returns {Function} | ||
*/ | ||
declare function useDebounce(func: Function, defaultDelay?: number | undefined, scope?: any | undefined): Function; | ||
declare function useDebounce(func: Function, delay?: number | undefined, scope?: any | undefined): Function; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
49647
1488