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

connect-debounce

v0.2.1

Published

Distributed debounced function execution ala underscore on per session basis as connect middleware.

Downloads

13

Readme

Distributed debounced function execution ala underscore on per session basis as connect middleware.

Why

If user interaction is followed by a request to the server and has heavy task to do, you might want to prevent the user from triggering this multiple times. It is not always possible to solve this on the client, because:

  1. User can reload the page directly after the action, so request never happens.
  2. User can switch to another page which has to display something depending on previous changes.
  3. Blocking the screen is not a good option from the UI side of view, also it will not prevent user from page reload.

How

Module will save the date of the last attempt to execute the function into the session store of connect. On every attempt to execute it again, it will check the date and prevent execution more often than the wait time defined for the function.

Setup

Debounce returns a middlware function. You can pass new wait option, default is 1000ms.

Example:

var debounce = require('connect-debounce');
var app = connect();

app
    .use(debounce({wait: 3000}))
    .use(connect.logger('dev'))
    .use(connect.static('public'))
    .use(function(req, res){
        res.end('hello world\n');
    })
    .listen(3000);

req.debounce(fn:Function, [wait:Number], [immediate:Boolean])

  • fn is a function which execution will be debounced. It can get an error object passed as first argument. Don't ignore it! Better to use a function name to avoid potential conflicts with some other debounced function which has the same implementation.
  • wait time in ms to wait, default is the value described in setup.
  • immediate exec function immediately and debounce it later

Example:

app.get('/', function(req, res, next) {
    req.debounce(function(err) {
        if (err) {

            // Request is already responded, log the error.
            return log(err);
        }

        doSomething();
    }, 3000);

    res.send('my response');
});

Install

npm i connect-debounce

Running tests

npm test