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-action-generate

v0.1.26

Published

Generates reducers and actions from one reducers list

Readme

redux-action-generate

Generates reducers and actions from one reducers list.

Install:

yarn add redux-action-generate

import reduxActionGenerate from 'redux-action-generate';

'reduxActionGenerate' function signature:

_

Common object argument that is passed to 'reduxActionGenerate' function:
{
// *required 
// array of reducers;
 reducers = [
   {
      // *required
      // name of reducer
      name: 'users',
      // *required
      // name for action's dispatch type 
      basicType: constants.COMMON,
      // initial state for this specific reducer
      initialState: authInitialState,
      // specific config for redux-persist lib
      config: usersPersistConfig,
      // reducer's handlers for some specific action's type 
      handlers: {
         [constants.LOGIN + '_CUSTOM']: (state, action) => ({ ...state }),
         [constants.LOGIN + '_CUSTOM2']: (state, action) => {
           return { ...state };
         },
         [constants.LOGIN + '_CUSTOM3']: (state, action) => {
           return { ...state };
         },
       },
     },
    },
    {
    ...
    }
 ],
 
 // any redux middlewares;
 middlewares = [],
 
 // initial state for 'configureStore' redux api funcrtion;
 initialState = {},
 
 // config object for redux-persist library
 persistConfig = defaultPersistConfig,
 
 // function which inserts custom headers to 
 // api calls made with A.dispatch[<reducer name>][<Get/Post/Put/Patch/Delete>] 
 // returns an object
 // i.e. A.dispatchCommonGet({url: 'http...'})
 apiCallCustomHeaders,
 
 // function which inserts custom 'catch' behaviour on each http request
 commonCatchFunc,
}

Example:

_

// receives error as an argument
function commonCatchFunc(err) {
 if (err.response.status) === 401) {
   logout();
 }
}

// receives store where you can get 'store.getState().token' to insert it in each request
// must return an object
function apiCallCustomHeaders(store) {
 let headers = {
   'Content-Type': 'application/json',
   'Authorization': store.getState().token
 };
 return headers;
}

// common config for redux-persist - to save info locally - is not required
const persistConfig = {
 key: 'root',
 whitelist: ['token'],
 storage: storage,
 stateReconciler: autoMergeLevel2,
};

export const { 
   store, 
   persistor, 
   A 
} = reduxActionGenerate({
 reducers,
 apiCallCustomHeaders,
 commonCatchFunc,
 persistConfig,
});

Features

  • all reducers are generated from an array of objects - each for specific reducer - no need for separate files;
  • for each reducer there is a bunch of default actions generated:
  • default actions image naming convention - A. + 'dispatch' + name of reducer (in this case name was 'common') /+ possible actions
  • no mess with files for each reducer + file for each action creator
  • each bunch of actions for each reducer has:
  1. common dispatcher - A.dispatchCommon({ 'config[0].locale': 'en'}) - can set values on any depth (thanks to lodash set with no mutation under the hood)
  2. A.dispatchCommonClear() - set initial state on reducer
  3. A.dispatchCommonError({error: error}) - set error on reducer (but can be done with the first method)
  4. Bunch of methods for ajax request (with axios)
A.dispatchCommonPost({
    url: 'https://...',
    data: data,
    
    // may be omitted - if 'format' function is not provided - all response will 
    // be injected in reducer as is
    format: (response) => { 
        // do what uyou need with the response
        // if don't want to inject anything in reducer - return empty object
    }
})