quiqup-redux-network
v1.0.0-web734.1
Published
Middleware used to handle network request in redux
Readme
QuiupReduxNetwork
Package that provides middlewares that handle network actions
Network Error Middleware
Middleware that dispatches actions when some network call fails
Usage
import { createStore, applyMiddleware, compose } from 'redux'
import rootReducer from './reducers'
import { networkErrorMiddleware } from '@quiqupltd/quiqup-redux-network'
export default function configureStore(preloadedState) {
return createStore(rootReducer, preloadedState, compose(
applyMiddleware(networkErrorMiddleware),
))
}What it does
Middleware used to handle network request errors. Dispatches action type NETWORK_ERROR or handles action and continues to the next middleware
Example
let myAction = {
payload: 'test',
type: 'getStore'
}
let next = (action) => {
return (action) => {
return action
}
}
networkErrorMiddleware(action) {
// on fail
expect(next(myAction).type).toBe('NETWORK_ERROR')
// on success
expect(next(myAction).payload).toBe('test')
}Contributing
Getting the project ready:
git clone [email protected]:frontend/quiqup-redux-network.git
cd quiqup-redux-network
npm installRunning tests
npm run test:watchBuild bundle
npm run build:watchWorking with another project
To develop with another application, you can use npm link to connect your project to quiqup-redux-network while developing
cd quiqup-redux-network
npm link
cd /project-using-quiqup-redux-network
npm link @quiqup/quiqup-redux-network