npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

debounce-add-throttle

v1.0.4

Published

debounce-add-throttle

Downloads

12

Readme

debounce(防抖)

防止抖动,单位时间内事件触发会被重置,只执行最后一次触发事件,避免事件被误伤触发多次。

  • 场景
    表单提交、调整浏览器窗口大小时,resize 次数过于频繁,造成计算过多,此时需要一次到位,就用到了防抖

Installation

$ npm i static-koa

Usage

throttle

    import { throttle } from 'debounce-add-throttle';
    button.addEventListener('click', throttle(function(event) {
              console.log(this, event);
        }, 1000, 1));

throttle

    import { debounce } from 'debounce-add-throttle';
    window.addEventListener('scroll', debounce(function(event){
         console.log(this, event);
     }, 200));

options

  • fn
    函数,处理实际业务逻辑
  • delay.
    延迟执行毫秒数.
    default:200
  • immediate.
    设置函数是否立即执行
    true 表立即执行,false 表非立即执行. 不传参数,默认false

throttle(节流)

控制流量,单位时间内事件只能触发一次,只执行一次函数

  • 场景.
    scroll事件,每隔一秒计算一次位置信息等. 浏览器播放事件,每个一秒计算一次进度信息. input 框实时搜索并发送请求展示下拉列表,没隔一秒发送一次请求 (也可做防抖)

options

  • fn.
    函数,处理实际业务逻辑
  • delay.
    延迟执行毫秒数.
    default:1000
  • type.
    两种实现方式. 1 表时间戳版,2 表定时器版. 不传参数,默认走定时器