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 🙏

© 2025 – Pkg Stats / Ryan Hefner

redux-utils

v1.3.15

Published

Utility functions for redux

Downloads

34

Readme

redux-utils

Utility functions for redux

Redux-utils makes it easy to combine redux and immutableJS as well as make api calls using FSA conventions.

It combines redux-immutable and redux-api-middleware. It also adds two simple custom functions for creating actions and api call actions.

Click here for an example recreating the redux async example with far less code.


Installation

npm install redux-utils


Usage

The two custom functions that come with redux-utils are createAction and createApiAction. They do what their names says.

Use createAction like this createAction(Type, payloadTypes)

let action = createAction('FOO', 'id')

This will make

let action = (value) => {
return {
    type: 'FOO',
    payload: {
        id: value
        }
    }
}

If you want more than just one parameter

    let action = createAction('FOO', 'user', 'pwd')

This will make

let action = (user, pwd) => {
    return {
        type: 'FOO',
        payload: {
            userName: user,
            password: pwd
        }
    }
}

In order to get the api calls to actually work, you need to apply this middleware.

Example:

import { apiMiddleware } from 'redux-utils'
const createStoreWithMiddleware = applyMiddleware(
  thunkMiddleware,
  loggerMiddleware,
  apiMiddleware
)(createStore);

Now, createApiAction(name, endpoint, method, body, rest(not Implemented yet))

let createFetchSubmissionsAction = createApiAction('POSTS','api/posts', 'GET')

Well that's terse. It creates an api call to api/posts with the GET method and it creates 3 different actions that you can apply reducers to, 'POSTS_REQUEST', 'POSTS_SUCCESS' and'POSTS_FAILURE'. The actions are made from the name given then _REQUEST, _SUCCESS and _FAILURE added to the end.

Now lets have a slightly more complex api call

let createLoginAction = createApiAction('LOGIN', 'api/login', 'POST',
function(user, password) {
    return JSON.stringify({
    userName: user,
    password: password
    })
})

This creates LOGIN_REQUEST, LOGIN_SUCCESS and LOGIN_FAILURE which you can use with reducers. In order to call createLoginAction, you pass in a username and a password which are sent in the body of the request as a JSON object. Simple.

Combine reducers is a function from redux-immutable with minor changes to make it FSA standard.

The example below starts a store with the CONSTRUCT reducers. The import of reducers is different than normal so in order to use this, you need to check out the documentation of redux-immutable.

let reducer = combineReducers(reducers)
let state = Immutable.Map({})
state = reducer(state, {type: `CONSTRUCT`})
const Store = createStoreWithMiddleware(reducer, state)

All functions and middleware is imported with {} around it, there is no default export.


There is a currently a feature in the middleware where if you have an Immutable store and have a session object with token inside, it will use the token as part of the api call and place it in the header of the request. This will be worked on more.