just-debounce

WebJar for just-debounce

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

just-debounce
Last Version

Last Version

1.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

just-debounce
WebJar for just-debounce
Project URL

Project URL

https://www.webjars.org
Source Code Management

Source Code Management

https://github.com/hayes/just-debounce

Download just-debounce

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/just-debounce/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>just-debounce</artifactId>
    <version>1.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/just-debounce/
implementation 'org.webjars.npm:just-debounce:1.1.0'
// https://jarcasting.com/artifacts/org.webjars.npm/just-debounce/
implementation ("org.webjars.npm:just-debounce:1.1.0")
'org.webjars.npm:just-debounce:jar:1.1.0'
<dependency org="org.webjars.npm" name="just-debounce" rev="1.1.0">
  <artifact name="just-debounce" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='just-debounce', version='1.1.0')
)
libraryDependencies += "org.webjars.npm" % "just-debounce" % "1.1.0"
[org.webjars.npm/just-debounce "1.1.0"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

just-debounce

just a basic debounce function

changes

  • 1.1.0: added typescript definitions

Why?

I searched npm and the first 3 pages of results for "debounce" did not have a small correctly implemented version of debounce

Usage

arguments

  • fn: the function to debounce
  • delay: debounce delay in ms
  • atStart: if true, the function will be called at the beginning of the delay rather than the end
  • guarantee: additional calls to debounced function will not reset they delay. This guarantees that if the function is called frequently, it will fire once every delay rather than waiting for a break in calls.
var db = require('just-debounce');

var debounced = db(function (v) {
  console.log(v);
}, 100);

debounced('hi');
debounced('hi');
// logs 'hi' once after 100ms
var db = require('just-debounce');

var debounced = db(
  function (v) {
    console.log(v);
  },
  100,
  true
);

debounced('hi');
debounced('hi');
// logs 'hi' once right away, but not a second time. calling after 100ms will log again
var db = require('just-debounce');

var debounced = db(
  function (v) {
    console.log(v);
  },
  100,
  false,
  true
);

debounced('hi');
setTimeout(function () {
  debounced('hi2');
}, 80);

// logs 'hi2' once 100ms after the first call to debounced

license

MIT

Versions

Version
1.1.0
1.0.0