ts-debounce-throttle
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

ts-debounce-throttle

Build Status Coverage Status MIT Licence npm version

Typescript Version of debounce and throttle

为了仅仅使用 lodash 中的 debouncethrottle 这两个函数的 TS 版本,在社区库库找了半天没有找到,于是只能自己动手将其迁移成 Typescript 版本;

这两个函数的功能完全对齐 lodash 中的 debouncethrottle 中的功能,也就是说其 API 和 lodash 中保持一致,可以直接参考官方文档的使用:

迁移的时候,使用的是 lodash v 4.17.5 版本源码,不过考虑到这两个函数已经很稳定,所以 lodash 的版本升级对这个两个函数的影响很有限;

Installation

Node.js / Browserify

npm install ts-debounce-throttle --save
const {debounce, throttle} = require('ts-debounce-throttle');
 
// Avoid costly calculations while the window size is in flux.
jQuery(window).on('resize', _.debounce(calculateLayout, 150));
 
// Avoid excessively updating the position while scrolling.
jQuery(window).on('scroll', _.throttle(updatePosition, 100));
 

Global object

Include the pre-built script.

<script src="./dist/index.umd.min.js"></script>
 
<script>
const {debounce, throttle} = window.debounceThrottle;
 
// Avoid costly calculations while the window size is in flux.
jQuery(window).on('resize', _.debounce(calculateLayout, 150));
// Avoid excessively updating the position while scrolling.
jQuery(window).on('scroll', _.throttle(updatePosition, 100));
 
</script> 

Build & test

npm run build
npm test

License

MIT.

Readme

Keywords

none

Package Sidebar

Install

npm i ts-debounce-throttle

Weekly Downloads

3

Version

1.0.0

License

none

Unpacked Size

77.3 kB

Total Files

24

Last publish

Collaborators

  • jscon