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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@super-formal/chain-reaction

v0.1.0

Published

A class that aggregates a group of callbacks that can be invoked with a single function call.

Readme

@super-formal/chain-reaction

A class that aggregates a group of callbacks that can be invoked with a single function call.

Index

Installation

Using npm:

npm i -g npm
npm i --save @super-formal/chain-reaction

Using yarn:

yarn add @super-formal/chain-reaction

Basic Usage

After installing the package you can use it as follows:

import ChainReaction from '@super-formal/chain-reaction';

function actionA(input) {
  console.log(`performing action A with input: "${input}"`);
}

function actionB(input) {
  console.log(`performing action B with input: "${input}"`);
}

let reaction = ChainReaction.fromList([actionA, actionB]);
let reactionCb = reaction.toFunction();
reactionCb("some input");

// prints:
// >> performing action A with input: "some input"
// >> performing action B with input: "some input"

The ChainReaction class

ChainReaction.fromList()

  • @param callbacks - {Array<Function>} - A list of functions to include in the chain reaction.

  • @returns {ChainReaction} - A ChainReaction that includes all the callbacks provided in the input.

ChainReaction.resolve()

  • @param input - {Function|Array<Function>|ChainReaction} - Either a function, a list of functions, or an instance of a ChainReaction.

  • @returns {ChainReaction} - Evaluates the input based on type and converts it into a ChainReaction. If the input is a Function then the returned object will include that function as a callback. If the input is an array of functions then those functions are included into the ChainReaction's list of functions. If the input is a ChainReaction then a copy of the input is returned.

callbacks

  • @returns {Array<Function>} a copy of the internal callbacks.

pushCallback(callback)

  • @param callback - {Function} - The function to add to the chain reaction.

Adds the provided function to the end of the list of callbacks within the chain reaction.

appendCallbacks(callbacks)

  • @param callbacks - {Array<Function>} - The functions to add to the chain reaction.

Adds the provided list of functions to the end of the list of callbacks within the chain reaction.

copy()

  • @returns {ChainReaction} - a copy of the ChainReaction with the same list of callbacks.

join(otherChainRx)

  • @param otherChainRx - {ChainReaction} - The other chain reaction to join with this chain reaction.

  • @returns {ChainReaction} - A reference to the same instance of the ChainReaction being called.

Appends the callbacks from otherChainRx to the end of the list of callbacks in this chain reaction.

toFunction()

  • @returns Function - a function that invokes all the callbacks within the chain reaction.

The argument provided to the returned function will be passed on to each of the internal callbacks. If a callback returns nothing when invoked (undefined or null) then the next callback will get invoked and so on. The list of callbacks will be invoked in the order in which they are listed in the chain reaction. If a callback returns an Object with a continue property with a value false then none of the following callbacks will get called. To demonstrate:

function a() {
  console.log(`invoking a...`);
}

function b() {
  console.log(`invoking b...`);
  return {continue: false};
}

function c() {
  console.log(`invoking c...`);
}

let reaction = ChainReaction.fromList([a, b, c]);
reaction.toFunction()();

// prints:
// >> invoking a...
// >> invoking b...

Helper joinReactions(inputA, inputB)

  • @param inputA - {Function | Array<Function> | ChainReaction}

  • @param inputB - {Function | Array<Function> | ChainReaction}

  • @returns ChainReaction - A reaction that includes both the callbacks from inputA and inputB.

This method resolves each input into a ChainREaction, if they aren't a ChainReaction already. Modifying either of inputA or inputB doesn't affect the returned ChainReaction.

Helper result(_continue)

  • @param _continue - {Boolean} - whether the callback invokations should continue after this point.

  • @returns {Object} - this object can be returned by any of the internal callbacks in ChainReaction and can be used to inform the callbacks to stop invoking.