Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/arojunior/redux-middleware-injector
Middleware injector for Redux
https://github.com/arojunior/redux-middleware-injector
javascript middleware redux redux-middleware-injector
Last synced: 3 months ago
JSON representation
Middleware injector for Redux
- Host: GitHub
- URL: https://github.com/arojunior/redux-middleware-injector
- Owner: arojunior
- Created: 2017-04-12T20:06:32.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-05-03T11:51:27.000Z (over 7 years ago)
- Last Synced: 2024-09-21T19:51:37.306Z (4 months ago)
- Topics: javascript, middleware, redux, redux-middleware-injector
- Language: JavaScript
- Size: 9.77 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Redux Middleware Injector
[![npm version](https://img.shields.io/npm/v/redux-middleware-injector.svg)](https://www.npmjs.com/package/redux-middleware-injector) [![npm downloads](https://img.shields.io/npm/dm/redux-middleware-injector.svg)](https://www.npmjs.com/package/redux-middleware-injector) [![Standard - JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
The recomended place to execute actions with side-effects in Redux is in the Middlewares.
With this lib you can write your own middleware wherever you want, for example in the action creators file.
You don't need to import all the middlewares with applyMiddleware before create the store.Just import the injector:
```javascript
import injectMiddleware from "redux-middleware-injector"const store = createStore(rootReducer, applyMiddleware(injectMiddleware))
```
And then you can write your own middlewares like the example below:```javascript
export const getUser = username => store => {
const {dispatch} = storereturn next => action => {
dispatch({type: 'modules/Github/FETCHING'})return axios.get(`https://api.github.com/users/${username}`).then(res => {
dispatch({
type: 'modules/Github/SUCCESS',
payload: {
data: res.data
}
})
})
}
}
```See [Redux documentation](http://redux.js.org/docs/advanced/Middleware.html) about Middlewares