{"id":29284955,"url":"https://github.com/smnandre/stimulus-throttle","last_synced_at":"2026-04-13T20:32:53.043Z","repository":{"id":301818027,"uuid":"1008675404","full_name":"smnandre/stimulus-throttle","owner":"smnandre","description":"A Stimulus package for throttling event handlers","archived":false,"fork":false,"pushed_at":"2025-06-29T01:50:07.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-06T06:19:49.478Z","etag":null,"topics":["antispam","click","debounce","delay","event","stimulus","symfony","throttle","ux"],"latest_commit_sha":null,"homepage":"","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/smnandre.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","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,"zenodo":null},"funding":{"github":"smnandre"}},"created_at":"2025-06-25T23:26:54.000Z","updated_at":"2025-06-29T01:50:10.000Z","dependencies_parsed_at":"2025-06-29T02:45:42.734Z","dependency_job_id":"10cecf62-a546-449c-aeda-0ede08ba20f9","html_url":"https://github.com/smnandre/stimulus-throttle","commit_stats":null,"previous_names":["smnandre/stimulus-throttle"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/smnandre/stimulus-throttle","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smnandre%2Fstimulus-throttle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smnandre%2Fstimulus-throttle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smnandre%2Fstimulus-throttle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smnandre%2Fstimulus-throttle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smnandre","download_url":"https://codeload.github.com/smnandre/stimulus-throttle/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smnandre%2Fstimulus-throttle/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31770720,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-13T20:17:16.280Z","status":"ssl_error","status_checked_at":"2026-04-13T20:17:08.216Z","response_time":93,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["antispam","click","debounce","delay","event","stimulus","symfony","throttle","ux"],"created_at":"2025-07-05T22:02:25.458Z","updated_at":"2026-04-13T20:32:53.023Z","avatar_url":"https://github.com/smnandre.png","language":"TypeScript","funding_links":["https://github.com/sponsors/smnandre"],"categories":[],"sub_categories":[],"readme":"# Stimulus Throttle\n\nA Stimulus controller to throttle events.\n\nThis library provides a `throttle` function and a Stimulus controller that makes it easy to throttle events in your Stimulus applications. You can use it to limit the rate at which a function is called, for example, to prevent a function from being called too frequently on `scroll` or `resize` events.\n\n## Installation\n\n```bash\nnpm install stimulus-throttle\n```\n\n## Usage\n\nThere are two ways to use this library:\n\n### 1. Using `useThrottle` with `throttledListeners`\n\nYou can use the `useThrottle` function to automatically wire up throttled event listeners on your Stimulus controller. To do this, add a static `throttledListeners` object to your controller, where the keys are the event names and the values are the configuration for the throttled listener.\n\n```javascript\n// src/controllers/my-controller.js\nimport { Controller } from '@hotwired/stimulus';\nimport { useThrottle } from 'stimulus-throttle';\n\nexport default class extends Controller {\n  static throttledListeners = {\n    scroll: {\n      method: 'onScroll',\n      throttle: {\n        delay: 100,\n        leading: true,\n        trailing: false,\n      },\n      options: {\n        passive: true,\n      },\n    },\n  };\n\n  connect() {\n    useThrottle(this);\n  }\n\n  onScroll(event) {\n    console.log('scrolling');\n  }\n}\n```\n\n### 2. Using the action modifier syntax\n\nThis library also extends the Stimulus `Application` object to allow you to use a `:throttle` modifier in your action descriptors. To enable this, you need to call `registerThrottleModifiers` on your Stimulus application instance.\n\n```javascript\n// src/application.js\nimport { Application } from '@hotwired/stimulus';\nimport { extendApplicationWithThrottle } from 'stimulus-throttle';\n\nconst application = Application.start();\nextendApplicationWithThrottle(application).registerThrottleModifiers();\nwindow.Stimulus = application;\n```\n\nOnce you've done this, you can use the `:throttle` modifier in your HTML:\n\n```html\n\u003cdiv data-controller=\"my-controller\" data-action=\"scroll-\u003emy-controller#onScroll:throttle:500ms\"\u003e\n  ...\n\u003c/div\u003e\n```\n\nThis will throttle the `onScroll` method to be called at most once every 500 milliseconds.\n\n## API\n\n### `useThrottle(controller)`\n\nAutomatically wires up throttled event listeners on the given Stimulus controller based on the `throttledListeners` static property.\n\n### `useThrottledListeners(controller, listeners)`\n\nWires up the given throttled event listeners on the given Stimulus controller.\n\n### `extendApplicationWithThrottle(application)`\n\nExtends the given Stimulus `Application` object with the ability to use the `:throttle` action modifier.\n\n### `throttle(func, delay, options)`\n\nCreates a throttled function that only invokes `func` at most once per every `delay` milliseconds.\n\n#### `options`\n\n- `leading` (boolean, default: `true`): Whether to invoke the function on the leading edge of the timeout.\n- `trailing` (boolean, default: `true`): Whether to invoke the function on the trailing edge of the timeout.\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/smnandre/stimulus-throttle.\n\n## License\n\nReleased under the [MIT License](LICENSE) by [Simon André](https://github.com/smnandre).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmnandre%2Fstimulus-throttle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmnandre%2Fstimulus-throttle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmnandre%2Fstimulus-throttle/lists"}