{"_id":"@dankreiger/with-http-reducer","_rev":"3-c135916c9d7c9882b3bf4f3c44f179bb","name":"@dankreiger/with-http-reducer","dist-tags":{"latest":"1.1.18"},"versions":{"1.1.16":{"name":"@dankreiger/with-http-reducer","version":"1.1.16","description":"Higher order reducer that adds standard async actions to a redux reducer","keywords":["async","http","reducers","redux"],"homepage":"https://github.com/dankreiger/with-http-reducer#readme","bugs":{"url":"https://github.com/dankreiger/with-http-reducer/issues"},"repository":{"type":"git","url":"git+https://github.com/dankreiger/with-http-reducer.git"},"license":"ISC","author":{"name":"Dan Kreiger","email":"dan@dankreiger.com","url":"http://www.dankreiger.com/"},"main":"lib/index.js","types":"lib/index.d.ts","scripts":{"build":"tsc","demo":"tar tvf $(npm pack)","format":"prettier --write \"src/**/*.ts\" \"src/**/*.js\"","lint":"tslint -p tsconfig.json","prepare":"husky install","prepublishOnly":"npm run sort && npm test && npm run lint","semantic-release":"semantic-release","sort":"sort-package-json","test":"jest --config jestconfig.json","preversion":"npm run lint","postversion":"git push && git push --tags"},"lint-staged":{"src/**/*.{js,tsx,jsx,json,css}":["prettier --write"]},"devDependencies":{"@commitlint/cli":"12.0.1","@commitlint/config-conventional":"12.0.1","@semantic-release/changelog":"5.0.1","@semantic-release/git":"9.0.0","@semantic-release/github":"7.2.0","@semantic-release/npm":"7.0.10","@types/jest":"26.0.20","husky":"5.1.3","jest":"26.6.3","lint-staged":"10.5.4","prettier":"2.2.1","semantic-release":"17.4.1","sort-package-json":"1.49.0","ts-jest":"26.5.3","tslint":"6.1.3","tslint-config-prettier":"1.18.0","typescript":"4.2.3"},"publishConfig":{"access":"public","registry":"https://registry.npmjs.org"},"release":{"branches":["master"],"plugins":["@semantic-release/commit-analyzer","@semantic-release/release-notes-generator",["@semantic-release/changelog",{"changelogFile":"CHANGELOG.md"}],"@semantic-release/npm","@semantic-release/github",["@semantic-release/git",{"assets":["CHANGELOG.md","package.json"]}]]},"gitHead":"34ff3bc4f41fdbf1d74caa14e7fa7dfa1a612e2c","_id":"@dankreiger/with-http-reducer@1.1.16","_nodeVersion":"14.16.0","_npmVersion":"6.14.11","dist":{"integrity":"sha512-0FH26ic/wjs/6r73IiQssWyx4t3AQUF4GCLy91fO6A5dO//9McPRvCaZpRGOFGzYP2zDLlbhIgbEEBNM+JWI3w==","shasum":"8735ccae700c4837bcf6184286cbaa3e82d91cd0","tarball":"https://registry.npmjs.org/@dankreiger/with-http-reducer/-/with-http-reducer-1.1.16.tgz","fileCount":13,"unpackedSize":14988,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgQ8QpCRA9TVsSAnZWagAA9egP/0OGNaDqvlvJjURKWodt\nIMi/AhueLKeUXZTrbuqoNpJO+/CeHiNvQeOLwL32g3Mpv0UZwbe0QwzKVzj/\n1jNrhyhwOiGkJezA5LpIiXYVlVJWuiflsBcDmN8vhDQzDinno/I6j0GkAUv8\n9BfagEFyZNdQkDVtxuQm7S8taEj3BxQsxjhyMvEXMR3eB1kbOcnqr3i4Bx2m\nsG+JvFMvKlUQ4yjUNAvt1A6/ARDNQSKcCEMDz6BYa/V44t/bZ+hwq+MThpxF\nkYdlflMRGX6mgs0uBS0/+hRUmUmn+XbT+bYyq057rwGOwsnLBZ4xkq6cnNTK\n+9JHONsJ0gSwXJ2NYGZhM7s3hGVlwObqCUyfZFPv8Uo0h3bOoxP+nu2QL/lA\n6qPK3j68VPpNmPLl/NsLEAz1LmQ0VX8T5yp1E30+fEs6pJTETeIACPaX38AJ\nNqVF3B1lgwQQpSLrBx0S92Q/8U5jxH96IHPPYrcsGpAnqSfsSnjgrGD8XN71\nBZbg5A5ikkPbhfI097cKr7OPPHqkvqWAChiaqLkUbgVz91ngt3HJ4OKRyfQ7\nPsDXwDGfA/NUQ7R8fgcxMJkmu+7eTgxL1zy7WAIRBgM7NR8cdfFUOpcxFpgm\nA2FOSd5G/ekIfpYtODSZT8gf/AFtsESwZ0n/8HgcMvrYXr2/1ObEDKEpqm80\nimSh\r\n=pFVJ\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDarewd22pJQh9qf4Z9JvES35vM47vIHwlKzesHtlM6twIhAKFiq4Dv+ReAzLCWcJLedw7QwTMb6ZqyjDD3gvmR3kCd"}]},"_npmUser":{"name":"dankreiger","email":"dan@dankreiger.com"},"directories":{},"maintainers":[{"name":"dankreiger","email":"dan@dankreiger.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/with-http-reducer_1.1.16_1615053864853_0.5685089622529471"},"_hasShrinkwrap":false},"1.1.17":{"name":"@dankreiger/with-http-reducer","version":"1.1.17","description":"Higher order reducer that adds standard async actions to a redux reducer","keywords":["async","http","reducers","redux"],"homepage":"https://github.com/dankreiger/with-http-reducer#readme","bugs":{"url":"https://github.com/dankreiger/with-http-reducer/issues"},"repository":{"type":"git","url":"git+https://github.com/dankreiger/with-http-reducer.git"},"license":"ISC","author":{"name":"Dan Kreiger","email":"dan@dankreiger.com","url":"http://www.dankreiger.com/"},"main":"lib/index.js","types":"lib/index.d.ts","scripts":{"build":"tsc","demo":"tar tvf $(npm pack)","format":"prettier --write \"src/**/*.ts\" \"src/**/*.js\"","lint":"tslint -p tsconfig.json","prepare":"husky install","prepublishOnly":"npm run sort && npm test && npm run lint","semantic-release":"semantic-release","sort":"sort-package-json","test":"jest --config jestconfig.json","preversion":"npm run lint","postversion":"git push && git push --tags"},"lint-staged":{"src/**/*.{js,tsx,jsx,json,css}":["prettier --write"]},"devDependencies":{"@commitlint/cli":"12.0.1","@commitlint/config-conventional":"12.0.1","@semantic-release/changelog":"5.0.1","@semantic-release/git":"9.0.0","@semantic-release/github":"7.2.0","@semantic-release/npm":"7.0.10","@types/jest":"26.0.20","husky":"5.1.3","jest":"26.6.3","lint-staged":"10.5.4","prettier":"2.2.1","semantic-release":"17.4.1","sort-package-json":"1.49.0","ts-jest":"26.5.3","tslint":"6.1.3","tslint-config-prettier":"1.18.0","typescript":"4.2.3"},"publishConfig":{"access":"public","registry":"https://registry.npmjs.org"},"release":{"branches":["master"],"plugins":["@semantic-release/commit-analyzer","@semantic-release/release-notes-generator",["@semantic-release/changelog",{"changelogFile":"CHANGELOG.md"}],"@semantic-release/npm","@semantic-release/github",["@semantic-release/git",{"assets":["CHANGELOG.md","package.json"]}]]},"gitHead":"c57ec5e8272d044a0b7d53615a35d840095d81f8","_id":"@dankreiger/with-http-reducer@1.1.17","_nodeVersion":"14.16.0","_npmVersion":"6.14.11","dist":{"integrity":"sha512-LIrUy7paBaNzTWFmD680eBgK9+EhrX6jPeSZGipIayQowVRcw4j2Mjmlm8Xp9aTSAlAfQmqHvHwlUrL/qN4ppw==","shasum":"2c84d9e4f1fcef8525f0f0f067c07c253238482d","tarball":"https://registry.npmjs.org/@dankreiger/with-http-reducer/-/with-http-reducer-1.1.17.tgz","fileCount":13,"unpackedSize":15233,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgQ8Y0CRA9TVsSAnZWagAApcwP/RabEqqqxHWRlG3Mx6jt\nCl47Ek1Zt3YQpAznXowNL5T8CtI8IK6Pu0nszU/bbfoU4UCt2T6PhREb4/Bt\nfn2deBiV+xBDFxlcfMPwskKfH/yNJv/luVhlayIx1WAE5cR4lKwHNtdJo1IL\njOAicTWR9o0cYV0LbFjplH0N/p5k6jVaDuadubHioLqI8RqGyHo1O8LCGykb\nSe/7tYMcew5x54FnvR/Uq89haqEPn3WK4DhkGgxABArwlzlLs4SRkZY84a+q\nucp9AINzlfjBZ4Tt8q+yIMucV40KuQVAN1WmFasaXg3GPJOLP3jtidXKZOV/\n6K7TpL2j7Lro5MmQmybtTZUhp7Avn7+W145nRjdh8ph4YnmKpSf2bUx2w6J+\nmPH/wAh1bru9eaREEDyzzD1rofzEdmCyG/l11NlHZ86ncqq8XNNjdj0WnTEi\nwEYeRzm8O1Pmy3QDoqZAiPTr9UueHcGGrDF3zwtK4WjzhZ1e9dDqnAHr/E2r\nS3CC6HJOzmx5ncbBvUkUETAmQsv0WHT5vZW0A7By4e9vLnuXNWIECgAlqBw5\n5jm3/e9yMhvc2DxE27k6J/1jhvr37l1WmXIzwgyhDHOdq+86WRGdY9WSdXKk\nHlhXOtV/p5RN9XsojhtuwywVKJHxP60xoh54oJlcMqy5etFUz8T4i2NgcIaw\nunQB\r\n=tfUR\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGbypGSVql2PDHey0wpUsQg8gLytNymdlfXGet/46ue8AiADzxAB+KfIig92SXK6L3nxo9/AKiXJwDrBpKv68Gw2lg=="}]},"_npmUser":{"name":"dankreiger","email":"dan@dankreiger.com"},"directories":{},"maintainers":[{"name":"dankreiger","email":"dan@dankreiger.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/with-http-reducer_1.1.17_1615054388362_0.3159119660485006"},"_hasShrinkwrap":false},"1.1.18":{"name":"@dankreiger/with-http-reducer","version":"1.1.18","description":"Higher order reducer that adds standard async actions to a redux reducer","keywords":["async","http","reducers","redux"],"homepage":"https://github.com/dankreiger/with-http-reducer#readme","bugs":{"url":"https://github.com/dankreiger/with-http-reducer/issues"},"repository":{"type":"git","url":"git+https://github.com/dankreiger/with-http-reducer.git"},"license":"ISC","author":{"name":"Dan Kreiger","email":"dan@dankreiger.com","url":"http://www.dankreiger.com/"},"main":"lib/index.js","types":"lib/index.d.ts","scripts":{"build":"tsc","demo":"tar tvf $(npm pack)","format":"prettier --write \"src/**/*.ts\" \"src/**/*.js\"","lint":"tslint -p tsconfig.json","prepare":"is-ci || husky install","prepublishOnly":"npm run sort && npm test && npm run lint","semantic-release":"semantic-release","sort":"sort-package-json","test":"jest --config jestconfig.json","preversion":"npm run lint","postversion":"git push && git push --tags"},"lint-staged":{"src/**/*.{js,tsx,jsx,json,css}":["prettier --write"]},"devDependencies":{"@commitlint/cli":"12.0.1","@commitlint/config-conventional":"12.0.1","@semantic-release/changelog":"5.0.1","@semantic-release/git":"9.0.0","@semantic-release/github":"7.2.0","@semantic-release/npm":"7.0.10","@types/jest":"26.0.20","husky":"5.1.3","is-ci":"^3.0.0","jest":"26.6.3","lint-staged":"10.5.4","prettier":"2.2.1","semantic-release":"17.4.1","sort-package-json":"1.49.0","ts-jest":"26.5.3","tslint":"6.1.3","tslint-config-prettier":"1.18.0","typescript":"4.2.3"},"publishConfig":{"access":"public","registry":"https://registry.npmjs.org"},"release":{"branches":["master"],"plugins":["@semantic-release/commit-analyzer","@semantic-release/release-notes-generator",["@semantic-release/changelog",{"changelogFile":"CHANGELOG.md"}],"@semantic-release/npm","@semantic-release/github",["@semantic-release/git",{"assets":["CHANGELOG.md","package.json"]}]]},"gitHead":"81503a34826487495d637031a916851d2d5c5fea","_id":"@dankreiger/with-http-reducer@1.1.18","_nodeVersion":"14.16.0","_npmVersion":"6.14.11","dist":{"integrity":"sha512-SEavRBRRjUgiWgppx6/x28HJI2YCqgw55qX/oFfX2musPDWsidOs1uhHmzMsn3EqBLEc3vZUlVoe4it/uhdFyA==","shasum":"2f3d9a1ec283889260ca7f4aa47156a2c3ca8522","tarball":"https://registry.npmjs.org/@dankreiger/with-http-reducer/-/with-http-reducer-1.1.18.tgz","fileCount":13,"unpackedSize":15536,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgQ/mdCRA9TVsSAnZWagAAiZgP/1cPwtB7Rr5gfYd2Df8x\nBCozLbCqwefYEly/TqhSelNVrRXj802I5sIioSZ7gsQQsVRLX7QYQVKbMFdf\nGuGuyV6yz8ByvzTgBs3Mk0SYvgeJHeo3jZi1+EwFZ0Db+v9Svi/mOQbeAr09\nHXt9tA3LDsm8TqMg0A5WPOhQFZyMqvdIQIyBic+caaWq4ezuPw6Ojz2hLEif\nk0EG9AsCFImzaCCvYi+mXBGeKORYpif1DB40rKbszkggwRwgJyZ+M33U/Szw\nrSFh5QI9XGOouJjHg09uY/c5zXDCbDfpNSfpMQSlXWL6YiKb/fUfInrN5sRe\nmBa/u6N1FFWacSczrRHrJZasGyQ54I0z240Jzv5vlTC7N88vcWqYp7RwpbeS\n5iMK19Q0hdpANchtUN7DUda6RZiemGFZiywFlywWno/Ts9ZXb0UU8Ny0NQBR\nckHnLaQx9k8LS7oRAfgJzd4bzZDQAq1yI/B0F7nfrKxJZ2M4kmviWuTuZGSD\nZFTTYmSRdX2s+6OGNfTT7WCCiXGyMepsiPzuhfvt0XZwMo5hceL7rfULpRlZ\nRyer2Kr8vEN+kej74cNr6nkCJcloD/1didLFdzORqxGQ7wwt03/aFxrAkqjg\nUgOtwaff/Or73FSQ9/+DfvNBlyPtJ2owupUvUXiW4YfFI/Xf3y1uebXDukUn\nY6mI\r\n=pY2+\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCcNXQDKxHiX58KhaizVREL/AaCsOzEQHCZnOovKzKTkAIgL7SFwWDAdbUMm5jO+Dp4X5PEAqa2+N4scyYeI8tHj1g="}]},"_npmUser":{"name":"dankreiger","email":"dan@dankreiger.com"},"directories":{},"maintainers":[{"name":"dankreiger","email":"dan@dankreiger.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/with-http-reducer_1.1.18_1615067548927_0.7132884470716971"},"_hasShrinkwrap":false}},"time":{"created":"2021-03-06T18:04:24.790Z","1.1.16":"2021-03-06T18:04:25.047Z","modified":"2022-04-05T02:42:00.994Z","1.1.17":"2021-03-06T18:13:08.562Z","1.1.18":"2021-03-06T21:52:29.089Z"},"maintainers":[{"name":"dankreiger","email":"dan@dankreiger.com"}],"description":"Higher order reducer that adds standard async actions to a redux reducer","homepage":"https://github.com/dankreiger/with-http-reducer#readme","keywords":["async","http","reducers","redux"],"repository":{"type":"git","url":"git+https://github.com/dankreiger/with-http-reducer.git"},"author":{"name":"Dan Kreiger","email":"dan@dankreiger.com","url":"http://www.dankreiger.com/"},"bugs":{"url":"https://github.com/dankreiger/with-http-reducer/issues"},"license":"ISC","readme":"# With HTTP Reducer\n\n[![Build Status](https://travis-ci.org/dankreiger/with-http-reducer.svg?branch=master)](https://travis-ci.org/dankreiger/with-http-reducer)\n\nHigher order reducer for generic `FETCH_BEGIN`, `FETCH_SUCCESS`, and `FETCH_FAILURE` actions\n\n---\n\n```sh\n$ npm install with-http-reducer\n```\n\n## Todo\n\n- fix module exporting so imports can be destructured\n- organize `src` so helpers are more compact and easy to use\n- more tests\n- update docs to describe functionality\n- fix the issues with module exports\n- add better typescript interfaces, enums, and types\n\n## Usage\n\n1. Add helpers to a constants file\n\n   ```js\n   // users.constants.js\n   import whr from 'with-http-reducer';\n\n   export const usersReducerName = 'users';\n\n   export const usersWithHttp = reducer =>\n     whr.withHttpReducer(reducer, usersReducerName);\n\n   export const usersHttpBegin = payload =>\n     whr.httpBegin(usersReducerName, payload);\n   export const usersHttpFailure = payload =>\n     whr.httpFailure(usersReducerName, payload);\n   export const usersHttpSuccess = payload =>\n     whr.httpSuccess(usersReducerName, payload);\n   ```\n\n2. Add in higher order reducer:\n\n   ```js\n   import { usersWithHttp } from './users.constants';\n\n   const users = (state = { current: null }, { type, payload }) => {\n     switch (type) {\n       // any other case statements\n       case 'SET_CURRENT_USER':\n         return { ...state, current: payload };\n       default:\n         return state;\n     }\n   };\n\n   export default usersWithHttp(users);\n   ```\n\n3. Use other helpers where you need them\n\n   ```js\n   // components\n   import React, { useEffect } from 'react';\n   import { usersHttpBegin, selectUsersLoading } from './users.constants';\n   import { useSelector, useDispatch } from 'react-redux';\n\n   export default () => {\n     const dispatch = useDispatch();\n     const loading = useSelector(selectUsersLoading);\n     const httpError = useSelector(selectUsersHttpError);\n     useEffect(() => {\n       dispatch(usersHttpBegin());\n     }, [dispatch]);\n\n     if (httpError) {\n       // show error boundary\n       throw new Error(httpError.message);\n     }\n     if (loading) {\n       return <Spinner />;\n     }\n     return <div>content</div>;\n   };\n   ```\n\n   ```js\n   // thunks\n   import { normalize } from 'normalizr';\n   import {\n     usersHttpBegin,\n     usersHttpSuccess,\n     usersHttpFailure,\n     usersReducerName\n   } from './users.constants';\n\n   function fetchUsers() {\n     return async dispatch => {\n       dispatch(usersHttpBegin());\n       try {\n         const res = await fetch(`someendpoint/users`);\n         const users = await res.json();\n         const usersDictionary = normalize(users, usersSchema);\n         dispatch(\n           usersHttpSuccess({\n             byId: usersDictionary.entities[usersReducerName],\n             allIds: usersDictionary.result\n           })\n         );\n       } catch (err) {\n         dispatch(usersHttpFailure({ err }));\n       }\n     };\n   }\n   ```\n\n   ```js\n   // epics\n   import { normalize } from 'normalizr';\n   import { switchMap, map, catchError } from 'rxjs/operators';\n   import { ajax } from 'rxjs/ajax';\n   import { ofType } from 'redux-observable';\n   import {\n     usersHttpBegin,\n     usersHttpSuccess,\n     usersHttpFailure,\n     usersReducerName\n   } from './users.constants';\n   import { usersSchema } from './users.schema';\n   import { of } from 'rxjs';\n\n   export function fetchUsersEpic(action$) {\n     return action$.pipe(\n       ofType(usersHttpBegin().type),\n       switchMap(() => {\n         return ajax.getJSON(`someendpoint/users`).pipe(\n           map(users => normalize(users, usersSchema)),\n           map(({ entities, result }) =>\n             usersHttpSuccess({\n               byId: entities[usersReducerName],\n               allIds: result\n             })\n           ),\n           catchError(err => of(usersHttpFailure({ err })))\n         );\n       })\n     );\n   }\n   ```\n\n   ```js\n   // sagas\n   import { normalize } from 'normalizr';\n   import { call, put, takeLatest } from 'redux-saga/effects';\n   import {\n     usersHttpBegin,\n     usersHttpSuccess,\n     usersHttpFailure,\n     usersReducerName\n   } from './users.constants';\n   const api = url => fetch(url).then(res => res.json());\n\n   function* handleFetchUsersBeginAsync() {\n     try {\n       const users = yield call(api, `someendpoint/users`);\n       const usersDictionary = yield normalize(users, usersSchema);\n       yield put(\n         usersHttpSuccess({\n           byId: usersDictionary.entities[usersReducerName],\n           allIds: usersDictionary.result\n         })\n       );\n     } catch (err) {\n       put(usersHttpFailure({ err }));\n     }\n   }\n\n   export function* watchFetchUsersBegin() {\n     yield takeLatest(usersHttpBegin().type, handleFetchUsersBeginAsync);\n   }\n   ```\n","readmeFilename":"README.md"}