{"id":13422397,"url":"https://github.com/tshelburne/redux-batched-actions","last_synced_at":"2025-05-14T20:09:02.522Z","repository":{"id":55868425,"uuid":"44563844","full_name":"tshelburne/redux-batched-actions","owner":"tshelburne","description":"redux higher order reducer + action to reduce actions under a single subscriber notification","archived":false,"fork":false,"pushed_at":"2024-03-27T12:02:26.000Z","size":37,"stargazers_count":1047,"open_issues_count":11,"forks_count":37,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-13T15:59:09.971Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tshelburne.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2015-10-19T21:01:34.000Z","updated_at":"2025-02-01T19:19:22.000Z","dependencies_parsed_at":"2024-01-11T17:42:57.248Z","dependency_job_id":"f3ac0140-c7ff-49e4-b09e-8f000c4fc234","html_url":"https://github.com/tshelburne/redux-batched-actions","commit_stats":{"total_commits":51,"total_committers":17,"mean_commits":3.0,"dds":0.5490196078431373,"last_synced_commit":"577b81bf4e7c9538dba9a8c1e251c1555f5c94f1"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tshelburne%2Fredux-batched-actions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tshelburne%2Fredux-batched-actions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tshelburne%2Fredux-batched-actions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tshelburne%2Fredux-batched-actions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tshelburne","download_url":"https://codeload.github.com/tshelburne/redux-batched-actions/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254219373,"owners_count":22034397,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T23:00:43.852Z","updated_at":"2025-05-14T20:09:02.500Z","avatar_url":"https://github.com/tshelburne.png","language":"JavaScript","funding_links":[],"categories":["Code Design","Uncategorized","JavaScript"],"sub_categories":["Data Store","Uncategorized"],"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 =\u003e {\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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftshelburne%2Fredux-batched-actions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftshelburne%2Fredux-batched-actions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftshelburne%2Fredux-batched-actions/lists"}