Socket
Socket
Sign inDemoInstall

debounce-promise

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

debounce-promise - npm Package Compare versions

Comparing version 1.1.1 to 2.0.0

4

dist/index.js

@@ -28,5 +28,7 @@ /* global setTimeout, clearTimeout */

nextArgs = args;
var onTimeout = run.bind(this, nextArgs, resolve, reject);
if (!pending) {
if (leading) {
pending = fn.apply(this, nextArgs);
onTimeout = clear;
} else {

@@ -40,3 +42,3 @@ pending = new Promise(function (_resolve, _reject) {

clearTimeout(timer);
timer = setTimeout(run.bind(this, nextArgs, resolve, reject), getWait(wait));
timer = setTimeout(onTimeout, getWait(wait));
return pending;

@@ -43,0 +45,0 @@ };

@@ -10,5 +10,7 @@ /* global setTimeout, clearTimeout */

nextArgs = args
let onTimeout = run.bind(this, nextArgs, resolve, reject)
if (!pending) {
if (leading) {
pending = fn.apply(this, nextArgs)
onTimeout = clear
} else {

@@ -22,3 +24,3 @@ pending = new Promise((_resolve, _reject) => {

clearTimeout(timer)
timer = setTimeout(run.bind(this, nextArgs, resolve, reject), getWait(wait))
timer = setTimeout(onTimeout, getWait(wait))
return pending

@@ -25,0 +27,0 @@ }

{
"name": "debounce-promise",
"version": "1.1.1",
"version": "2.0.0",
"description": "Create a debounced version of a promise returning function",

@@ -5,0 +5,0 @@ "main": "dist/index",

@@ -31,2 +31,18 @@ /* global setTimeout */

test('does not call the given function again after the timeout when leading=true if executed only once', async t => {
let callCount = 0
const debounced = debounce(async () => callCount++, 100, {leading: true})
await debounced()
await sleep(200)
t.equal(callCount, 1)
})
test('calls the given function again after the timeout when leading=true if executed multiple times', async t => {
let callCount = 0
const debounced = debounce(async () => callCount++, 100, {leading: true})
await* [1, 2, 3, 4].map(debounced)
await sleep(200)
t.equal(callCount, 2)
})
test('waits until the wait time has passed', async t => {

@@ -33,0 +49,0 @@ let callCount = 0

Sorry, the diff of this file is not supported yet

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