Socket
Socket
Sign inDemoInstall

redux-async-await

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    redux-async-await

redux middleware to es7 async/await syntax action and promise action


Version published
Weekly downloads
343
increased by2.69%
Maintainers
1
Install size
4.66 kB
Created
Weekly downloads
 

Readme

Source

redux-async-await

Build Status

redux middleware deal with es7 async/await syntax action and promise action

install

npm i -S redux-async-await

usage

// apply middleware
import {createStore, applyMiddleware} from 'redux';
import asyncAwait from 'redux-async-await';
const store = applyMiddleware(asyncAwait)(createStore)(yourRootReducer);

------------
// **actions.js**
// use async/await
export async function getInfo(id){
  const data = await fetch('/getUserInfo/' + id).then(res => res.json())
  return {
    type: 'GET_USERINFO',
    data
  }
}
export function getList(){
  return fetch('/getList').then(res => res.json()).then(data => ({
    type: 'GET_LIST',
    data
  }))
}

----------------
// dispatch
try{
  const data = await store.dispatch(getInfo(20)) // if resolve, data === action.data
} catch(e) {
  console.log(e) // if reject
}

Keywords

FAQs

Last updated on 25 Oct 2016

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc