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

simple-redux-utils

v1.0.0

Published

Simple Redux utils for facilitate workflow

Readme

Simple redux utils

npm version Build Status

Installation

npm install --save simple-redux-utils

Usage

Import the module in your application:

// From ES6
import * as reduxUtils from 'simple-redux-utils'
import { createReducer } from 'simple-redux-utils';

// From CJS
const reduxUtils = require('simple-redux-utils');

// From global
const reduxUtils = simpleReduxUtils.default;

Documentation

Reducers

# createReducer(initialState, handler)

const reducer = createReducer({}, {
  ['ACTION']: (state, action) => state,
});

Return the initialState if no action match.

initialState

Type: any

handler

Type: { actionType: (previousState, action) => nextState } | default: {}

Actions

# asyncActionWith(fn, ...actions)(...params)(dispatch)

const fn = (...params) =>
  Promise.resolve(params);

const request = payload => ({
  type: 'REQUEST',
  payload,
});

const success = payload => ({
  type: 'SUCCESS',
  payload,
});

const failure = payload => ({
  type: 'FAILURE',
  payload,
});

export const action = id =>
  asyncActionWith(
    fn,
    request,
    success,
    failure,
  )(id);

dispatch(action(id));
fn

Type: (...params: Array<any>): Promise<any>

The function to execute in the action creator.

actions

Type: Array<(payload: any) => ACTION>

Array of 3 action creators (REQUEST, SUCCESS, FAILURE).

params

Type: any

Parameters for the function (will be dispatch in REQUEST action).

dispatch

Type: (ACTION) => any

Redux dipatch function.

# bindActionToPromise(actionCreator)(dispatch)

const actionCreator = payload => ({
  type: 'ACTION',
  payload,
})

const boundAction = bindActionToPromise(actionCreator);

dispatch(boundAction(payload));

// Usage with Redux Saga
function* saga() {
  const action = take('ACTION');
  const resolver = getResolverBindActionToPromise(action);

  try {
    yield call(fn, value);
    yield put(actionCreator());

    resolver.resolve();
  } catch(error) {
    resolver.reject(error);
  }
}
actionCreator

Type: (payload: any) => ACTION

payload

Type: any

dispatch

Type: (ACTION) => any

Redux dipatch function.

# getPromiseResolverBoundToPromise(action)

const resolver = getPromiseResolverBoundToPromise(action);

resolver.resolve();
resolver.reject();
action

Type: ACTION

Sagas

# throws(error)

const saga = function* saga() {
  yield put(request());

  try {
    const response = yield call(fetch);

    yield put(success(response));
    yield response;
  } catch (error) {
    // We can handle error at this level
    yield put(failure(error));
    yield call(throws, error);
  }
}

const main = function* main() {
  try {
    yield call(saga);
    yield call(otherSagaWhoCanDispatchActionLikePrevious);
    yield put(success());
  } catch (error) {
    // Or at this one
    // Useful for dispatch different action
    yield put(failure(error));
  }
}
error

Type: { [KEY: any]: any }

# wrapSagaWithResolver(saga, action)

export const watch = function* watch() {
  while (true) {
    const action = yield take(ACTION);

    yield fork(wrapSagaWithResolver, saga, action);
  }
};

const boundAction = bindActionToPromise(actionCreator);

dispatch(boundAction(payload)).then(() => {
  // Enable the possibility to call `.then` on dispatch when action creator
  // has been bound to promise with `bindActionToPromise`
})
saga

Type: function* () => any

action

Type: ACTION

MUST have been bound to promise with bindActionToPromise.

Run the test

npm test