8000 GitHub - spypsy/redux-object-to-promise: Redux middleware to transform an object into a promise
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

spypsy/redux-object-to-promise

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

redux-object-to-promise

build status npm version

Redux middleware middleware to transform an object into a promise.

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 'redux-object-to-promise';

composeStoreWithMiddleware = applyMiddleware(
	middleware({
	  keyIn = 'promise',
	  keyOut = 'promise',
	  axiosOptions = {},
	  tokenOptions = {storage = window.localStorage, key = 'token-key'}
	})
)(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 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 redux-optimist-promise'
	},
	promise: axiosPromise({url: '/todo', method: 'post', data: {text}})
}

Usage with React-native

import { AsyncStorage } from 'react-native';
import middleware from 'redux-object-to-promise';

composeStoreWithMiddleware = applyMiddleware(
	middleware({
	  tokenOptions: {
			storage: AsyncStorage
		}
	})
)(createStore);

License

MIT

About

Redux middleware to transform an object into a promise

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 97.2%
  • Makefile 2.8%
0