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

v1.0.10

Published

Alternative reducer combinator for the redux library. Grouping action types and context names.

Readme

redux-combinator

Alternative reducer combinator for the redux library. Grouping action types and context names.

Install

Install with npm:

$ npm install --save redux-combinator

Usage

Task list example.

This is an example to understand how the library works. Please... In real life, do not do this!

import { createStore } from 'redux';
import { rootReducer, addReducer } from 'redux-combinator';

// Create a Redux store holding the state of your app.
// Warning: Set default state!
let store = createStore(rootReducer, {});

// This reducer creates an array of tasks. The `taskList` context.
function reducerFirst(state, action) {
	
	switch (action.type) {
		case 'FILL_TASK':
			return action.payload.slice();
			
		case 'ADD_TASK':
			const copyForAdd = state.slice();
			copyForAdd.push(action.payload);
			return copyForAdd;
			
		case 'REMOVE_TASK':
			const index = state.indexOf(action.payload);
			if(index > -1) {
				const copyForRemove = state.slice();
				copyForRemove.splice(index, 1);
				return copyForRemove;
			}
			else {
				break;
			}
    }
    return state
}

// This reducer creates and supports tasks statistics. The `taskStat` context.
function reducerSecond(state, action, globalState) {
	
	// This action uses only this reducer.
	if(action.type === "CLEAR_TASK_STAT") {
		return {
			fill: 0, add: 0, remove: 0, total: 0
		}
	}
	
	// Update values for all action.
	let {
		fill, 
		add, 
		remove, 
		total: prevTotal
	} = state, 
	total = globalState.taskList.length;
	
	switch (action.type) {
		case 'FILL_TASK':
			fill++;
			break;
			
		case 'ADD_TASK':
			add ++;
			break;
			
		case 'REMOVE_TASK':
			if(prevTotal !== total) {
				remove ++
			}
			break;
	}
	
	return {fill, add, remove, total}
}

// Set reducer properties
reducerSecond.reducerActionTypes = ["ADD_TASK", "REMOVE_TASK", "FILL_TASK", "CLEAR_TASK_STAT"];
reducerSecond.reducerContext = "taskStat";
reducerSecond.reducerDefaultValue = {fill: 0, add: 0, remove: 0, total: 0};

// Add reducers
// The wrapper for the `rootReducer.add` method
addReducer(reducerFirst, ["ADD_TASK", "REMOVE_TASK", "FILL_TASK"], "taskList", []); // alternative syntax
addReducer(reducerSecond);

// Dispatch actions
store.dispatch({ type: "FILL_TASK", payload: ["One", "Two", "More..."] });
store.dispatch({ type: "ADD_TASK", payload: "This is task" });
store.dispatch({ type: "REMOVE_TASK", payload: "Two" });

console.log(store.getState());

Functions

Create new reducer combinator.

Use this function when there are several store objects in your project (createStore (reducer)). If you used only one root store (as Redux recommends), you should use the rootReducer, addReducer, setDefault, and getDefault functions.

Arguments

  1. def: any - Default store value, global context.

Returns

Function - new reducer function.

Root reducer.

This function was created by the createReducer() function.

Arguments

  1. state: Object - The type of state to be held by the store.
  2. action: Object - The type of actions which may be dispatched.

Returns

Object - Result mixed state.

Add new reducer.

This wrapper function is for the createReducer().add function.

Arguments

  1. reducer: Function - Reducer function.
  2. context: String|Number|Symbol - Context key, use '*' for global context (default).
  3. actionTypes: String|Number|Symbol|*[] - Action type name or action type collection.
  4. defaultValue: any - Any default value for used context. Ignored if added before.

The reducer function (reducerFunction) may contain (as an alternative) the following properties. In this case, it is not necessary to pass additional parameters to the function.

  • reducerFunction.reducerContext - Context key.
  • reducerFunction.reducerActionTypes - Action type name or action type collection.
  • reducerFunction.reducerDefaultValue - Any default value for used context.

See the example above.

Sets the default value for the context state.

This wrapper function is for the createReducer().setDefault function.

Arguments

  1. value: any - The context value.
  2. context: String|Number|Symbol - Context key, use '*' for global context.
  3. override: boolean = true - Modify if exists. Default is true.

Gets the default value for the context state.

This wrapper function is for the createReducer().getDefault function.

Arguments

  1. context: String|Number|Symbol - Context key, use '*' for global context.

Returns

* - Mixed value.

License

Copyright © 2019, GoshaV Maniako. Released under the MIT License.