{"_id":"redux-simple-promise","_rev":"8-fb81dc158ce67e9065d37fdb5f133698","name":"redux-simple-promise","description":"FSA-compliant promise middleware for Redux with simple behaviour with minimal boilerplate declarations.","dist-tags":{"latest":"2.0.2"},"versions":{"1.0.0":{"name":"redux-simple-promise","version":"1.0.0","description":"FSA-compliant promise middleware for Redux with simple behaviour with minimal boilerplate declarations.","main":"lib/index.js","scripts":{"test":"make test","prepublish":"make clean build"},"repository":{"type":"git","url":"git+https://github.com/alanrubin/redux-simple-promise.git"},"homepage":"https://github.com/alanrubin/redux-simple-promise","keywords":["redux","promise","middleware","redux-middleware","fsa","flux"],"author":{"name":"Alan Rubin","email":"alan@frubin.com"},"license":"MIT","devDependencies":{"babel":"^5.6.14","babel-core":"^5.6.15","babel-eslint":"^3.1.20","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.0"},"gitHead":"29c0faee81ed5e46dcf1b89b20802308204e0e6e","bugs":{"url":"https://github.com/alanrubin/redux-simple-promise/issues"},"_id":"redux-simple-promise@1.0.0","_shasum":"84d1098c71ef9cc9d0faf347ef41e610be8efdf9","_from":".","_npmVersion":"2.12.1","_nodeVersion":"0.12.7","_npmUser":{"name":"alanrubin","email":"alan@frubin.com"},"dist":{"shasum":"84d1098c71ef9cc9d0faf347ef41e610be8efdf9","tarball":"https://registry.npmjs.org/redux-simple-promise/-/redux-simple-promise-1.0.0.tgz","integrity":"sha512-J53MIsXmtKu/VgteAEtTEgqq5GpPH5ZpMClFi8qukehMEr6qAYRSyhdFwFJl/iClSi0yg334veV25hOOBTEMkg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICBwaEMFGV9IS+LqfOA15sXGrVcv4jm4N1zY7F5qT5l5AiEA7XzsYKGGgELWGfwjYwvm9pVwvzWj8yoqPjWqFsX3yEM="}]},"maintainers":[{"name":"alanrubin","email":"alan@frubin.com"}]},"1.0.1":{"name":"redux-simple-promise","version":"1.0.1","description":"FSA-compliant promise middleware for Redux with simple behaviour with minimal boilerplate declarations.","main":"lib/index.js","scripts":{"test":"make test","prepublish":"make clean build"},"repository":{"type":"git","url":"git+https://github.com/alanrubin/redux-simple-promise.git"},"homepage":"https://github.com/alanrubin/redux-simple-promise","keywords":["redux","promise","middleware","redux-middleware","fsa","flux"],"author":{"name":"Alan Rubin","email":"alan@frubin.com"},"license":"MIT","devDependencies":{"babel":"^5.6.14","babel-core":"^5.6.15","babel-eslint":"^3.1.20","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.0"},"gitHead":"3216be5dc66d98dc7fb0aa65e387142909ab96fe","bugs":{"url":"https://github.com/alanrubin/redux-simple-promise/issues"},"_id":"redux-simple-promise@1.0.1","_shasum":"4d2cfbce02f6b45406fde257f869488bf72b0ec3","_from":".","_npmVersion":"2.12.1","_nodeVersion":"0.12.7","_npmUser":{"name":"alanrubin","email":"alan@frubin.com"},"dist":{"shasum":"4d2cfbce02f6b45406fde257f869488bf72b0ec3","tarball":"https://registry.npmjs.org/redux-simple-promise/-/redux-simple-promise-1.0.1.tgz","integrity":"sha512-n09pLrCTNfkNg48F5NFAxLTLHCRx1ywv1QwQbFMrsCeVawZnbxh/y6ZfaH1trP1zJXjfGLSUm1sEVRaxxHtn6A==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFr+ra4+6tlNzUH1jec3My+c4nvnfWcvw4uwOH02SHhLAiEAmQ1nfmLtG0LauOCf2CYgvbAjNLijEwzvf1VcSC4YYsU="}]},"maintainers":[{"name":"alanrubin","email":"alan@frubin.com"}]},"2.0.0":{"name":"redux-simple-promise","version":"2.0.0","description":"FSA-compliant promise middleware for Redux with simple behaviour with minimal boilerplate declarations.","main":"lib/index.js","scripts":{"test":"make test","prepublish":"make clean build"},"repository":{"type":"git","url":"git+https://github.com/alanrubin/redux-simple-promise.git"},"homepage":"https://github.com/alanrubin/redux-simple-promise","keywords":["redux","promise","middleware","redux-middleware","fsa","flux"],"author":{"name":"Alan Rubin","email":"alan@frubin.com"},"license":"MIT","devDependencies":{"babel":"^5.6.14","babel-core":"^5.6.15","babel-eslint":"^3.1.20","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.0"},"gitHead":"9c6138c5c11cf06f0b5b53a74277cafdb83c0eee","bugs":{"url":"https://github.com/alanrubin/redux-simple-promise/issues"},"_id":"redux-simple-promise@2.0.0","_shasum":"f6847060de81b7d5c1b190131a0a614457680191","_from":".","_npmVersion":"2.12.1","_nodeVersion":"0.12.7","_npmUser":{"name":"alanrubin","email":"alan@frubin.com"},"dist":{"shasum":"f6847060de81b7d5c1b190131a0a614457680191","tarball":"https://registry.npmjs.org/redux-simple-promise/-/redux-simple-promise-2.0.0.tgz","integrity":"sha512-8GW0rVWC9iHdGQfAJC8dyWj9BGEEXSsKOzVGSfjKFp3YpFfvqhe6jFAx+HXLPpLdjrZhbRrKDyWz9yA+SqM6uQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCQeVFA8ZlXo67Cg4QnkqRmnrUOUmzpKBN7pJY6cIk7SwIgSg2HS3Eparb+z5wf+F86nWVYl7o0qCQTtJH2sDKLwJg="}]},"maintainers":[{"name":"alanrubin","email":"alan@frubin.com"}]},"2.0.1":{"name":"redux-simple-promise","version":"2.0.1","description":"FSA-compliant promise middleware for Redux with simple behaviour with minimal boilerplate declarations.","main":"lib/index.js","scripts":{"test":"make test","prepublish":"make clean build"},"repository":{"type":"git","url":"git+https://github.com/alanrubin/redux-simple-promise.git"},"homepage":"https://github.com/alanrubin/redux-simple-promise","keywords":["redux","promise","middleware","redux-middleware","fsa","flux"],"author":{"name":"Alan Rubin","email":"alan@frubin.com"},"license":"MIT","devDependencies":{"babel":"^5.6.14","babel-core":"^5.6.15","babel-eslint":"^3.1.20","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.0"},"gitHead":"ee62630d3aef5cd0ac6c89092a14d6f258ae7386","bugs":{"url":"https://github.com/alanrubin/redux-simple-promise/issues"},"_id":"redux-simple-promise@2.0.1","_shasum":"647e7890a432282062e2c8abb87d59710ef4741c","_from":".","_npmVersion":"2.12.1","_nodeVersion":"0.12.7","_npmUser":{"name":"alanrubin","email":"alan@frubin.com"},"dist":{"shasum":"647e7890a432282062e2c8abb87d59710ef4741c","tarball":"https://registry.npmjs.org/redux-simple-promise/-/redux-simple-promise-2.0.1.tgz","integrity":"sha512-NTxf1gYi84Bt15ZBsLuV9fhWqQ0/AxwY+w3CBQ9BlzL5VTNvxGg7sa5HWHzGSvlpcWmodvBR+yIN7tKU6bN1ww==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCcRqy/jkie24sxNoyacy9DT6Z5F0QyKYbfUowVMG4w9AIgEoz+JoXPdiAyelH1Gdn0YpViIkp9gt1yc9tfoPGFTps="}]},"maintainers":[{"name":"alanrubin","email":"alan@frubin.com"}]},"2.0.2":{"name":"redux-simple-promise","version":"2.0.2","description":"FSA-compliant promise middleware for Redux with simple behaviour with minimal boilerplate declarations.","main":"lib/index.js","scripts":{"test":"make test","prepublish":"make clean build"},"repository":{"type":"git","url":"git+https://github.com/alanrubin/redux-simple-promise.git"},"homepage":"https://github.com/alanrubin/redux-simple-promise","keywords":["redux","promise","middleware","redux-middleware","fsa","flux"],"author":{"name":"Alan Rubin","email":"alan@frubin.com"},"license":"MIT","devDependencies":{"babel":"^5.6.14","babel-core":"^5.6.15","babel-eslint":"^3.1.20","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.0"},"gitHead":"da12d933d4cafd19cd9465ff809b9ea1bdc674a2","bugs":{"url":"https://github.com/alanrubin/redux-simple-promise/issues"},"_id":"redux-simple-promise@2.0.2","_shasum":"068131d76fea0590ffba47ee55c28bef24ea9642","_from":".","_npmVersion":"2.12.1","_nodeVersion":"0.12.7","_npmUser":{"name":"alanrubin","email":"alan@frubin.com"},"dist":{"shasum":"068131d76fea0590ffba47ee55c28bef24ea9642","tarball":"https://registry.npmjs.org/redux-simple-promise/-/redux-simple-promise-2.0.2.tgz","integrity":"sha512-Bzab1yCkajK+/D4RDkhowkgp3dFr3pBXIuusEERSyScTz6JVcx+oADe9vwgTmaC68N5mXOit505f+5BD5ajY6g==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIA0TOIcDmq4N1pryEhbpjNu/pcPHnOoWhiKvFa1HZsVkAiEAku5BYwRJnUY/hlfXy8U74wVwL3J0DsYpESy6MElSIzE="}]},"maintainers":[{"name":"alanrubin","email":"alan@frubin.com"}]}},"readme":"redux-simple-promise\n=============\n\n[![build status](https://img.shields.io/travis/alanrubin/redux-simple-promise/master.svg?style=flat-square)](https://travis-ci.org/alanrubin/redux-simple-promise)\n[![npm version](https://img.shields.io/npm/v/redux-simple-promise.svg?style=flat-square)](https://www.npmjs.com/package/redux-simple-promise)\n\n[FSA](https://github.com/acdlite/flux-standard-action)-compliant promise [middleware](http://rackt.github.io/redux/docs/advanced/Middleware.html) for Redux with simple behaviour with minimal boilerplate declarations.\n\n```js\nnpm install --save redux-simple-promise\n```\n\n## Usage\n\nFirst, 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):**\n\n```js\nimport promiseMiddleware from 'redux-simple-promise';\n\ncomposeStoreWithMiddleware = applyMiddleware(\n  promiseMiddleware()\n)(createStore);\n\n```\n\nTo use the middleware, dispatch a `promise` property and optional additional properties within the `payload` of the action and specify the action `type` string as you normally do. \n\nThe pending action is dispatched immediately, with `type` the same as the original dispatching action with all original `payload` properties apart from the `promise` as the payload object (those are useful for optimistic updates). The resolve action is dispatched only if the promise is resolved, e.g., if it was successful; and the rejected action is dispatched only if the promise is rejected, e.g., if an error occurred.\n\nBoth fullfilled actions (resolved and rejected) will be dispatched with the result of the promise as the payload object and all other remaining properties will be dispatched inside the `meta` property. More specifically, in the case of a rejected promise, an `error` is returned in the payload property. Also those fullfiled actions will have the original `type` added by a suffix (default is `_RESOLVED` for resolved and `_REJECTED` for rejected).\n\nExample:\n\nThe below action creator, when triggered `dispatch(loadUser('alanrubin'))`\n\n```js\nexport function loadUser(username) {\n  return {\n    type: 'LOAD_USER',\n    payload: {\n      promise: loadUserServiceAndReturnPromise(username)\n      username\n    }\n  };\n}\n```\n\nwill dispatch immediatelly\n```js\n{\n\ttype: 'LOAD_USER',\n\tpayload: {\n\t\tusername: 'alanrubin'\n\t} \n}\n```\n\nAssuming promise resolves with `{ id: '1', name: 'Alan Rubin' }`, then it will dispatch\n```js\n{\n\ttype: 'LOAD_USER_RESOLVED',\n\tpayload: { id: '1', name: 'Alan Rubin' },\n\tmeta: {\n\t\tusername: 'alanrubin'\n\t}\n}\n```\n\nAssuming promise rejects with `Error` object, then it will dispatch\n```js\n{\n\ttype: 'LOAD_USER_REJECTED',\n\tpayload: Error,\n\tmeta: {\n\t\tusername: 'alanrubin'\n\t}\n}\n```\n\nThe middleware also returns the original promise, so you can listen to it and act accordingly from your component if needed (for example redirecting to a new route).\n\nThe middleware doesn't include the original promise in the 3 processed actions as it is not useful in the reducers - it is a bad practice to store promises in the state as the state should be serializable.\n\n### Usage in reducers\n\nAnother nice feature is that `resolve` and `reject` functions can be imported from the package in order to provide nice semantic switch conditions when writing reducers for those actions. Assuming the example above, in your reducer:\n\n```js\nimport { resolve, reject } from 'redux-simple-promise';\n\nfunction users(state = {}, action) {\n  switch (action.type) {\n  case LOAD_USER:\n    return Object.assign({}, state, {\n      action.payload.username: { isLoading: true }\n    });\n  case resolve(LOAD_USER):\n    return Object.assign({}, state, {\n      action.meta.username: action.payload\n    });\n  case reject(LOAD_USER):\n  \treturn Object.assign({}, state, {\n      action.meta.username: { error: action.payload }\n    });\n  default:\n    return state;\n  }\n}\n\n```\n\n## Configuration\n\nYou can configure the string being added to the action type when resolved or rejected by declaring it when initialiazing the middleware, so considering the example above, if you do\n\n```js\nimport promiseMiddleware from 'redux-simple-promise';\n\ncomposeStoreWithMiddleware = applyMiddleware(\n  promiseMiddleware('_MY_RESOLVED', '_MY_REJECTED')\n)(createStore);\n\n```\n\nthen resolved/rejected promised will trigger actions as `'LOAD_USER_MY_RESOLVED'` and `'LOAD_USER_MY_REJECTED'` instead of the default ones `'LOAD_USER_RESOLVED'` and `'LOAD_USER_REJECTED'`.\n\n## Inspiration\n\nI have tried to mix the best behaviour from both [redux-promise](https://github.com/acdlite/redux-promise) and [redux-promise-middleware](https://github.com/pburtchaell/redux-promise-middleware) projects, avoiding as much as possible additional boilerplate declarations (such as declaring 3 times the action type or passing the arguments of the first dispatch in data or meta) and the most consistent behavior (at least in my opinion...).\n\nThanks to both projects for inspiration, specially to [redux-promise](https://github.com/acdlite/redux-promise) for the project setup and test inspiration.\n\n---\nLicensed MIT. Copyright 2015 Alan Rubin.","maintainers":[{"name":"alanrubin","email":"alan@frubin.com"}],"time":{"modified":"2022-06-26T10:27:08.401Z","created":"2015-09-03T10:30:11.885Z","1.0.0":"2015-09-03T10:30:11.885Z","1.0.1":"2015-09-03T10:35:50.962Z","2.0.0":"2015-09-07T12:33:02.384Z","2.0.1":"2015-09-07T15:43:00.977Z","2.0.2":"2015-09-08T13:12:27.202Z"},"homepage":"https://github.com/alanrubin/redux-simple-promise","keywords":["redux","promise","middleware","redux-middleware","fsa","flux"],"repository":{"type":"git","url":"git+https://github.com/alanrubin/redux-simple-promise.git"},"author":{"name":"Alan Rubin","email":"alan@frubin.com"},"bugs":{"url":"https://github.com/alanrubin/redux-simple-promise/issues"},"license":"MIT","readmeFilename":"README.md","users":{"shakakira":true}}