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

reduxec

v1.17.2

Published

Reusable actions and reducers for redux

Readme

Reduxec

Reusable actions and reducers for redux

Concepts

Add additional dimension for actions and reducers to specify where exactly on the state tree action should be applied.

Install

yarn add reduxec

or

npm install reduxec --save

Usage

Reduxec uses several conceptual elements:

  • Target
  • Namespace
  • Exection (exec-action)

Targets

Targets are reducers grouped in one namespace. Target can be created with handlers object by createTarget:

// counter-target.js
import { createTarget } from 'reduxec';

const counterHandlers = {
  INCREMENT: (state, action) => state + 1, 
  DECREMENT: (state, action) => state - 1,
  SET: (state, action) => action.payload
};

export default createTarget(counterHandlers);

Created target should be passed to namespace.

Namespaces

Namespaces are reducers with targets. Namespace will take action and will pass it to corresponding target.

// counters-namespace.js
import createNamespace from 'reduxec';
import counterTarget from './counter-target';

const countersNamespace = createNamespace({
  counter1: counterTarget(0),
  counter2: counterTarget(100),
  counter3: counterTarget(-100)
}, 'COUNTERS');

export default countersNamespace;

Note that counterTarget is a function that takes initialState as an argument.

Reduxec namespace reducer can be used along side with any other reducers:

// root-reducer.js
import { combineReducers } from 'redux';
import counterNamespace from './counters-namespace.js';

const rootReducer = combine({
  plain: myPlainReducer,
  counters: counterNamespace
});

export default rootReducer;

Exec-actions

Differences from plain redux actions:

  1. should have exec and target fields
  2. type is used as a trigger to determine on which namespace it should be used
// Simple reduxec-action
const action = {
  type: 'COUNTERS',
  meta: {
    target: 'counter1',
    exec: 'INCREMENT'
  }
};

Same action can be created with createAction:

import { createAction } from 'reduxec';

const actionDescriptor = { exec: 'INCREMENT' };

// return [Function]
const withTrigger = createAction('COUNTERS');

// return [Function]
const withTriggerAndTarget = withTrigger('counter1');

// return final action object
const action = withTriggerAndTarget(actionDescriptor);

createAction is a higher-order function, so it can be bound to specific namespace and/or target.

To bind multiple actions can be used createActions:

// actions.js
import { createActions } from 'reduxec';

const actionsObject = {
  increment: { exec: 'INCREMENT' },
  decrement: { exec: 'DECREMENT' }
  // actions in action object could be functions.
  set: value => ({ exec: 'SET', payload: value }),
};

// we can hard bind to `COUNTERS` namespace if we are sure 
// that it is the only place where actions will be used
const countersActions = createActions('COUNTERS');

export default function getActions(target) {
  return countersActions(target)(actionsObject);
}
// index.js
import getActions from './actions.js';
import getStore from './store.js';

const counterOneActions = getActions('counter1');
const counterTwoActions = getActions('counter2');
const store = getStore();

store.dispatch(counterOneActions.increment());
/* action:
{ 
  type: 'COUNTERS',
  meta: {
    exec: 'INCREMENT',
    target: 'counter1'
  }
}
*/

store.dispatch(counterTwoActions.set(10));
/* action:
{ 
  type: 'COUNTERS',
  meta: {
    exec: 'SET',
    target: 'counter2'
  },
  payload: 10
}
*/

Examples

counter

API

Targets

createTarget

  • signature :: handlers -> initialState -> { initialState, reducer }

Namespaces

createNamespace

  • signature :: (targets, trigger) -> reducer

createNamespaceObject

  • signature :: (targets, namespace) -> { namespace: reducer }

Exections

createAction

  • signature :: string -> string -> { exec, payload, meta} -> { type, meta, payload }

wrapActions

  • signature :: F (...args -> action) -> { ...action } -> { ...F(action) }

bindActions

  • signature :: (F actionCreatorWithTrigger -> target -> { ...action }) -> { ...F(action) }

createActions

  • signature :: string -> string -> { ...action } -> { ...action }