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

tiny-polling

v1.1.0

Published

A very tiny (~200B) solution for polling that is offline aware

Downloads

15

Readme

Tiny Polling

Coverage Status

🎯A very tiny (~200B) solution for polling that is offline aware

Features

  • It's tiny, of course (~200B)
  • Polls any function you pass to it at the specific interval you pass to it
  • Online/Offline aware so it stops polling when offline and starts back when online
  • Written in TypeScript so you get good autocompletion

Installation

npm i tiny-polling or yarn add tiny-polling

Example

Tiny Polling is a function that takes two parameters and returns two methods - that's it. Here it is:

import { Polling } from 'tiny-polling';
import updateState from '../src/update-state'; // This could be any type of state updater like Redux, etc.

function updatePosts() {
  const posts = async () => await axios.get('/posts');
  updateState(posts);
}

// The first param is the function to poll
// The second param is the interval in seconds at which it will poll
const poll = Polling(updatePosts, 30);
poll.start(); // Starts the polling

function onExit() {
  poll.stop(); // Stop the polling
}

// Or, maybe you need to pass a callback to Polling because you have a function that takes arguments
function doSomething(params) {
  // Does something with the params
}

// Notice the second parameter is missing? The default interval is 10 seconds
const anotherPoll = Polling(() => {
  const params = { foo: false, bar: true };
  doSomething(params);
});

NOTE: The callback will not be called as soon as start() is invoked. It will start after the initial interval has passed, so you may need to fire your method the first time.

Params

| Name | Type | Required | Default | Description | |---------------------|------------|----------|---------|---------------------------------------------------------------------------| | callback | function | true | | This is the callback or function that is called at the specific interval. | | intervalInSeconds | number | false | 10 | This is the interval at which the callback will be called. |

Contributing

If you find a bug, submit an issue with enough information to reproduce the bug. If you have a fix, please do not hesitate to submit a PR. If you feel that the API needs to be modified, open an issue so that we can discuss it first.

Running the dev environment

  1. Clone the repo - git clone https://github.com/dericgw/tiny-polling.git && cd tiny-polling
  2. Install the dependencies - yarn
  3. Run the dev server - yarn start (Use tests for verification)

Testing

This package is only one JS file and it is tested pretty good. Make sure that none of the tests are breaking if changes are made. Also, if you add new functionality and it warrants testing, please add tests. If you need help with this, I will gladly help.

Issues

If you find an issue, head over to the Issues section and let me know about it. If you want to be super cool, you can submit a PR that fixes the issue.

License (MIT)

Check it out here.