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

pipeline-middleware

v0.1.2

Published

Simple action in / action out pipeline capable of handling Redux actions, functions, generators and promises.

Downloads

5

Readme

Pipeline Middleware

Build Status Coverage Status

Pipeline Middleware represents a simple and customizable way to dispatch Redux actions based on other actions being dispatched. The Pipeline Middleware is capable of handling simple actions as the output as well as action returning functions, action yielding generators and actions resulting from promise fullfilment.

The Pipeline Middleware provide a simple way of combining the pipelines based on an actionType keyed object that will pair actions with execution pipelines that result in different actions.

The original action can be allowed to reach the reducer or not through a simple halt flag that breaks the pipeline execution thread when an action containing it has been fired.

Installation

To install Pipeline Middleware simply add it to your dependency modules:

NPN: npm install pipeline-middleware
Yarn: yarn add pipeline-middleware

Then simply hook it into the Redux middlewares declaration:

const middlewares = applyMiddleware(pipelineMiddleware(pipelines()));
const store = createStore(reducers, {}, middlewares);

Pipeline Middleware takes one argument when invoked, and that is an object of actionType, function (pipeline) pairs. Each function will be executed when that specific action whose type is the pipeline key will be fired.

Support

Pipelines will be executed expecting an action representation as a result. If one is not reached the outcome will be recursively executed (if possible) until such an action representation is reached. As such the pipelines can return an action representation, a function, a generator, a promise or any chain of the previous as long as at the end of all the executions an action representation is returned. If that point is not reached the pipeline will simply let the normal flow continue.

Action Example

const pipelines = () => ({
    [action1.type]: (action1, store) => chAction1(),
    [action2.type]: (action2, store) => ({ ...chAction2(), halt: true })
});

While the first example will chain chAction1 and action1 and send them both to the reducers, the second example will only send chAction2 to the reducers, the halt flag being present and telling the pipeline that execution has to be stopped after this action is sent to the store.

Function example

const pipelines = () => ({
    [action1.type]: (action1, store) => () => chAction1(),
    [action2.type]: (action2, store) => () => ({ ...chAction2(), halt: true })
});

As in the previous exemple the pipeline will fire the following actions:
Eg1: chAction1 > action1
Eg2: chAction2

Generator example

const pipelines = () => ({
    [action1.type]: () => function* generator() {
        yield chAction1();
        yield () => chAction2();
        yield () => () => () => chAction3();
        yield chAction4();
    },
    [action2.type]: () => function* generator() {
        yield chAction5();
        yield () => chAction6();
        yield { ...chAction7(), halt: true };
        yield chAction8();
    }
});

The pipeline will fire the following actions:
Eg1: chAction1 > chAction2 > chAction3 > chAction4 > action1
Eg2: chAction5 > chAction6 > chAction7

Note that a halt flag will stop not only the original action but also the following chained actions

Promise Example

const pipelines = () => ({
    [action1.type]: () => new Promise(resolve => {
      setTimeout(resolve, 100, () => chAction1());
    });,
    [action2.type]: () => new Promise(resolve => {
      setTimeout(resolve, 300, () => () => () => () => () => ({
        ...chAction2(),
        halt: true
      }));
    });
});

The pipeline will fire the following actions:
Eg1: chAction1 > action1
Eg2: chAction2