Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lukem512/react-native-redux-object-to-promise
Redux middleware to transform an object into a promise for React Native apps
https://github.com/lukem512/react-native-redux-object-to-promise
fetch middleware network react-native redux
Last synced: about 8 hours ago
JSON representation
Redux middleware to transform an object into a promise for React Native apps
- Host: GitHub
- URL: https://github.com/lukem512/react-native-redux-object-to-promise
- Owner: lukem512
- Created: 2017-04-24T13:17:07.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-05-03T09:37:23.000Z (over 7 years ago)
- Last Synced: 2024-10-30T11:51:06.437Z (21 days ago)
- Topics: fetch, middleware, network, react-native, redux
- Language: JavaScript
- Homepage: https://npmjs.com/package/react-native-redux-object-to-promise
- Size: 18.6 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
react-native-redux-object-to-promise
=============[![npm version](https://img.shields.io/npm/v/react-native-redux-object-to-promise.svg?style=flat-square)](https://www.npmjs.com/package/react-native-redux-object-to-promise)
Redux [middleware](http://rackt.github.io/redux/docs/advanced/Middleware.html) middleware to transform an object into a promise. Uses `fetch` and `AsyncStorage`.
```js
npm install --save redux-optimist-promise
```## Usage in middlewares
First, import the middleware creator and include it in `applyMiddleware` when creating the Redux store. **You need to call it as a function (See later why on configuration section below):**
```js
import middleware from 'react-native-redux-object-to-promise';composeStoreWithMiddleware = applyMiddleware(
middleware({
keyIn = 'promise',
keyOut = 'promise',
tokenKey = 'token-key',
fetchOptions = {}
})
)(createStore);```
To use the middleware, dispatch a `promise` property within the `meta` of the action.
Example:
The below action creator, when triggered `dispatch(addTodo('use react-native-redux-object-to-promise'))`
```js
export function addTodo(text) {
return {
type: 'ADD_TODO',
payload: {
text
},
meta: {
promise: {url: '/todo', method: 'post', data: {text}},
}
};
}
```will dispatch
```js
{
type: 'ADD_TODO',
payload: {
text: 'use react-native-redux-optimist-promise'
},
promise: Promise({url: '/todo', method: 'post', data: {text}})
}
```## License
MIT