redux-async-await

1.0.1 • Public • Published

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
}
 

Package Sidebar

Install

npm i redux-async-await

Weekly Downloads

343

Version

1.0.1

License

ISC

Last publish

Collaborators

  • eyasliu