{"id":18609467,"url":"https://github.com/soenkekluth/micromitter","last_synced_at":"2025-11-02T19:30:37.050Z","repository":{"id":57296694,"uuid":"100674897","full_name":"soenkekluth/micromitter","owner":"soenkekluth","description":"minimal and performant event emitter / dispatcher","archived":false,"fork":false,"pushed_at":"2023-12-15T11:47:47.000Z","size":88,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-29T09:02:22.169Z","etag":null,"topics":["data","dispatch","dispatcher","emit","emitter","event","eventdriven","handler","on","send","trigger"],"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/soenkekluth.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}},"created_at":"2017-08-18T05:08:46.000Z","updated_at":"2018-03-16T11:47:44.000Z","dependencies_parsed_at":"2024-01-06T13:09:43.069Z","dependency_job_id":"1b0a76f1-d593-4aa7-8b60-2540039871ee","html_url":"https://github.com/soenkekluth/micromitter","commit_stats":{"total_commits":9,"total_committers":2,"mean_commits":4.5,"dds":"0.11111111111111116","last_synced_commit":"e392aecb62a322998e4fd4140bb9d1fd89e02dd9"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soenkekluth%2Fmicromitter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soenkekluth%2Fmicromitter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soenkekluth%2Fmicromitter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soenkekluth%2Fmicromitter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/soenkekluth","download_url":"https://codeload.github.com/soenkekluth/micromitter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239400596,"owners_count":19632049,"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":["data","dispatch","dispatcher","emit","emitter","event","eventdriven","handler","on","send","trigger"],"created_at":"2024-11-07T03:06:10.986Z","updated_at":"2025-11-02T19:30:37.004Z","avatar_url":"https://github.com/soenkekluth.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# micromitter\n\nminimal and performant event emitter / emitter with custom events and payload\n\n## API\n\n\u003c!-- Generated by documentation.js. Update this documentation by updating the source code. --\u003e\n\n#### Table of Contents\n\n-   [constructor](#constructor)\n-   [on](#on)\n-   [off](#off)\n-   [once](#once)\n-   [emit](#emit)\n\n### constructor\n\nCreates an instance of MicroMitter.\n\n**Parameters**\n\n-   `target` **any** the event target\n\n### on\n\nadds an event handler to an event type\n\n**Parameters**\n\n-   `type` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** \n-   `handler` **[function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** \n\n**Examples**\n\n```javascript\nemitter.on('type', (e)=\u003e{\nconsole.log(e);\n});\n```\n\nReturns **MicroMitter** self\n\n### off\n\nremoves either a specific handler or all handlers related to an event type\n\n**Parameters**\n\n-   `type` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** \n-   `handler` **[function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** \n\nReturns **MicroMitter** self\n\n### once\n\nadds an event handler to an event type and immediately removes it after first event call\n\n**Parameters**\n\n-   `type` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** \n-   `handler` **[function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** \n\n**Examples**\n\n```javascript\nemitter.onc('type', (e)=\u003e{\nconsole.log('only once');\n});\n```\n\nReturns **MicroMitter** self\n\n### emit\n\ntriggers an event for a specific type with an optional data object\n\n**Parameters**\n\n-   `type` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** \n-   `data` **any**  (optional, default `{}`)\n\n**Examples**\n\n```javascript\nemitter.off('type', handler);\n```\n\nReturns **MicroMitter** self\n\n## Usage\n\n```js\nimport Emitter from 'micromitter';\n\nconst emitter = new Emitter();\n\nemitter.on('test', (e)=\u003e{\n  console.log(e.type === 'test');\n  console.log(e.foo === 'bar');\n});\n\nemitter.emit('test', {foo:'bar'});\nemitter.off('test');\n\nlet counter = 0;\nemitter.once('oneTime', (e)=\u003e{\n  counter += 1;\n});\n\nemitter.emit('oneTime', {foo:'bar'});\nemitter.emit('oneTime', {foo:'bar'});\nemitter.emit('oneTime', {foo:'bar'});\nemitter.emit('oneTime', {foo:'bar'});\nconsole.log(counter); // 1\n```\n\n### chaining\n\n```js\nemitter\n  .on('type', handler)\n  .emit('type', {foo:'bar'})\n  .off('type', handler);\n```\n\n### use global instance\n\n```js\nimport {emitter} from 'micromitter';\n\nemitter.on('test', (e)=\u003e{\n  console.log(e.type === 'test');\n  console.log(e.foo === 'bar');\n});\n\nemitter.emit('test', {foo:'bar'});\n```\n\n### use decorator\n\n```js\nimport { micromitter } from 'micromitter';\n\n//v1: use es7 decorators\n@micromitter\nclass Tester {\n\tonTest(e){\n\t\tconsole.log(e.type === 'test');\n\t\tconsole.log(e.foo === 'bar');\n\t}\n}\n\n//v2 use the decorator as a function\nmicromitter(Tester);\n\nconst tt = new Tester();\n\ntt.on('test', tt.onTest);\ntt.emit('test', {foo:'bar'});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoenkekluth%2Fmicromitter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoenkekluth%2Fmicromitter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoenkekluth%2Fmicromitter/lists"}