{"id":19872751,"url":"https://github.com/snuffydev/lil-emit","last_synced_at":"2026-05-11T08:47:22.785Z","repository":{"id":116488143,"uuid":"538613739","full_name":"snuffyDev/lil-emit","owner":"snuffyDev","description":"a fully typed event emitter, in 253 bytes","archived":false,"fork":false,"pushed_at":"2022-09-19T17:16:43.000Z","size":54,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-11T16:48:35.771Z","etag":null,"topics":["emitter","event-emitter","events","javascript","micro-library","microlibrary","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/snuffyDev.png","metadata":{"files":{"readme":"README.md","changelog":null,"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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-09-19T17:16:37.000Z","updated_at":"2024-08-02T15:09:45.000Z","dependencies_parsed_at":"2023-03-21T06:44:15.768Z","dependency_job_id":null,"html_url":"https://github.com/snuffyDev/lil-emit","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/snuffyDev%2Flil-emit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snuffyDev%2Flil-emit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snuffyDev%2Flil-emit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snuffyDev%2Flil-emit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/snuffyDev","download_url":"https://codeload.github.com/snuffyDev/lil-emit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241299480,"owners_count":19940483,"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":["emitter","event-emitter","events","javascript","micro-library","microlibrary","typescript"],"created_at":"2024-11-12T16:16:36.593Z","updated_at":"2026-05-11T08:47:22.756Z","avatar_url":"https://github.com/snuffyDev.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lil-emit\n\n\u003e a typed 253 byte event emitter\n\nYes, another tiny event emitter library.\n\n## Install\n\n```sh\nnpm  install --save  lil-emit    // npm\npnpm install --save  lil-emit    // pnpm\nyarn add             lil-emit    // yarn\n```\n\nAnd then use!\n\n```ts\nimport { emitter } from \"lil-emit\";\n\ninterface MyEvents {\n\tclick: [number, number];\n\tupdate: Record\u003cstring, unknown\u003e;\n}\n\n// Create our event handler\nconst ee = emitter\u003cMyEvents\u003e();\n\nconst handler = (data) =\u003e console.log(data);\n\n// Listen for our events to be fired\n// (It's best to avoid using lambda functions for the callback)\nee.on(\"click\", handler);\n\nee.on(\"update\", handler);\n\n// Dispatch our 'click' event\nee.dispatch(\"click\", [32, 425]);\n\n// Stop listening to the 'click' event\nee.off(\"click\", handler);\n// ...or all events\nee.off(\"*\");\n```\n\nThat's all that's needed!\n\n## Guide\n\nThe following guide will reference this event handler function at different points:\n\n```ts\nfunction handler(a, b, c) {\n\tconsole.log(a, b, c);\n}\n```\n\n### `.on(name, callback)`\n\nRegisters an event handler for a given name.\n\n#### Callback\n\nThe callback has the type `(...data) =\u003e void`, where `(...data)` is the data being emitted.\nFor example:\n\n```ts\nee.on(\"test\", handler);\n// or the leaky way\nee.on(\"test\", (a, b, c) =\u003e console.log(a, b, c));\n```\n\n### `.dispatch(name, ...data)`\n\nInvokes all listeners for the given event name.\n\nTo demonstrate, here's how you would dispatch to the example above:\n\n```ts\nee.dispatch(\"test\", \"One\", \"Two\", \"Three!\");\n```\n\n### `.off(name, callback)`\n\nUnregisters an event handler from an event.\n\n```ts\n// This won't work.\nee.off(\"test\", (a, b, c) =\u003e console.log(a, b, c));\n\n// But this will!\nee.off(\"test\", handler);\n```\n\nYou can also do `.off(\"*\")` to remove all event listeners, from all events.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsnuffydev%2Flil-emit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsnuffydev%2Flil-emit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsnuffydev%2Flil-emit/lists"}