{"id":15511688,"url":"https://github.com/daun/stimulants","last_synced_at":"2025-06-25T18:31:52.623Z","repository":{"id":57370967,"uuid":"283452916","full_name":"daun/stimulants","owner":"daun","description":"Basic building blocks for Stimulus controllers","archived":false,"fork":false,"pushed_at":"2022-04-26T17:34:26.000Z","size":17,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-06-02T22:14:48.304Z","etag":null,"topics":["hotwired","javascript","mixins","stimulus"],"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/daun.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":"2020-07-29T09:14:47.000Z","updated_at":"2023-07-27T13:34:43.000Z","dependencies_parsed_at":"2022-09-09T01:12:43.248Z","dependency_job_id":null,"html_url":"https://github.com/daun/stimulants","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/daun/stimulants","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daun%2Fstimulants","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daun%2Fstimulants/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daun%2Fstimulants/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daun%2Fstimulants/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/daun","download_url":"https://codeload.github.com/daun/stimulants/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daun%2Fstimulants/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261930740,"owners_count":23231945,"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":["hotwired","javascript","mixins","stimulus"],"created_at":"2024-10-02T09:53:10.784Z","updated_at":"2025-06-25T18:31:52.579Z","avatar_url":"https://github.com/daun.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# Stimulants 🍸\n\n[![NPM version](https://img.shields.io/npm/v/stimulants?color=97aab4)](https://www.npmjs.com/package/stimulants)\n[![GitHub license](https://img.shields.io/github/license/daun/stimulants?color=97aab4)](./LICENSE)\n[![Bundle size](https://img.shields.io/bundlephobia/minzip/stimulants?color=97aab4\u0026label=size)](https://bundlephobia.com/result?p=stimulants)\n\u003c!-- [![GitHub (pre-)release date](https://img.shields.io/github/release-date-pre/daun/stimulants?label=updated)](https://github.com/daun/stimulants/releases) --\u003e\n\nBasic building blocks for Stimulus controllers.\n\nExtend your controllers by adding and combining modular behaviors. **Work in progress**.\n\n## Installation\n\n```bash\nnpm install stimulants\n```\n\n## Usage\n\nAdd the desired behaviors by applying the use functions on your controllers.\n\n```js\nimport { Controller } from 'stimulus'\nimport { useDebug, useEvents } from 'stimulants'\n\nexport default class extends Controller {\n  constructor(...args) {\n    super(...args)\n    useDebug(this)\n    useEvents(this)\n  }\n\n  connect() {\n    this.debug('...')\n  }\n\n  disconnect() {\n    this.emit('custom-event', {})\n  }\n}\n```\n\n## Behaviors\n\n### useDebug\n\nConsole log helper prefixed with the controller name, disabled in production.\n\n```js\nthis.debug('Lorem ipsum dolor sit amet', 42)\n// console.log output in development:\n// [test-controller] Lorem ipsum dolor sit amet  42\n```\n\n### useEvents\n\nEmit and receive custom DOM events. Useful for communicating between\nparent-child controllers.\n\nThe emitting controller's identifier is prepended to the event type for\nnamespacing: `type` → `controller:type`\n\nAll event listeners are removed when the controller is disconnected.\n\n```js\n// Dispatch event from 'child' controller\n\nthis.emit('custom-event', { lorem: 'ipsum' })\n\n// Listen for event in 'parent' controller\n\nthis.on('child:custom-event', ({ detail }) =\u003e {\n  console.log(detail)\n})\n\nthis.once('child:custom-event', () =\u003e {\n  console.log('I will only run once')\n})\n```\n\n### useInstances\n\nTrack and access all connected instances of the current controller. Useful for\nsibling communication between controllers.\n\nReturns an array of instantiated controller objects. If you need to access the\ncontrollers' DOM elements, map over the array to pluck the `element` property.\n\n```js\n// Get all connected instances\nthis.instances.forEach(controller =\u003e {\n  console.log(controller.identifier)\n})\n\n// Get array of DOM elements\nconst elements = this.instances.map(controller =\u003e controller.element)\n```\n\n### useAnnouncements\n\nAdds a live region for announcing updates to screen reader users. Great for\npartial page visits and dynamically loaded content.\n\n```js\n// Announce first heading inside newly fetched content\nconst heading = document.querySelector('h1, h2')\nthis.announce(heading.textContent || document.title)\n```\n\n## License\n\n[MIT](https://opensource.org/licenses/MIT)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaun%2Fstimulants","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaun%2Fstimulants","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaun%2Fstimulants/lists"}