@nielse63/throttle

Creates a throttled function that's evoked only as frequently as you want it to

Stats

stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
12Sep 25, 2018Jul 28, 2018Minified + gzip package size for @nielse63/throttle in KB

Readme

@nielse63/throttle

Creates a throttled function that's evoked only as frequently as you want it to

Installation

Install with Yarn or npm

yarn add --dev @nielse63/throttle
npm install --save-dev @nielse63/throttle

Usage

const throttle = require('@nielse63/throttle');

function callback() {
  // some expensive function...
}

window.addEventListener('scroll', throttle(callback, 150), false);
// `callback` is only executed once every 150ms

API

debounce(callback[, delay, immediate])

Name Type Description Default
callback Function Callback to execute after delay ms undefined
wait Number Delay, in ms, before executing callback 250

Return Value

Function - The wrapper to execute the callback

Contributing

Development Setup

This project uses a monorepo setup that requires using Yarn because it relies on Yarn workspaces. Clone the repo and install the dependencies:

git clone https://github.com/nielse63/nielse63.git
cd nielse63
yarn

License

MIT © Erik Nielsen

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.