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

stifle

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stifle - npm Package Compare versions

Comparing version 1.0.2 to 1.0.4

12

index.js

@@ -27,4 +27,10 @@ module.exports = stifle;

wrapper.cancel = function () {
if (timer) clearTimeout(timer)
timer = undefined
// Clear the called flag, or it would fire twice when called again later
called = false;
// Turn off the timer, so it won't fire after the wait expires
if (timer) {
clearTimeout(timer);
timer = undefined;
}
}

@@ -39,3 +45,3 @@

called = false;
wrapper()
wrapper();
}

@@ -42,0 +48,0 @@ }

{
"name": "stifle",
"version": "1.0.2",
"version": "1.0.4",
"description": "A very simple way to throttle a function",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -23,3 +23,3 @@ stifle

The wrapped function comes with a `cancel` method to kill and pending future invocations -- useful for shutting it down when a page or component is being unloaded.
The wrapped function comes with a `cancel` method to kill any pending future invocations -- useful for shutting it down when a page or component is being unloaded.

@@ -26,0 +26,0 @@

@@ -39,2 +39,19 @@ var stifle = require('../index')

it('should not trigger an extra call after a `cancel`', function (done) {
var callCount = 0,
wrapper = stifle(function () { callCount++; }, 10);
wrapper();
wrapper(); // This call should get cancelled
wrapper.cancel();
assert.strictEqual(callCount, 1);
wrapper();
setTimeout(function () {
assert.strictEqual(callCount, 2);
done();
}, 50);
});
it('should trigger a second wrapper call as soon as possible', function (done) {

@@ -41,0 +58,0 @@ var callCount = 0;

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