0.1.9 • Published 7 years ago

react-native-redux-object-to-promise v0.1.9

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

react-native-redux-object-to-promise

npm version

Redux middleware middleware to transform an object into a promise. Uses fetch and AsyncStorage.

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):

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'))

export function addTodo(text) {
	return {
		type: 'ADD_TODO',
		payload: {
			text
		},
		meta: {
			promise: {url: '/todo', method: 'post', data: {text}},
		}
	};
}

will dispatch

{
	type: 'ADD_TODO',
	payload: {
		text: 'use react-native-redux-optimist-promise'
	},
	promise: Promise({url: '/todo', method: 'post', data: {text}})
}

License

MIT

0.1.9

7 years ago

0.1.8

7 years ago

0.1.7

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago