GithubHelp home page GithubHelp logo

lixquid / js-dualbounce Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 68 KB

102.23.02 Debounce stuttering changes into a single change.

Home Page: https://www.npmjs.com/package/dualbounce

License: MIT License

TypeScript 100.00%
typescript nodejs jl 102-23-02

js-dualbounce's Introduction

dualbounce

Debounce stuttering changes into a single change.

Installation

npm install dualbounce

or

yarn add dualbounce

Example

import dualbounce from "dualbounce";

const fn = dualbounce(
    (newValue, oldValue) => console.log("From", oldValue, "to", newValue),
    1000
);

for (var i = 0; i < 10; i++) {
    fn(i + 1, i);
}

// After 1 second: "From 0 to 10"

Returning values is supported too:

const fn = dualbounce(
    (newValue, oldValue) => `From ${oldValue} to ${newValue}`,
    1000
);

const promise = fn("Erica", "Monica");
fn("Rita", "Erica");
fn("Tina", "Rita")

console.log(await promise);
// After 1 second: "From Monica to Tina"

All invocations of the dualbounced function within the wait period will return the same promise.

API

debounce(func, wait)

  • func: (newValue, oldValue) => returnValue

    The function that will execute once the wait time is up. It will always be executed with the last value of newValue in the wait period, and the first value of oldValue in the wait period. returnValue can be a Promise!

  • wait: number

    The number of milliseconds to wait.

  • Returns: (newValue, oldValue) => Promise<typeof returnValue>

    A dualbounced func. The Promise will resolve wait milliseconds after the last invocation.

License

MIT

js-dualbounce's People

Contributors

lixquid avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.