{"id":19417980,"url":"https://github.com/americanexpress/redux-lifesaver","last_synced_at":"2025-04-24T13:34:14.534Z","repository":{"id":21936022,"uuid":"93082319","full_name":"americanexpress/redux-lifesaver","owner":"americanexpress","description":"✨ redux-lifesaver is a middleware that keeps track of how many times actions of the same type are dispatched within a given period.","archived":false,"fork":false,"pushed_at":"2024-06-18T11:56:11.000Z","size":521,"stargazers_count":22,"open_issues_count":1,"forks_count":5,"subscribers_count":16,"default_branch":"main","last_synced_at":"2025-04-19T07:49:35.647Z","etag":null,"topics":["limiter","middleware","one-app","react","redux-lifesaver","throttling"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/americanexpress.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-01T17:25:21.000Z","updated_at":"2024-02-08T19:55:21.000Z","dependencies_parsed_at":"2024-01-03T18:30:04.894Z","dependency_job_id":"e518f1c0-462c-4d66-a1b8-e3a9008ee8ac","html_url":"https://github.com/americanexpress/redux-lifesaver","commit_stats":{"total_commits":63,"total_committers":13,"mean_commits":4.846153846153846,"dds":0.6666666666666667,"last_synced_commit":"f84df6ee4c9c39d856991cc34facf21d9f968220"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/americanexpress%2Fredux-lifesaver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/americanexpress%2Fredux-lifesaver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/americanexpress%2Fredux-lifesaver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/americanexpress%2Fredux-lifesaver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/americanexpress","download_url":"https://codeload.github.com/americanexpress/redux-lifesaver/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250636519,"owners_count":21463096,"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":["limiter","middleware","one-app","react","redux-lifesaver","throttling"],"created_at":"2024-11-10T13:12:17.152Z","updated_at":"2025-04-24T13:34:14.178Z","avatar_url":"https://github.com/americanexpress.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# redux-lifesaver\n\n[![npm version](https://badge.fury.io/js/redux-lifesaver.svg)](https://badge.fury.io/js/redux-lifesaver)\n![Health Check](https://github.com/americanexpress/redux-lifesaver/workflows/Health%20Check/badge.svg)\n\n\u003e Want to get paid for your contributions to `redux-lifesaver`?\n\u003e Send your resume to oneamex.careers@aexp.com\n\n`lifesaver` is a middleware that keeps track of how many times actions of the\nsame type are dispatched within a given period. If a single action type is\ndispatched more times than the allowed amount within a given period, subsequent\ndispatches of that action type will be blocked from the reducer for the same\nperiod. At the end of the period, the most recently attempted dispatch of that\naction type will go through.\n\n```js\nimport { createStore, applyMiddleware } from 'redux';\nimport lifesaver from 'redux-lifesaver';\nimport rootReducer from './reducers/index';\n\n// Note: this API requires redux@\u003e=3.1.0\nconst store = createStore(\n  rootReducer,\n  applyMiddleware(lifesaver())\n);\n```\n\n`lifesaver` accepts a configuration object with four optional properties,\n`dispatchLimit`, `limitDuration`, `actionTypes`, and `actionCreator`. Where\n`dispatchLimit` is the number of dispatches allowed for a single action type in\na given period, and `limitDuration` is the duration of that period in\nmilliseconds. `dispatchLimit` defaults to `10`, and `limitDuration` to `100`.\n`actionTypes` should be an object with keys that are action types that you want\nto have a special configuration. The values are objects that contain\n`dispatchLimit` and/or `limitDuration`. For instance, if you had a\n`VERY_SPECIAL_ACTION` that shouldn't be limited at all, your configuration\nobject may look like this:\n\n```js\nimport { VERY_SPECIAL_ACTION } from './path/to/my/duck';\n\nconst lifesaverConfig = {\n  actionTypes: {\n    [VERY_SPECIAL_ACTION]: {\n      limitDuration: 0,\n    },\n  },\n};\n```\n\n`actionCreator` will replace the action creator that `lifesaver` dispatches when\nit throttles an action. This can be handy if you are using thunks and want to do\nsomething outside your reducer when an action is throttled. For instance:\n\n```js\nimport { actionThrottled } from 'redux-lifesaver';\nimport { reportError, REPORT_ERROR } from './some/path';\n\nconst actionCreator = (action) =\u003e (dispatch) =\u003e\n  dispatch(reportError({\n    message: `Over exuberant dispatching of ${action.type}, throttling`,\n    data: action,\n  })).then(() =\u003e dispatch(actionThrottled(action)));\n\nconst lifesaverConfig = {\n  actionCreator,\n  actionTypes: {\n    [REPORT_ERROR]: {\n      limitDuration: 0,\n    },\n  },\n};\n```\n\n## Contributing\nWe welcome Your interest in the American Express Open Source Community on Github.\nAny Contributor to any Open Source Project managed by the American Express Open\nSource Community must accept and sign an Agreement indicating agreement to the\nterms below. Except for the rights granted in this Agreement to American Express\nand to recipients of software distributed by American Express, You reserve all\nright, title, and interest, if any, in and to Your Contributions. Please [fill\nout the Agreement](https://cla-assistant.io/americanexpress/).\n\n## License\nAny contributions made under this project will be governed by the [Apache License\n2.0](https://github.com/americanexpress/redux-lifesaver/blob/main/LICENSE.txt).\n\n## Code of Conduct\nThis project adheres to the [American Express Community Guidelines](https://github.com/americanexpress/redux-lifesaver/wiki/Code-of-Conduct).\nBy participating, you are expected to honor these guidelines.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famericanexpress%2Fredux-lifesaver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famericanexpress%2Fredux-lifesaver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famericanexpress%2Fredux-lifesaver/lists"}