npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

d-bounce

v0.0.5

Published

Javascript debounce tool

Downloads

8

Readme

d-bounce

Simple javascript debounce tool

Getting started

$ npm install d-bounce
// import d-bounce
const dBounce = require('d-bounce');

// callback function to be invoked after delay
function sayWord(word) {
    console.log(word);
}

// list of arguments to be passed to the callback function on invocation
const arguments = ['bounced'];

// this will console.log the word 'bounced' after 3 seconds
dBounce(sayWord, 'say-word-debounce', 3000, arguments);

/*
 * if dBounce is called again within 3 seconds 
 * with the same identifier string 'say-word-debounce' 
 * the clock will reset and another 3 seconds will be 
 * waited before the callback is invoked. 
 */

API

d-bounce accepts 4 arguments although only one is necessary.

dBounce(callback [, identifier [, delay [, arguments]]])

callback (Function or null or undefined) required

The function that you wish to be invoked after the delay provided dBounce is not called again with the same identifier.

Passing either null or undefined will cancel the debounce for the given identifier.

function exampleCallback() {
    console.log('I am an example');
}
dBounce(exampleCallback, 'example-debounce', 3000, arguments);

dBounce(null, 'example-debounce');
// debounce will be cancelled before it invokes the callback

identifier (String) optional default: 'default'

A string identifier used to associate each attempted invocation with other attempted invocations. calls to d-bounce are linked to each other by the identifier. This means that you could pass a different callback function every time you call dBounce, using the same identifier, and dBounce will reset the clock on the delay.

// create a debpunced function with the identifier 'example-debounce-1'
dBounce(() => console.log('callback 1'), 'example-debounce-1');

// create a second debpunced function with the identifier 'example-debounce-2'
dBounce(() => console.log('callback 2'), 'example-debounce-2');

// both callbacks will be invoked as they have different identifiers.
// one has no effect on the other

The last callback function that dBounce is called with when the delay is satisfied will be the function that gets invoked.

dBounce(() => console.log('callback 1'), 'example-debounce');
dBounce(() => console.log('callback 2'), 'example-debounce');
// the the second callback that logs out 'callback 2' will be the only one that is invoked.

delay (Number) optional - default: 300

default: 300

The amount of time waited by dBounce before invoking the callback, provided debounce is not called again with the same identifier.

arguments (Array) optional - default: []

An array of arguments to be passed to the callback upon invocation.

function callback(one, two, three) {
    console.log(one);
    console.log(two);
    console.log(three);
}

const arguments = ['first arg', 'second arg', 'third arg'];

dBounce(callback, 'example-debounce', 1000, arguments);

/*
 *  After 1 second the callback will be invoked and 
 *  the console will log out the following
 *
 *  first arg
 *  second arg
 *  third arg
 */

Testing

$ npm test