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

redux-async-reducer

v0.0.8

Published

Dynamically add reducers in Redux

Readme

Build Status PRs Welcome

redux-async-reducer

Dynamically add reducers in Redux

store.addReducer(name, reducer)

In applications that use code spliting, the PRPL pattern or the like would benefit from having the ability to add reducers dynamically.

redux-async-reducer adds a thin wrapper around createStore from Redux. This wrapper provides the same functionality as createStore but with additional helper methods such as addReducer. See below for examples and the full API.

How to use

npm i -S redux-async-reducer

Replace createStore from Redux with createStore from redux-async-reducer

+ import { createStore } from 'redux-async-reducer';
- import { createStore } from 'redux';

That's it.

You can now use createStore as you normally would*.

*Note

createStore by redux-aysnc-reducer expects a reducer object (the same object that you would pass to combineReducers). It must be provided a reducer with a key and not just a reducer function.

Examples

Example 1. (Create store)

import { createStore } from 'redux-async-reducer';

const rootReducerObj = {
    root: (state = {}, action) => state
} 

const store = creatStore(rootReducerObj)

Example 2. (Add reducer)

import { createStore } from 'redux-async-reducer';

const rootReducerObj = {
    root: (state = {}, action) => state
} 

const store = creatStore(rootReducerObj)

store.addReducer('foo', (state = {}, action) => state)

Example 3. (Get reducers)

import { createStore } from 'redux-async-reducer';

const rootReducerObj = {
    root: (state = {}, action) => state
} 

const store = creatStore(rootReducerObj)

store.addReducer('foo', (state = {}, action) => state)

store.getReducers()
/* 
    {
        root: (state = {}, action) => state
        foo: (state = {}, action) => state
    }
*/

API

// Same as redux createStore but epects reducer object
createStore(reducerObj, [preloadedState], [enhancer])

// Method. Expects 2 parameters. 1. String 2. Function(reducer)
addReducer(name, reducer)

// Method. no Parameters. Returns object of reducers
getReducers()

Motivation

Traditionally in Redux apps all reducers are known when bootstrapping the application. This is fine in small sized apps but when applying code splitting, lazy-loading or something along those lines, Redux out of the box does not make it intuitive to add reducers dynamically. Dan Abramov has provided rough a solution on SO to address this.

While his solution works, it is not a full answer as he states. redux-async-reducer applies a similar technique but in a more intuitive manner. The store itself provides a method addReducer and keeps track of what reducers have been added. Using redux-async-reducer is as simple calling:

store.addReducer(name, reducer)

TODO

  • Add Typescript
  • Add moar tests

License

MIT