Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

call-func

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

call-func - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

build/cjs/src/__tests__/debounceAndThrottleTest.js

51

build/cjs/src/index.js

@@ -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 };

2

package.json
{
"name": "call-func",
"version": "0.1.0",
"version": "0.1.1",
"description": "call function",

@@ -5,0 +5,0 @@ "repository": "react-atomic/react-atomic-organism",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc