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

flush-js

v1.3.2

Published

Automatization processes for retrying unsuccessful (bad connection) requests

Downloads

3

Readme

NPM version Downloads

What is Flush.js

Flush.js is a system which allows you to automatically collect all failed requests and then repeat all of them by single method.

How it works

Here is animation of how this tool can be used. Red borders means error (request cancelled), green card - successful response from the server and black - waiting for response. You can clone this repository and check out the demo to understand process better.

Requirements

This tool uses jquery functions. So you need to include jquery before using this tool.

Installation

You can use this tool using npm or just by downloading script and linking to the project.

For the first way you need to follow next steps:

  • install the package using command npm install flush-js --save-dev
  • use it inside you project like this: var FlushJS = require('flush-js')

For the second way you need to do:

  • download dist/flush.min.js to your project
  • include it using something like <script type="text/javascript" src="../dist/flush.min.js"></script>

Usage

Here is very simple code of Flush.js usage.

$('.request-sender').click(function(){
    FlushJS.send({
        url: "http://httpbin.org/get",
        method: 'GET'
    });
});

var $flushBtn = $(".flush-button");
FlushJS.onChange = function(e){
    $flushBtn.text(e.queueLength);
}

$flushBtn.click(function(e){
    FlushJS.flush()
})
  • First 6 lines for setup click handlers. It's just a request send in jquery-ajax style. The only defference is that you must use FlushJS instead of $. So all failed requests will go to special queue.
  • Next block makes interface a little responsive. Button for flushing contains number of failed requests and these lines just update this value.
  • Last block of code just makes flush button work.

See demo. There you can find more complex and realistic usage.

Additional properties, methods and handlers

  • timeout - integer, milliseconds, 1000 by default. Change it if you want to work with slower or faster requests.

  • checkProblemIsConnection(xhr, status) - useful function. Use it in complete or error methods when you call FlushJS.send to understand will this request be lost or not.

  • queueLength() - method which returns length of the queue.

  • onChange(e) - change handler. Set it up (see demo) to make interface more responsive. event has multiple.


  • send(request) - main method to make a request. Argument structure the same as in jQuery.ajax method.

  • flush() - main method to repeat all failed requests.