{"id":20494063,"url":"https://github.com/jaystack/redux-repatch","last_synced_at":"2025-04-13T17:21:29.260Z","repository":{"id":57351400,"uuid":"101649059","full_name":"jaystack/redux-repatch","owner":"jaystack","description":"Redux enhancer for dispatching reducers","archived":false,"fork":false,"pushed_at":"2017-09-25T10:06:58.000Z","size":42,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-04-26T22:20:41.683Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/jaystack.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-08-28T14:01:54.000Z","updated_at":"2018-04-20T23:01:53.000Z","dependencies_parsed_at":"2022-08-31T03:50:30.120Z","dependency_job_id":null,"html_url":"https://github.com/jaystack/redux-repatch","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaystack%2Fredux-repatch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaystack%2Fredux-repatch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaystack%2Fredux-repatch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaystack%2Fredux-repatch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jaystack","download_url":"https://codeload.github.com/jaystack/redux-repatch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248750850,"owners_count":21155795,"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-11-15T17:38:05.920Z","updated_at":"2025-04-13T17:21:29.217Z","avatar_url":"https://github.com/jaystack.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# redux-repatch\n\nRedux enhancer for dispatching reducers\n\n[Repatch](https://www.npmjs.com/package/repatch) is just a simplfied [Redux](https://www.npmjs.com/package/redux), that let you create actions more briefly by dispatching reducers directly. However if you would like to use [redux]((https://www.npmjs.com/package/redux)) with this feature, you need this package.\n\n## Installation\n\n```\nnpm install --save redux-repatch\n```\n\n## How to use\n\n`redux-repatch` provides a store enhancer, that is usable at creating the store. This enhancer ensures that you can use regular actions and repatch actions together:\n\n```javascript\nimport { createStore } from 'redux'\nimport repatch from 'redux-repatch'\n\nconst reducer = (state = 0, action) {\n  switch (action.type) {\n    'SET_TO_VALUE': return action.value\n    default: state\n  }\n}\n\nconst store = createStore(reducer, repatch())\n\nconst setToValue = value =\u003e ({ type: 'SET_TO_VALUE', value }) // redux action\nconst increment = value =\u003e state =\u003e state + value // repatch action\n\nstore.dispatch(setToValue(42)) // 42\nstore.dispatch(increment(10)) // 52\n```\n\n### Use with other enhancers\n\n```javascript\nimport { createStore, applyMiddlewares, compose } from 'redux'\nimport repatch from 'redux-repatch'\n\nconst store = createStore(\n  reducer,\n  compose(\n    applyMiddlewares(myMiddleware),\n    repatch()\n  )\n)\n```\n\n### Use with [redux-thunk](https://www.npmjs.com/package/redux-thunk)\n\nWe cannot use `repatch` actions and `thunk` actions together, because both of actions are defined as functions. Therefore `redux-repatch` provides a builtin `thunk` mechanism.\nThe original [repatch](https://www.npmjs.com/package/repatch) library shares its own `thunk` middleware, that's using is optional. `redux-repatch` does it automatically.\nIn the `repatch` terminology `thunk` reducer is a function, that returns a function. We call this function as the `delegate`.\n\n```javascript\nconst waitAndIncrement = time =\u003e state =\u003e async (dispatch, getState) =\u003e {\n  await sleep(time);\n  dispatch(increment(10))\n}\n\nstore.dispatch(waitAndIncrement(3000))\n```\n\n**However if you would like to use with the original [redux-thunk](https://www.npmjs.com/package/redux-thunk), then you are looking for this: [redux-repatch-creator](https://www.npmjs.com/package/redux-repatch-creator).**\n\n#### Injecting extra argument\n\n```javascript\nimport { createStore } from 'redux'\nimport repatch from 'redux-repatch'\nimport api from './api'\nimport { hashHistory } from 'react-router';\n\nconst store = createStore(reducer, repatch({ api, hashHistory }))\n\nconst updateUser = delta =\u003e state =\u003e\n  async (dispatch, getState, { api, hashHistory }) =\u003e {\n    // ...\n  }\n```\n\n## How it works\n\nThe `repatch` enhancer extends your reducer by handling a special action type, and enhances the `store` with a middleware. This middleware handles the function-like actions. The `thunk` actions will fired in the middleware and they returned value will be returned. The regular `repatch` reducers will be transformed to regular `redux` action objects with the previously mentioned special action type. Then the extended reducer can handle it.\n\n## Import in CommonJS\n\n```javascript\nconst repatch = require('redux-repatch').repatch\n```\n\nor\n\n```javascript\nconst repatch = require('redux-repatch').default\n```\n\n## Bundles\n\n```html\n\u003cscript src=\"https://unpkg.com/redux-repatch/dist/redux-repatch.js\"\u003e\u003c/script\u003e\n```\n\nor the minified bundle:\n\n```html\n\u003cscript src=\"https://unpkg.com/redux-repatch/dist/redux-repatch.min.js\"\u003e\u003c/script\u003e\n```\n\nthen\n\n```javascript\nconst repatch = ReduxRepatch.repatch\n```\n\n---\n\n## License\n\n[MIT](https://spdx.org/licenses/MIT)\n\n## Community\n\n[https://twitter.com/repatchjs](https://twitter.com/repatchjs)\n\n## Developed by\n\n[![JayStack](http://jaystack.com/wp-content/uploads/2017/08/jaystack_logo_transparent_50.png)](http://jaystack.com/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaystack%2Fredux-repatch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjaystack%2Fredux-repatch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaystack%2Fredux-repatch/lists"}