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

reducer-chain

v1.0.1

Published

Allows to chain redux reducers with given state and action, then keep last updated state.

Readme

reducer-chain npm package Travis Coveralls

reducer-chain helps you to chain redux reducers with given state and action, then keep last updated state.

Getting started

Install reducer-chain using npm:

npm install reducer-chain --save

Then using ES6

import { increment, decrement } from './my-reducers';
import reducerChain from 'reducer-chain';

export default reducerChain([
  increment,
  decrement,
]);

Using ES5

var myReducers = require('./my-reducers');
var reducerChain = require('reducer-chain');

module.exports = reducerChain([
  myReducers.increment,
  myReducers.decrement,
]);

Usage

You can rewrite this:

const reducer = (state, action) => {
  if (!state) state = initialState;
  switch (action.type) {
    case 'ADD':
    case 'INCREMENT':
      return incrementReducer(state, action);
    case 'SUBTRACT':
    case 'DECREMENT':
      return decrementReducer(state, action);
    case 'RESET':
      return merge(state, {counter: 0});
    default:
      return state;
  }
};

reducer({counter: 0}, {type: 'INCREMENT'}); //=> {counter: 1}

To this:

import reducerChain from 'reducer-chain';

const chain = reducerChain([
  incrementReducer,
  decrementReducer,
]);

const reducer = (state, action) => {
  if (!state) state = initialState;
  switch (action.type) {
    case 'RESET':
      return merge(state, {counter: 0});
    default:
      return chain(state, action);
  }
};

reducer({counter: 0}, {type: 'INCREMENT'}); //=> {counter: 1}

See also reducer-pipe in order to pipe previously saved/returned state to next reducer in list with given action.

Examples

Compare signature

initialize(initialState) => iterator(previousState, currentState) => nextState
  • initialState is corresponding to the state passed to the high order reducer.
  • previousState is corresponding to the previously returned state. Defaults to initialState.
  • currentState is corresponding to the state returned by the reducer at the current index in the list.
  • nextState is corresponding to the state you want to keep.
  • initialize will be called everytime once with the given state from the high order reducer. It must returns an iterator function for comparing previous and current state, and return the prefered one.
  • iterator will be called on each reducer result (passed as currentState). It must compare with previousState (defaults to initialState) and return the state you want to keep next.

Note: Please note that all reducers will be call before the iterator. The order of each call remain the same as given to chain.

Available compare functions

reducer-chain built in with 4 different compare functions available under reducerChain.compare:

| Name | Signature | Equals | | ---- | --------- | ------ | | withInitial (default) | (initialState) => (previousState, currentState) => nextState | R.equals(initialState, currentState) | | withInitialCustomEquals | (customEquals) => (initialState) => (previousState, currentState) => nextState | customEquals(initialState, currentState) | | withPrevious | (initialState) => (previousState, currentState) => nextState | R.equals(previousState, currentState) | | withPreviousCustomEquals | (customEquals) => (initialState) => (previousState, currentState) => nextState | customEquals(previousState, currentState) |

Compare usage

With immutable:

// ./immutableReducerChain.js
import Immutable from 'immutable';
import reducerChain from 'reducer-chain';

export default reducerChain(
  reducerChain.compare.withPreviousCustomEquals(Immutable.is)
);
// ./index.js
import Immutable from 'immutable';
import { reducer1, reducer2 } from './reducers';
import immutableReducerChain from './immutableReducerChain';

const reducers = immutableReducerChain([
  reducer1,
  reducer2,
]);

const initialState = Immutable.Map({counter: 0});

export default (state, action) => {
  return reducers(state ? state : initialState, action);
};

With custom compare:

import reducerChain from 'reducer-chain';
import {reducer1, reducer2} from './reducers';

const customCompare = initialState => (previousState, currentState) => (
  currentState !== null &&
  currentState !== initialState ?
  currentState : previousState
);

const reducers = reducerChain(customCompare, [
  reducer1,
  reducer2,
]);

const initialState = Object.freeze({counter: 0});

export default (state, action) => {
  return reducers(state ? state : initialState, action);
};

Links

  • renum is a small library to create enum using frozen objects in javascript from multiple sources.
  • reducer-pipe helps you to pipe given reducers with the previously saved/returned state and given action.
  • reducer-sandbox helps you to reuse your reducers in different place without conflict them.