{"id":15679764,"url":"https://github.com/aduth/refx","last_synced_at":"2025-07-22T21:36:25.824Z","repository":{"id":49576664,"uuid":"76615152","full_name":"aduth/refx","owner":"aduth","description":"Redux middleware for triggering side effects","archived":false,"fork":false,"pushed_at":"2025-02-19T15:38:43.000Z","size":606,"stargazers_count":11,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-28T07:22:21.390Z","etag":null,"topics":["middleware","redux","side-effects"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aduth.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"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,"publiccode":null,"codemeta":null}},"created_at":"2016-12-16T02:45:02.000Z","updated_at":"2024-10-05T14:43:38.000Z","dependencies_parsed_at":"2024-06-23T00:58:16.746Z","dependency_job_id":null,"html_url":"https://github.com/aduth/refx","commit_stats":{"total_commits":43,"total_committers":3,"mean_commits":"14.333333333333334","dds":0.2093023255813954,"last_synced_commit":"00b6ea6e42338658dcbb3a7f3167775e09f93178"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aduth%2Frefx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aduth%2Frefx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aduth%2Frefx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aduth%2Frefx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aduth","download_url":"https://codeload.github.com/aduth/refx/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248942433,"owners_count":21186946,"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":["middleware","redux","side-effects"],"created_at":"2024-10-03T16:35:45.011Z","updated_at":"2025-04-14T18:54:33.979Z","avatar_url":"https://github.com/aduth.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# refx\n\n_refx_ is a Redux middleware for triggering side effects.\n\nIn Redux, actions are dispatched synchronously. However, in many real-world applications you'll find yourself needing to fetch data from an API asynchronously. Other popular solutions in the ecosystem like [redux-thunk](https://github.com/gaearon/redux-thunk) augment your [action creators](http://redux.js.org/docs/Glossary.html#action-creator) and empower them to dispatch whenever and as often as necessary.\n\n_refx_ takes a different approach; like in a plain Redux store, your actions must always be plain objects. To perform side effects, you instead define effects as an object of action type keys whose values are functions which trigger additional effects. Those side effects have access to both the dispatched action and the store instance meaning they — like thunks — can dispatch whenenever and as often as necessary.\n\nWhy is this any better than the other solutions? It separates actions which affect change in your store from the side effects that occur as a mere consequence of said actions. Actions as plain objects are also easier to extend, enabling you to compose action creators in ways that would otherwise be not possible with thunks.\n\nHeavily optimized, it weighs in at a paltry 241 bytes gzipped and minified. Browser support follows Redux, including all Node.js versions and browsers Internet Explorer 9 or newer. If you need to support Internet Explorer 8, add [`es5-shim`](https://github.com/es-shims/es5-shim) to your page prior to loading _refx_.\n\n## Example\n\n_refx_ is a function returning a [middleware](http://redux.js.org/docs/advanced/Middleware.html), meaning it should be applied during the creation of your Redux store. The function accepts an object or array of objects mapping action types to the side effect handlers.\n\n```js\nimport { createStore, applyMiddleware } from 'redux';\nimport refx from 'refx';\nimport todos from './reducer';\n\nconst effects = {\n\tTODO_ADD: ( action, store ) =\u003e {\n\t\tfetch( `/todos`, {\n\t\t\tmethod: 'POST',\n\t\t\tbody: action.todo\n\t\t} ).then( ( response ) =\u003e {\n\t\t\treturn response.json();\n\t\t} ).then( ( todo ) =\u003e {\n\t\t\tstore.dispatch( {\n\t\t\t\ttype: 'TODO_SAVED',\n\t\t\t\ttodo\n\t\t\t} );\n\t\t} );\n\t}\n};\n\nexport default function configureStore() {\n\treturn createStore( todos, [], applyMiddleware( refx( effects ) ) );\n}\n```\n\nIn this example, we've defined a handler to observe the `TODO_ADD` action. When this action is dispatched, we'll trigger a request to our API to save the todo. Once complete, we'll then dispatch another action to the store to indicate that the request has succeeded.\n\n## Usage\n\nDownload [`refx.min.js` from unpkg](https://unpkg.com/refx/dist/refx.min.js) and include in your application, or install from `npm`.\n\n```\nnpm install refx\n```\n\nIf included as a script in the browser, it is made available in the global context as `refx`.\n\nThe _refx_ function accepts an object of action type keys or an array of objects.\n\nEach effect handler is a function or array of functions, each accepting the dispatched action object and store instance. The effect handler can return an action object to be dispatched.\n\nThe returned middleware includes a reference to the normalized `effects` object (where each value is an array of effects), in case you need to manipulate effects after initialization.\n\n## License\n\nCopyright (c) 2018 Andrew Duthie\n\n[The MIT License (MIT)](https://opensource.org/licenses/MIT)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faduth%2Frefx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faduth%2Frefx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faduth%2Frefx/lists"}