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 🙏

© 2024 – Pkg Stats / Ryan Hefner

redux-actions-promise

v1.1.5

Published

FSA-compliant promise middleware for Redux, supports referencing dispatcher/state in action

Downloads

4

Readme

build pass npm-version license bower-license

redux-actions-promise

FSA-compliant promise middleware for Redux, supports referencing dispatcher/state in action.

Installation

Install the pkg with npm:

npm install redux-actions-promise --save

or yarn

yarn add redux-actions-promise

or bower

bower install redux-actions-promise

Usage

// store.js
// create store
import ReduxActionsPromise from 'redux-actions-promise';
import { createStore, applyMiddleware } from 'redux';

// Note: this API requires redux@>=3.1.0
export default createStore(rootReducer, applyMiddleware(ReduxActionsPromise));

// actions.js
import {createAction} from 'redux-actions';

// async action
export let addToDo = createAction(CONSTANT.ADD_TODO, (val) => async (dispatch, getState) => {
    console.log('prev state', getState())
    let v = await Promise.resolve('todo: ' + val);
    return v;
});

// sync action
export let deleteToDo = createAction(CONSTANT.DELETE_TODO);

FAQ

  1. why not use redux-thunk ?
  • I would like to use createAction for FSA.
  • I don't want to handle promise error in action by myself.

In redux-thunk:

addToDo = (val) => async (dispatch, getState) => {
    let v = await Promise.reject('error');
    // can't output in console
    console.log('addToDo');
    dispatch({
        type: "ADD_TODO",
        payload: {
            val: v
        }
    })
};

If promise is rejected, the programme will be abort. So if you don't want this happen, you should handle it by yourself:

addToDo = (val) => async (dispatch, getState) => {
    try{
        let v = await Promise.reject('error');
        // can't output in console
        console.log('addToDo');
        dispatch({
            type: "ADD_TODO",
            payload: {
                val: v
            }
        })
    } catch(e) {
        dispatch({
            type: "ADD_TODO_ERROR",
            payload: e,
            error: true
        })
    }
};

Use async-await-error-handling maybe simple the code:

import awaitTo from 'async-await-error-handling';

//...

addToDo = (val) => async (dispatch, getState) => {
    const [err, data] = await awaitTo(Promise.reject('error'));
    if(err){
        dispatch({
            type: "ADD_TODO_ERROR",
            payload: e,
            error: true
        });
        return;
    }
    dispatch({
        type: "ADD_TODO",
        payload: {
            val: data
        }
    });
};
  1. why not use redux-promise ?

Because it doesn't support referencing dispatcher or state in action. See #20.

LICENSE

MIT