{"_id":"@crossfield/redux-batched-actions","_rev":"2-80fe2f153b0d12cd6396b2649b447ce2","name":"@crossfield/redux-batched-actions","description":"redux higher order reducer + action creator to reduce actions under a single subscriber notification","dist-tags":{"latest":"0.1.6-0"},"versions":{"0.1.6-0":{"name":"@crossfield/redux-batched-actions","version":"0.1.6-0","description":"redux higher order reducer + action creator to reduce actions under a single subscriber notification","main":"lib/index.js","types":"lib/index.d.ts","scripts":{"test":"mocha --compilers js:babel-core/register","clean":"rm -rf lib","build":"babel src --out-dir lib && cp src/index.d.ts lib","prepublish":"npm run clean && npm run build"},"repository":{"type":"git","url":"git+https://github.com/tshelburne/redux-batched-actions.git"},"keywords":["redux","react","reactjs","batched","action"],"author":{"name":"Tim Shelburne","email":"shelburt02@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/tshelburne/redux-batched-actions/issues"},"homepage":"https://github.com/tshelburne/redux-batched-actions","devDependencies":{"babel-core":"^6.5.2","babel-cli":"^6.11.4","babel-preset-es2015":"^6.9.0","chai":"^3.3.0","mocha":"^2.3.3","sinon":"^1.17.1","sinon-chai":"^2.8.0"},"peerDependencies":{"redux":">=1.0.0"},"gitHead":"5c385c869025252f77da194b1a6d149bb59ab804","_id":"@crossfield/redux-batched-actions@0.1.6-0","_npmVersion":"5.3.0","_nodeVersion":"8.2.1","_npmUser":{"name":"crossfield","email":"dev@crossfield.com"},"dist":{"integrity":"sha512-4QF8bbFNq1nl+znbt3DbFRSx2QVpjx1XQmTFmaI7BujHDoIcVIMeFnKX0jRnvamOZFMhFev0TyvQnc0x7aBycg==","shasum":"238c3d06b12567191a63bd8f0edc95af4ae6bda4","tarball":"https://registry.npmjs.org/@crossfield/redux-batched-actions/-/redux-batched-actions-0.1.6-0.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDD+mikDGqVo2XnNFTjn4aYKdHHTucG8544IOdbBbzNIAiAbTYWCikia70FsjtmkrT/oRYCFUvTZlb1mDXj5GcbmnQ=="}]},"maintainers":[{"name":"crossfield","email":"dev@crossfield.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/redux-batched-actions-0.1.6-0.tgz_1501243306905_0.7419313054997474"},"directories":{}}},"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} from 'redux';\nimport {batchActions, enableBatching} 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\nconst store = createStore(enableBatching(reducer), initialState)\n\nstore.dispatch(batchActions([doThing(), doOther()]))\n// OR\nstore.dispatch(batchActions([doThing(), doOther()], 'DO_BOTH'))\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## Thanks\n\nThanks to [Dan Abramov](https://github.com/gaearon) for help in Redux best practices and original idea.\n","maintainers":[{"email":"dev@crossfield.com","name":"crxssfield"}],"time":{"modified":"2022-04-05T01:52:39.216Z","created":"2017-07-28T12:01:47.943Z","0.1.6-0":"2017-07-28T12:01:47.943Z"},"homepage":"https://github.com/tshelburne/redux-batched-actions","keywords":["redux","react","reactjs","batched","action"],"repository":{"type":"git","url":"git+https://github.com/tshelburne/redux-batched-actions.git"},"author":{"name":"Tim Shelburne","email":"shelburt02@gmail.com"},"bugs":{"url":"https://github.com/tshelburne/redux-batched-actions/issues"},"license":"MIT","readmeFilename":"README.md"}