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

v0.1.1

Published

Redux optimisation tool. Filter reducers and middleware with O(1) efficiency on inclusion and exclusion or through custom filter functions.

Downloads

17

Readme

Redux Optimal

Redux Optimal is a tool to assist in the optimisation of redux across reducers and middleware. The syntax is simple and designed for easy usage.

Installation

Requirements

  • react-redux
  • babel

$ npm install --save redux-optimal

About

Background:

Reducers are comprised of the following standard syntax:


import { SOME_ACTION_TYPE } from '../actions/some';

const someReducer = (state, action) {
  switch(action.type) {
    case SOME_ACTION_TYPE:
     return {
        ...state,
        value: action.value
     }
    default: return state
  }
}

export default someReducer;

Whereas middleware is usually comprised of the following code:


import { SOME_ACTION_TYPE } from '../actions/some';

const someMiddleware = store => next => (action) {
  if (action.type === SOME_ACTION_TYPE) {
    console.log(action.value)
  }
  return next(action);
}

export default reducer;

This implementation is fine and in most cases is optimal enough that it does not need any further adjustment. However, in large systems where multiple reducers are used, it can become a heavy burden to execute each reducer and middleware function upon each action request. This can become especially prevalent in environments such as react-native on lower-memory devices when triggering multiple requests simultaneously.

Why Redux Optimal

Redux Optimal provides a simple interception function that returns early based on the given criteria.

There are other solutions available, however Redux Optimal offers an o(1) efficiency for both middleware and reducers when determining whether to execute the respective functions when using the inclusion and exclusion wrapper methods, as well as a custom function for more complex use cases.

The o(1) efficiency is created by building an object upon initial execution of the wrapper function that can then be key value checked during the execution phase of the redux action request.

Usage

Both middleware and reducer functions have the same paradigm patterns:

  • Include
  • Exclude
  • Filter

Include

Include is an action type system (based on the action types being strings). Using the examples above, the wrapper functions can be included as below:

// Reducer Example

import { reducers } from 'redux-optimal';
import { SOME_ACTION_TYPE } from '../actions/some';

const only = [
  SOME_ACTION_TYPE,
];

const someReducer = ... // Same function as above

export default reducers.include(someReducer, only);
// Middleware Example

import { middleware } from 'redux-optimal';
import { SOME_ACTION_TYPE } from '../actions/some';

const only = [
  SOME_ACTION_TYPE,
];

const someMiddleware = ... // Same function as above

export default middleware.include(someReducer, only);

The resulting code will only trigger the middleware or reducer when the action type is equal to SOME_ACTION_TYPE. Multiple actions can be included in the array with the same level of efficiency (the only cost being the initial setup of the object.)

Exclude

Exclude is an action type system (based on the action types being strings). Using the examples above, the wrapper functions can be included as below:

// Reducer Example

import { reducers } from 'redux-optimal';
import { SOME_ACTION_TYPE } from '../actions/some';

const not = [
  SOME_ACTION_TYPE,
];

const otherReducer = ... // Different function from above

export default reducers.exclude(otherReducer, not);
// Middleware Example

import { middleware } from 'redux-optimal';
import { SOME_ACTION_TYPE } from '../actions/some';

const not = [
  SOME_ACTION_TYPE,
];

const otherMiddleware = ... // Different function from above

export default middleware.exclude(otherMiddleware, not);

The resulting code will trigger the middleware or reducer when the action type is an action that is not included in the supplied array. Again, multiple actions can be included in the array with the same level of efficiency (the only cost being the initial setup of the object.)

Filter

Sometimes there are more complex requirements for whether or not to return early from either reducers or middleware. Example use cases:

  • The action type starts with a certain prefix
  • The state object has a certain value
  • The action contains a certain value
  • A global event prevents the action
  • etc

In these cases, the Filter function allows an easy system to determine whether a redux reducer or middleware function should return early.

// Reducer Example

import { reducers } from 'redux-optimal';
import { SOME_ACTION_TYPE } from '../actions/some';

const fn = (action, state) => ... // do something with the action or the state to determine early return

const someReducer = ... // Same function as above

export default reducers.filter(someReducer, fn);
// Middleware Example

import { middleware } from 'redux-optimal';
import { SOME_ACTION_TYPE } from '../actions/some';

const fn = (action, store) => ... // do something with the action or the state to determine early return

const someMiddleware = ... // Same function as above

export default middleware.filter(someMiddleware, fn);

As can be seen in the above examples, the function signatures are slightly different for reducers and middleware, with the middleware passing the action and store, whilst the reducer passes the action and state.

License

MIT