Code Monkey home page Code Monkey logo

debounce-by-key's Introduction

debounce-by-key

debounce-by-key debounce-by-key

useful for employing a group of functions within a single debounce scope and/or employing a single function across a group of debounce scopes

Installation

npm install debounce-by-key --save

Usage

This module provides a single function that takes a single options arg (optional) and returns a Promise that resolves if the debounce state is non-blocking, and rejects if its blocking.

debounce([options])

  • options {Object}
  • return: Promise

[options]

  • key the string identifier of the debounce scope. Defaults to ''
  • duration the time in milliseconds of the blocking state. Defaults to 1000

Example

const debounce = require('debounce-by-key')

const sayHi = ()=>{console.log('hello world')}


/* no-args */
debounce().then(sayHi)
debounce().then(sayHi) //⛔ will not run


/* multiple functions, single scope */
debounce({key:'say hi'}).then(() => console.log('hola mundo') )
debounce({key:'say hi'}).then(() => console.log('hello world') ) //⛔ will not run
debounce({key:'say hi'}).then(() => console.log('bonjour monde') ) //⛔ will not run


/* single function, mutliple scopes */
debounce({key:'say hi 1'}).then(sayHi)
debounce({key:'say hi 2'}).then(sayHi) //✅ will run


/* duration arg */
const d = () => debounce({key:'say hi 3', duration:1000}).then(sayHi)

d()
setTimeout(d,500) //⛔ will not run
setTimeout(d,1500) //✅ will run

Tests

npm install
npm test

Dependencies

None

Dev Dependencies

  • tap: A Test-Anything-Protocol library

License

ISC

debounce-by-key's People

Contributors

json2d avatar

Stargazers

 avatar  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.