2.0.0 • Published 4 months ago

debounce v2.0.0

Weekly downloads
1,662,113
License
MIT
Repository
github
Last release
4 months ago

debounce

Delay function calls until a set time elapses after the last invocation

Install

npm install debounce

Usage

import debounce from 'debounce';

function resize() {
	console.log('height', window.innerHeight);
	console.log('width', window.innerWidth);
}

window.onresize = debounce(resize, 200);

(You can also use const debounce = require('debounce'))

To later clear the timer and cancel currently scheduled executions:

window.onresize.clear();

To execute any pending invocations and reset the timer:

window.onresize.flush();

API

debounce(fn, wait, options?)

Creates a debounced function that delays execution until wait milliseconds have passed since its last invocation.

Set the immediate option to true to invoke the function immediately at the start of the wait interval, preventing issues such as double-clicks on a button.

The returned function has a .clear() method to cancel scheduled executions, and a .flush() method for immediate execution and resetting the timer for future calls.

Related

webpack-bundle-analyzer@sheerid/jslib-nightly@fairfx/fujibit-bin@graphql-codegen/cli@knapsack/appblock-kitty-ui@react-material-table/material-table@coprocure/search-widget@netanelhaber/react-use-infinite-scrollzagenzagen-productionuse-resizing-testzawee-material-tablevia-websitesreact-adaptive-propsvue-snappy-selectics-data-tablereproduction-is@craftjs/core-2slate-react-es6material-table-2material-table-hotfix-for-initial-page-remote-datamaterial-table-initial-page-hotfixcolony-fixedtririga-react-components@bumble/reloadermaterial-table-glmaterial-table-gl2material-table-bendevview-page-tablegardenplacevue-dzkf-uivue-h3c-uivue-openplat-mastervtex3bunadmin-material-tableachiga-notificationsreact-native-web-dcapplauncherfavmenuckuessner2applauncherfavmenuckuessner3react-custom-card-testing@lucpolak/material-tableeasy-infinite-scrolldokztestmaterial-table-ex@idkman/material-table-fixedrobinbullock-material-table-coreinsync-stageplayer@moderno/workbenchvue-ant-patterns-cicdsalesforce-query-editor-app@robmayer/slate-react@codingkiwi/spook-clientngx-view-indexsalesforce-query-editor-test@reldb/cli@streetscape.gl_hik/monochromesvrx-plugin-tailwindcssdeltachat-desktopmaterial-table-fixed-bundle-sizehexidave-material-ui-core@cloudcue/plugin-client-core@cloudcue/plugin-cloud-client@cloudcue/plugin-cue@cloudcue/plugin-cuelight@cloudcue/plugin-midi@cloudcue/plugin-production@cloudcue/plugin-rfm69merge-chapters-md@pagezilla/core@clickadilla/datatable-formatter@clickadilla/vast-service-order-form@clickadilla/vuetify-datatable@heights/heights-uibubble-bgmd-notesray-material-table-coresilver-companion@aapokiiso/fillarivahti-web-frontend@monotaskio/client-commonhahnbee-testrel-cmdhahnbee-test-clientk3-nw-autoupdaterreact-responsive-theme-hoc@streetscape.gl_hk1/monochrome@emagis/conversations-editorreact-native-slider-kf@samsquatch/alteryx-components@samsquatch/service-titan-components@prodam/prodam-types@farnabaz/chzt-project-base@jetstreamlabs/tail-tables@noahbaron91/core@sparted/react-native-webnode-home-assistant-llatel-cronopea-bootstraapunless-material-ui
2.0.0

4 months ago

1.2.1

3 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.2

7 years ago

1.0.0

10 years ago

0.0.3

11 years ago

0.0.2

11 years ago