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-brick

v0.1.0

Published

building redux app in a simplified strategy

Readme

redux-brick

redux-brick is a simplified building strategy of redux app. Redux system could be built from redux bricks.

redux brick

Every redux brick is an object with three specific attribute names.

  • name: brick name
  • defaultState: default state of the redux brick
  • mutation: a generator function wrapping redux action creators and reducers together

Here are two examples of redux brick.

// src/store/countApp.js
module.exports = {
  name: 'countApp',
  defaultState: {
    count: 0
  },
  mutations: {
    add: function *() {
      yield type => {
        return () => ({type});
      };
      yield (state, action) => {
        return Object.assign({}, state, {
          count: state.count + 1
        });
      };
    }
  }
};

// src/store/todoApp.js
module.exports = {
  name: 'todoApp',
  defaultState: {
    todos: []
  },
  mutations: {
    add: function *() {
      yield type => {
        return todo => ({
          todo, type
        });
      };
      yield (state, action) => {
        return Object.assign({}, state, {
          todos: [
            ...state.todos,
            action.todo
          ]
        });
      };
    }
  }
};

Here is the benefits from decomposing the whole root redux into small bricks.

  1. Redux brick helps to save the declaration of lots of constants to make sure the unique of action type. Instead, just take care of brick name.
  2. Considering the fact that almost every action has its counterpart in reducers, action creators and reducers should be in same file for a more efficient coding. Leave no more separated actions and reducers and save two directories and a lot of files.

build

build function from redux-brick helps to compose redux bricks. It takes redux bricks as arguments and returns an object containing actions and reducers. Then it will go back the traditional redux way to apply middle wares, create store and so on.

Here is an example using two bricks declared before.

// src/store/index.js
import {
  createStore,
  combineReducers,
} from 'redux';
import {build} from 'redux-brick';

import countApp from './countApp';
import todoApp from './todoApp';

// compose bricks
const {actionCreators, reducers} = build(
  countApp,
  todoApp
);

// for now, `reducers` is an object.
// Use `combineReducers` to convert it to a valid redux reducers.
const store = createStoreWithMiddleware(
  combineReducers(reducers)
);

// dispatch some actions
store.dispatch(actionCreators.countApp.add());
expect(store.getState().countApp.count).toBe(1);// true

// the mutation name scope are isolated in different bricks
const newTodo = {
  title: 'hello',
  done: false
};
store.dispatch(actionCreators.todoApp.add(newTodo));
expect(store.getState().countApp.count).toBe(1);// true
expect(store.getState().todoApp.todos.length).toBe(1);// true
expect(store.getState().todoApp.todos[0]).toEqual(newTodo);// true

After composing bricks, actions and reducers will be generated. redux-brick only provides a sugar wrapper and do not break into the structure of origin redux. actions and reducers are still combined by a unique action name, but maintained automatically instead of declared in a long list of constants.

A unique action name is composed by two parts.

  • a unique redux brick name
  • a mutation name

type is the reserved attribute name of a redux action where a unique action name recorded.

So, for example, mutation add in countApp will be countApp.add. Mutation add in todoApp will be todoApp.add. Every brick has its own scope and will not disturb with each other.