JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q39444F
  • License MIT

Redux middleware to transform an object into a promise

Package Exports

  • redux-object-to-promise

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (redux-object-to-promise) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

redux-object-to-promise

build status npm version

Redux middleware middleware to transform an object into a promise.

npm install --save redux-object-to-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