Comparing version 0.1.0 to 0.1.1
@@ -8,3 +8,3 @@ "use strict"; | ||
}); | ||
exports.isRequired = exports.defaultCall = exports["default"] = void 0; | ||
exports.throttle = exports.debounce = exports.isRequired = exports.defaultCall = exports["default"] = void 0; | ||
@@ -35,5 +35,54 @@ var _typeof2 = _interopRequireDefault(require("reshow-runtime/helpers/typeof")); | ||
}; | ||
/** | ||
* only run lasttime. | ||
*/ | ||
exports.isRequired = isRequired; | ||
var debounce = function debounce(func) { | ||
var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 250; | ||
var timer; | ||
return function () { | ||
clearTimeout(timer); | ||
timer = setTimeout(func, delay); | ||
}; | ||
}; | ||
/** | ||
* reduce run times. | ||
*/ | ||
exports.debounce = debounce; | ||
var throttle = function throttle(func) { | ||
var threshhold = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 250; | ||
var needRunLast = arguments.length > 2 ? arguments[2] : undefined; | ||
var waiting = false; | ||
var lastCall = false; | ||
var run = function run() { | ||
lastCall = false; | ||
callFunc(func); | ||
}; | ||
return function () { | ||
lastCall = true; | ||
if (!waiting) { | ||
waiting = true; | ||
run(); | ||
setTimeout(function () { | ||
waiting = false; | ||
if (needRunLast && lastCall) { | ||
run(); | ||
} | ||
}, threshhold); | ||
} | ||
}; | ||
}; | ||
exports.throttle = throttle; | ||
var _default = callFunc; | ||
exports["default"] = _default; |
@@ -22,4 +22,49 @@ import _typeof from "reshow-runtime/es/helpers/typeof"; | ||
}; | ||
/** | ||
* only run lasttime. | ||
*/ | ||
var debounce = function debounce(func) { | ||
var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 250; | ||
var timer; | ||
return function () { | ||
clearTimeout(timer); | ||
timer = setTimeout(func, delay); | ||
}; | ||
}; | ||
/** | ||
* reduce run times. | ||
*/ | ||
var throttle = function throttle(func) { | ||
var threshhold = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 250; | ||
var needRunLast = arguments.length > 2 ? arguments[2] : undefined; | ||
var waiting = false; | ||
var lastCall = false; | ||
var run = function run() { | ||
lastCall = false; | ||
callFunc(func); | ||
}; | ||
return function () { | ||
lastCall = true; | ||
if (!waiting) { | ||
waiting = true; | ||
run(); | ||
setTimeout(function () { | ||
waiting = false; | ||
if (needRunLast && lastCall) { | ||
run(); | ||
} | ||
}, threshhold); | ||
} | ||
}; | ||
}; | ||
export default callFunc; | ||
export { defaultCall, isRequired }; | ||
export { defaultCall, isRequired, debounce, throttle }; |
{ | ||
"name": "call-func", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "call function", | ||
@@ -5,0 +5,0 @@ "repository": "react-atomic/react-atomic-organism", |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
14284
10
397
0