mi-redux-async-middleware
v0.1.1
Published
redux async middleware
Downloads
7
Readme
@cnpm/redux-async-middleware
redux中间件,用于stroe dispatch异步action
使用事例
npm install --save mi-redux-async-middleware
创建中间件
import createAsyncMiddleware from 'mi-redux-async-middleware' const asyncMiddleware = createAsyncMiddleware({}) export default asyncMiddleware
创建store
import asyncMiddleware from './create-async-middleware.js' import { createStore, applyMiddleware } from 'redux' const store = createStore( reducers, applyMiddleware(asyncMiddleware, crashReporter) ) export default store
注册要对于那些type使用asyncMiddleware
const addTodo = async (dispatch, getState, ...args) => { const { params } = args const list = await fetch(params) dispatch({ type: 'TODO', list, }) } fnMap.inject('addTodo', addTodo)
发送 dispatch
dispatch({ type: 'TODO', params: {} })