{"_id":"@conveyorhq/redux-batched-actions","_rev":"1-c6eda07cc97bf6b351637ba8141e7b7b","name":"@conveyorhq/redux-batched-actions","dist-tags":{"latest":"0.5.1"},"versions":{"0.5.0":{"name":"@conveyorhq/redux-batched-actions","version":"0.5.0","description":"redux higher order reducer + action creator to reduce actions under a single subscriber notification","main":"lib/index.js","unpkg":"dist/index.js","module":"es/index.mjs","types":"lib/index.d.ts","scripts":{"test":"export BABEL_ENV=cjs && node_modules/.bin/mocha --require @babel/register","clean":"rm -rf lib es dist","copy:ts":"cp src/index.d.ts lib/index.d.ts","build:js":"babel src","build:cjs":"npm run build:js -- --env-name cjs --out-dir lib/","build:mjs":"npm run build:js -- --env-name mjs --out-dir es/; j2m es/*","build:umd":"npm run build:js -- --env-name dist --out-dir dist/","build":"npm run clean; npm run build:umd && npm run build:cjs && npm run build:mjs && npm run copy:ts","prepublishOnly":"npm run clean && npm run build"},"repository":{"type":"git","url":"https://github.com/conveyor/redux-batched-actions"},"keywords":["redux","react","reactjs","batched","action"],"author":{"name":"Tim Shelburne","email":"shelburt02@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/conveyor/redux-batched-actions/issues"},"homepage":"https://github.com/conveyor/redux-batched-actions","devDependencies":{"@babel/cli":"^7.8.4","@babel/core":"^7.9.0","@babel/preset-env":"^7.9.0","@babel/register":"^7.9.0","chai":"^4.2.0","js-to-mjs":"^0.2.0","mocha":"^7.1.1","sinon":"^9.0.1","sinon-chai":"^3.5.0"},"peerDependencies":{"redux":">=1.0.0"},"licenseText":"MIT License\n\nCopyright (c) 2016 Tim Shelburne\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"@conveyorhq/redux-batched-actions@0.5.0","dist":{"shasum":"c59708fc44fdc620952774d28b74ac60df2b32e7","integrity":"sha512-KVj7uMBQFqO0RYagdBtKPUYV3Utj3DBwipJnPFWBtC9RrXjdpr/flDH4keWS7LyD232KSP/+IEEv//ruW4rykQ==","tarball":"https://registry.npmjs.org/@conveyorhq/redux-batched-actions/-/redux-batched-actions-0.5.0.tgz","fileCount":13,"unpackedSize":12525,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCaKUzlYLnJyi+DcxB+BbD0iV/769Z5UuenyIOsB9ts6wIgWmzy831fWwtk9UpGK428kbDGy3Lbb9y6OfrXAM4rf2I="}]},"_npmUser":{"name":"conveyorhq-eng","email":"engineering@conveyorhq.com"},"directories":{},"maintainers":[{"name":"conveyorhq-eng","email":"engineering@conveyorhq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/redux-batched-actions_0.5.0_1704465569842_0.05888845931676423"},"_hasShrinkwrap":false},"0.5.1":{"name":"@conveyorhq/redux-batched-actions","version":"0.5.1","description":"redux higher order reducer + action creator to reduce actions under a single subscriber notification","main":"lib/index.js","unpkg":"dist/index.js","module":"es/index.mjs","types":"lib/index.d.ts","scripts":{"test":"export BABEL_ENV=cjs && node_modules/.bin/mocha --require @babel/register","clean":"rm -rf lib es dist","copy:ts":"cp src/index.d.ts lib/index.d.ts","build:js":"babel src","build:cjs":"npm run build:js -- --env-name cjs --out-dir lib/","build:mjs":"npm run build:js -- --env-name mjs --out-dir es/; npx j2m --toM es/*","build:umd":"npm run build:js -- --env-name dist --out-dir dist/","build":"npm run clean; npm run build:umd && npm run build:cjs && npm run build:mjs && npm run copy:ts","prepublishOnly":"npm run clean && npm run build"},"repository":{"type":"git","url":"https://github.com/conveyor/redux-batched-actions"},"keywords":["redux","react","reactjs","batched","action"],"author":{"name":"Tim Shelburne","email":"shelburt02@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/conveyor/redux-batched-actions/issues"},"homepage":"https://github.com/conveyor/redux-batched-actions","devDependencies":{"@babel/cli":"^7.23.4","@babel/core":"^7.23.6","@babel/preset-env":"^7.23.6","@babel/register":"^7.22.15","chai":"^4.3.10","mocha":"^10.2.0","sinon":"^17.0.1","sinon-chai":"^3.7.0"},"peerDependencies":{"redux":">=5.0.0"},"licenseText":"MIT License\n\nCopyright (c) 2016 Tim Shelburne\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"@conveyorhq/redux-batched-actions@0.5.1","dist":{"shasum":"6a2c2ee302024a33f429d5c6ccfe3668c02b6823","integrity":"sha512-KIBmTwaqJWyAjABKQEdK7MOv+RSdxANVBYDtUjh2fnI0fN8ycLDgENUmg5WTjB/RJ71QRKU8M52QvdS+6DFoGQ==","tarball":"https://registry.npmjs.org/@conveyorhq/redux-batched-actions/-/redux-batched-actions-0.5.1.tgz","fileCount":13,"unpackedSize":12555,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBiaj+9U1tOZATk41hT+Q77yiQfbLnZovs7lvFy234YuAiBYi55JzWVjJxqyHKSeHQneNUR3Pz+Nir0MSx22q7U3iQ=="}]},"_npmUser":{"name":"conveyorhq-eng","email":"engineering@conveyorhq.com"},"directories":{},"maintainers":[{"name":"conveyorhq-eng","email":"engineering@conveyorhq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/redux-batched-actions_0.5.1_1704470061396_0.4089625701444848"},"_hasShrinkwrap":false}},"time":{"created":"2024-01-05T14:39:29.693Z","0.5.0":"2024-01-05T14:39:30.015Z","modified":"2024-01-05T15:54:21.762Z","0.5.1":"2024-01-05T15:54:21.586Z"},"maintainers":[{"name":"conveyorhq-eng","email":"engineering@conveyorhq.com"}],"description":"redux higher order reducer + action creator to reduce actions under a single subscriber notification","homepage":"https://github.com/conveyor/redux-batched-actions","keywords":["redux","react","reactjs","batched","action"],"repository":{"type":"git","url":"https://github.com/conveyor/redux-batched-actions"},"author":{"name":"Tim Shelburne","email":"shelburt02@gmail.com"},"bugs":{"url":"https://github.com/conveyor/redux-batched-actions/issues"},"license":"MIT","readme":"redux-batched-actions\n=====================\n\n[![Build Status](https://travis-ci.org/tshelburne/redux-batched-actions.svg)](https://travis-ci.org/tshelburne/redux-batched-actions)\n\nBatching action creator and associated higher order reducer for [redux](https://github.com/gaearon/redux) that enables batching subscriber notifications for an array of actions.\n\n```js\nnpm install --save redux-batched-actions\n```\n\n## Usage\n\n```js\nimport {createStore, applyMiddleware} from 'redux';\nimport {batchActions, enableBatching, batchDispatchMiddleware} from 'redux-batched-actions';\nimport {createAction} from 'redux-actions';\n\nconst doThing = createAction('DO_THING')\nconst doOther = createAction('DO_OTHER')\n\nfunction reducer(state, action) {\n\tswitch (action.type) {\n\t\tcase 'DO_THING': return 'thing'\n\t\tcase 'DO_OTHER': return 'other'\n\t\tdefault: return state\n\t}\n}\n\n// Handle bundled actions in reducer\nconst store = createStore(enableBatching(reducer), initialState)\n\nstore.dispatch(batchActions([doThing(), doOther()]))\n// OR\nstore.dispatch(batchActions([doThing(), doOther()], 'DO_BOTH'))\n\n```\n\n## Recipes\n\n### Async\n\nUsage for action creators that return objects is trivial, but it also works well with [thunks](https://github.com/gaearon/redux-thunk) to perform large reductions on multiple asynchronous actions, or actions that rely on external services. For example:\n\n```js\nconst setLoading = createAction('SET_LOADING')\nconst setUser = createAction('SET_USER')\nconst unsetLoading = createAction('UNSET_LOADING')\n\nfunction login(credentials) {\n\treturn function(dispatch) {\n\t\tdispatch(setLoading());\n\n\t\tauthenticate(credentials)\n\t\t\t.then(user => {\n\t\t\t\tdispatch(batchActions([\n\t\t\t\t\tsetUser(user),\n\t\t\t\t\tunsetLoading()\n\t\t\t\t], 'LOGIN_SUCCESS'))\n\t\t\t})\n\t\t})\n\t}\n}\n```\n\nIn this example, the subscribers would be notified twice: once when the state is loading, and then again once the user has been loaded.\n\n### Middleware integration\n\nYou can add a middleware to dispatch each of the bundled actions. This can be used if other middlewares are listening for one of the bundled actions to be dispatched.\n\n```js\nconst store = createStore(\n\t\treducer,\n\t\tinitialState,\n\t\tapplyMiddleware(batchDispatchMiddleware)\n)\n```\n\nNote that batchDispatchMiddleware and enableBatching should not be used together as batchDispatchMiddleware calls next on the action it receives, whilst also dispatching each of the bundled actions.\n\n## Thanks\n\nThanks to [Dan Abramov](https://github.com/gaearon) for help in Redux best practices and original idea.\n","readmeFilename":"README.md"}