New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

async-dispatch

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-dispatch

[![npm](https://img.shields.io/npm/v/async-dispatch.svg?maxAge=2592000?style=plastic)](https://www.npmjs.com/package/async-dispatch)

latest
Source
npmnpm
Version
1.0.10
Version published
Maintainers
1
Created
Source

async-dispatch middleware

npm

async-dispatch is a middleware can be added with no time to privilage the asynchronous server requests into your Redux store

For more informatiom about the future of redux-logger, check out the discussion here.

Table of contents

Install

npm i --save async-dispatch

Usage

import asyncDispatchMiddleware from "async-dispatch";
import { createStore } from "redux";
import { applyMiddleware } from "redux";

const store = createStore(
  rootReducer,
  applyMiddleware(asyncDispatchMiddleware)
);
// Note passing middleware as the third argument requires redux@>=3.1.0

Then applying this middleware is simple as

const LoginReducer = (state = intialState, action) => {
    //actionTypes.LOGIN
      login(userData).then((data) => {
        if (data.error) {
          action.asyncDispatch({
            type: actionTypes.ERROR,
            message: data.error,
          });
        } else {
          action.asyncDispatch({
            type: actionTypes.SUCCESS,
            user: data,
            message: "Logged successfully",
          });
        }
      });
      return { ...state };
})

Meanwhile you are leveraging your store as usual as you used to do


  const mapDispatchToProps = (dispatch) => {
    return {
      submit: () => dispatch({ type: actionTypes.LOGIN })
      }
  }
  //Inside your component
  SubmitHandler = () => {
      return props.submit();
  }

To Do

  • Adding typeScript types

License

MIT

Keywords

redux

FAQs

Package last updated on 03 Aug 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts