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

@dalisoft/as-batch

v0.1.8

Published

Convert many calls into batches

Downloads

20

Readme

asBatch

Greenkeeper badge

Convert many calls into batches

Mostly use this for solving 1+N (N+1) problem

Features

  • Fast
  • Automatic handling
  • No duplication
  • Almost zero-config
  • Flexible
  • On browsers works too
  • Types declaration for IDE/Editor

Import

// ES6
import asBatch from "@dalisoft/as-batch";

// or

// CommonJS
const asBatch = require("@dalisoft/as-batch");

// or

const asBatch = window.asBatch;

Example

const calling = new asBatch({
    onCallsTimeout: async calls => {
      await timeout(2000);

      return await Promise.all(calls);
    }
  });

// No await calling, because await blocks caching and this not works effectively
// Also available other ways, see tests and i'm happy your PR for examples
// Just i don't have time to create examples
  calling
    .call(
      async () => {
        return requestWithSomeLib('[endpoint]/posts);
      },
      responses => responses.find(response => response.src === '/posts').posts
    )
    .then(posts =>
      console.log('see posts', posts)
    );

For more info see tests.

Options

  • cache - store of cache, should be like ES6 Map constructor
  • callsCache - store of calls cache, should be like ES6 Map constructor
  • key - default key for instance, if no one will not specify in methods
  • transform - this options only for .register method as useful for query and/or something similar
  • maxAgeOfCache - max age of cached results and keys which are removed after expiring
  • onRegisterTimeout - this option only for .register method and callback when within specified delay no calls happen, this callback will be fired
  • onRegisterTimeoutDelay - delay ms for onRegisterTimeout
  • onCallsTimeout - this option only for .call method and callback when within specified delay no calls happen, this callback will be fired
  • onCallsTimeoutDelay - delay ms for onCallsTimeout

Methods

.register(key?: string | Function, value?: string | Function, resolve?: Function): Promise | CacheResult | Any

Registers anything and then call onRegisterTimeout if no again calling this method within specified delay

.call(key?: string | Function, value?: string | Function, resolve?: Function): Promise | CacheResult | Any

Returns the cached call within specified delay

.fetchRegistered(): Promise | Any

Fetchs registered caches from .register method

.delete(key: string)

Removes the callback from cache

.clear()

Clear cache instance to be empty

License

MIT