{"_id":"@benmosher/redux-promise","_rev":"4-29554f8c106363a3c94eb07391aae764","name":"@benmosher/redux-promise","description":"FSA-compliant promise middleware for Redux.","dist-tags":{"latest":"0.6.0"},"versions":{"0.6.0":{"name":"@benmosher/redux-promise","version":"0.6.0","description":"FSA-compliant promise middleware for Redux.","main":"lib/index.js","scripts":{"test":"make test","prepublish":"make clean build"},"repository":{"type":"git","url":"git+https://github.com/acdlite/redux-promise.git"},"homepage":"https://github.com/acdlite/redux-promise","keywords":["redux","promise","middleware","redux-middleware","fsa","flux"],"author":{"name":"Andrew Clark","email":"acdlite@me.com"},"license":"MIT","devDependencies":{"babel":"^5.6.14","babel-core":"^5.6.15","babel-eslint":"^5.0.0","chai":"^3.0.0","chai-as-promised":"^5.1.0","eslint":"^0.24.0","eslint-config-airbnb":"0.0.6","mocha":"^2.2.5","sinon":"^1.15.4"},"dependencies":{"flux-standard-action":"^0.6.1"},"gitHead":"a752a332e04a195e230b1d04beb0902362be4ef6","bugs":{"url":"https://github.com/acdlite/redux-promise/issues"},"_id":"@benmosher/redux-promise@0.6.0","_shasum":"f2a32282a973671fb8ed1d95fba2482db7a0c148","_from":".","_npmVersion":"3.7.2","_nodeVersion":"4.2.5","_npmUser":{"name":"benmosher","email":"me@benmosher.com"},"dist":{"shasum":"f2a32282a973671fb8ed1d95fba2482db7a0c148","tarball":"https://registry.npmjs.org/@benmosher/redux-promise/-/redux-promise-0.6.0.tgz","integrity":"sha512-7Y7EIqAznN04HSdaHqo562z/1hnB+jXTODsNkJKPbPL4PM2lhEIz/W4SGOz06m7IufLLXRD65cGQDyXaIXmxgw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCsSEfXiVEH1cAO3s7J09jydYuHgJHMObxdVGKebFWAIwIhAIsIFnO8d/qX7lC5Rt6DmETi6EVlrL3w9g2SK4wZ3CYa"}]},"maintainers":[{"name":"benmosher","email":"me@benmosher.com"}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/redux-promise-0.6.0.tgz_1469815326322_0.8022086194250733"},"directories":{},"deprecated":"redux-promise@0.6.0 officially published (May 2018)"}},"readme":"redux-promise\n=============\n\n[![build status](https://img.shields.io/travis/acdlite/redux-promise/master.svg?style=flat-square)](https://travis-ci.org/acdlite/redux-promise)\n[![npm version](https://img.shields.io/npm/v/redux-promise.svg?style=flat-square)](https://www.npmjs.com/package/redux-promise)\n\n[FSA](https://github.com/acdlite/flux-standard-action)-compliant promise [middleware](https://github.com/gaearon/redux/blob/master/docs/middleware.md) for Redux.\n\n```js\nnpm install --save redux-promise\n```\n\n## Usage\n\n```js\nimport promiseMiddleware from 'redux-promise';\n```\n\nThe default export is a middleware function. If it receives a promise, it will dispatch the resolved value of the promise. It will not dispatch anything if the promise rejects.\n\nIf it receives an Flux Standard Action whose `payload` is a promise, it will either\n\n- dispatch a copy of the action with the resolved value of the promise, and set `status` to `success`.\n- dispatch a copy of the action with the rejected value of the promise, and set `status` to `error`.\n\nThe middleware returns a promise to the caller so that it can wait for the operation to finish before continuing. This is especially useful for server-side rendering. If you find that a promise is not being returned, ensure that all middleware before it in the chain is also returning its `next()` call to the caller.\n\n## Using in combination with redux-actions\n\nBecause it supports FSA actions, you can use redux-promise in combination with [redux-actions](https://github.com/acdlite/redux-actions).\n\n### Example: Async action creators\n\nThis works just like in Flummox:\n\n```js\ncreateAction('FETCH_THING', async id => {\n  const result = await somePromise;\n  return result.someValue;\n});\n```\n\nUnlike Flummox, it will not perform a dispatch at the beginning of the operation, only at the end. We're still looking into the [best way to deal with optimistic updates](https://github.com/acdlite/flux-standard-action/issues/7). If you have a suggestion, let me know.\n\n\n### Example: Integrating with a web API module\n\nSay you have an API module that sends requests to a server. This is a common pattern in Flux apps. Assuming your module supports promises, it's really easy to create action creators that wrap around your API:\n\n```js\nimport { WebAPI } from '../utils/WebAPI';\n\nexport const getThing = createAction('GET_THING', WebAPI.getThing);\nexport const createThing = createAction('POST_THING', WebAPI.createThing);\nexport const updateThing = createAction('UPDATE_THING', WebAPI.updateThing);\nexport const deleteThing = createAction('DELETE_THING', WebAPI.deleteThing);\n```\n\n(You'll probably notice how this could be simplified this even further using something like lodash's `mapValues()`.)\n","maintainers":[{"name":"benmosher","email":"me@benmosher.com"}],"time":{"modified":"2022-06-12T15:10:51.965Z","created":"2016-07-29T18:02:09.398Z","0.6.0":"2016-07-29T18:02:09.398Z"},"homepage":"https://github.com/acdlite/redux-promise","keywords":["redux","promise","middleware","redux-middleware","fsa","flux"],"repository":{"type":"git","url":"git+https://github.com/acdlite/redux-promise.git"},"author":{"name":"Andrew Clark","email":"acdlite@me.com"},"bugs":{"url":"https://github.com/acdlite/redux-promise/issues"},"license":"MIT","readmeFilename":"README.md"}