{"id":19345190,"url":"https://github.com/gaya/redux-listeners","last_synced_at":"2025-04-23T04:36:24.729Z","repository":{"id":52158688,"uuid":"112736763","full_name":"Gaya/redux-listeners","owner":"Gaya","description":"Redux middleware which allows listening in on and handling of dispatched actions","archived":false,"fork":false,"pushed_at":"2022-12-02T21:51:30.000Z","size":143,"stargazers_count":10,"open_issues_count":6,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T08:22:05.756Z","etag":null,"topics":["dispatch","listeners","middleware","redux","redux-middleware","redux-store"],"latest_commit_sha":null,"homepage":"","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/Gaya.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-12-01T12:18:14.000Z","updated_at":"2020-11-19T09:02:18.000Z","dependencies_parsed_at":"2023-01-22T23:00:48.168Z","dependency_job_id":null,"html_url":"https://github.com/Gaya/redux-listeners","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gaya%2Fredux-listeners","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gaya%2Fredux-listeners/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gaya%2Fredux-listeners/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gaya%2Fredux-listeners/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Gaya","download_url":"https://codeload.github.com/Gaya/redux-listeners/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250372462,"owners_count":21419719,"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":["dispatch","listeners","middleware","redux","redux-middleware","redux-store"],"created_at":"2024-11-10T04:05:15.510Z","updated_at":"2025-04-23T04:36:24.372Z","avatar_url":"https://github.com/Gaya.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Redux Listeners\n\n[![npm version](https://img.shields.io/npm/v/redux-listeners.svg)](https://www.npmjs.com/package/redux-listeners)\n[![Build Status](https://travis-ci.org/Gaya/redux-listeners.svg?branch=master)](https://travis-ci.org/Gaya/redux-listeners)\n\nRedux middleware which allows listening in on and handling of dispatched actions\n\n```\nnpm install --save redux-listeners\n```\n\n## Who needs this?\n\nFor those who want to listen in on actions dispatched to the Redux store.\n\nIncludes the store's dispatch method to dispatch new actions after a listener is fired.\n\nMuch like `redux-saga`, but a way more toned down implementation which also allows for `async/await`.\n\n## Example\n\n```js\nimport { createStore, applyMiddleware } from 'redux';\nimport { createMiddleware } from 'redux-listeners';\n\n// import your reducers\nimport rootReducer from './reducers'; \n\n// create action middleware\nconst listenMiddleware = createMiddleware();\n\nconst store = createStore(\n  rootReducer,\n  applyMiddleware(listenMiddleware),\n);\n\n// register listeners to middleware\nlistenMiddleware.addListener('INIT', (dispatch) =\u003e {\n  dispatch({ type: 'FETCH_DATA' });\n});\n\nlistenMiddleware.addListener('FETCH_DATA', (dispatch) =\u003e {\n  fetch('/some-data')\n    .then(response =\u003e response.text())\n    .then(text =\u003e dispatch({ type: 'FETCH_DATA_SUCCESS', payload: text }))\n    .catch(err =\u003e dispatch({ type: 'FETCH_DATA_FAILED', payload: err }));\n});\n\nlistenMiddleware.addListener('FETCH_DATA_FAILED', (dispatch, action) =\u003e {\n  // display the error in console by reading the action\n  console.error(action.payload.message);\n});\n\nstore.dispatch({ type: 'INIT' });\n  // This will fire the 'INIT' listener\n  // Which in turn dispatches the 'FETCH_DATA' action\n  // 'FETCH_DATA' listener is fired and asynchronously dispatches response actions\n```\n\n## Usage\n\n### `createMiddleware()`\nCreates the middleware you can pass into Redux.\n\n*Returns* `middleware: Function`\n\n### `middleware.addListener(actionType, listener)`\nBinds `listener` function for each `actionType` dispatched to the redux store.\n\n- `actionType: String | Array` The action type or an array of action types to match.\n- `listener: Function(dispatch, action)` The function which will be called when an action of specified types is dispatched. Will receive `dispatch` and `action` as arguments to dispatch new actions and read the action being dispatched.\n\n### `middleware.addListeners(actionType, ...listeners)`\n\n- `actionType: String | Array` Same as `.addListener`.\n- `...listeners: Array\u003cFunction(dispatch, action)\u003e` Same as `.addListener`, but now a list of multiple listeners.\n\n## License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgaya%2Fredux-listeners","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgaya%2Fredux-listeners","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgaya%2Fredux-listeners/lists"}