{"id":15379143,"url":"https://github.com/hmans/eventery","last_synced_at":"2025-04-15T17:31:18.338Z","repository":{"id":65707247,"uuid":"586628930","full_name":"hmans/eventery","owner":"hmans","description":"Super-lightweight event class implementation. 🚀","archived":false,"fork":false,"pushed_at":"2023-07-16T10:01:53.000Z","size":88,"stargazers_count":21,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-28T23:05:06.233Z","etag":null,"topics":["events","gamedev","javascript","pubsub","typescript"],"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/hmans.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["hmans"]}},"created_at":"2023-01-08T19:46:44.000Z","updated_at":"2025-02-25T16:57:16.000Z","dependencies_parsed_at":"2023-02-13T00:15:33.152Z","dependency_job_id":null,"html_url":"https://github.com/hmans/eventery","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hmans%2Feventery","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hmans%2Feventery/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hmans%2Feventery/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hmans%2Feventery/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hmans","download_url":"https://codeload.github.com/hmans/eventery/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249118596,"owners_count":21215588,"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":["events","gamedev","javascript","pubsub","typescript"],"created_at":"2024-10-01T14:18:25.558Z","updated_at":"2025-04-15T17:31:18.316Z","avatar_url":"https://github.com/hmans.png","language":"TypeScript","funding_links":["https://github.com/sponsors/hmans"],"categories":[],"sub_categories":[],"readme":"# Eventery\n\nA tiny publish-subscribe library for JavaScript, specifically tailored for use in games:\n\n- Instantiate event objects with typed arguments.\n- Supports events with zero, one, or multiple typed arguments; no need to create extra payload objects for events with multiple arguments.\n- Events support synchronous and asynchronous publishing.\n- Events provide their own events that notify about new or removed subscribers.\n- Zero dependencies!\n\n## Overview\n\n```ts\nimport { Event } from \"eventery\";\n\n/* Create an event. You can pass a type to describe the event's\npayload arguments. These may optionally be named, like here: */\nconst event = new Event\u003c[deltaTime: number]\u003e();\n\n/* Create a callback and add it as a subscriber. */\nfunction callback(dt: number) {\n  console.log(dt);\n}\n\nevent.subscribe(callback);\n\n/* Publish an event. The subscribers will be invoked synchronously. */\nevent.publish(123);\n\n/* Unsubscribe the callback. */\nevent.unsubscribe(callback);\n\n/* Clear all subscribers. */\nevent.clear();\n```\n\n### With React (and similar)\n\nThe `subscribe` function returns a function that will unsubscribe the callback when called. This is handy for use with React's `useEffect` hook:\n\n```ts\nuseEffect(() =\u003e event.subscribe(listener), []);\n```\n\n## Event Payloads\n\nEvent payloads are typed using TypeScript's tuple syntax. For example, the following event has a payload with two arguments:\n\n```ts\nconst event = new Event\u003c[number, number]\u003e();\n```\n\nThese arguments may optionally be named:\n\n```ts\nconst event = new Event\u003c[x: number, y: number]\u003e();\n```\n\nPayload arguments can be made optional:\n\n```ts\nconst event = new Event\u003c[dt: number, context?: string]\u003e();\n```\n\nThey can use the `...` syntax to indicate that the argument is a rest parameter:\n\n```ts\nconst event = new Event\u003c[context: string, ...deltas: number[]]\u003e();\n```\n\n## Subscribe/Unsubscribe Notification Events\n\n`Event` provides two events that notify about new or removed subscribers:\n\n```ts\nimport { Event } from \"eventery\";\n\nconst event = new Event\u003c[number]\u003e();\n\n/* Subscribe to the event that notifies about new subscribers. */\nevent.onSubscribed.subscribe((callback) =\u003e {\n  console.log(\"New subscriber:\", callback);\n});\n\n/* Subscribe to the event that notifies about removed subscribers. */\nevent.onUnsubscribed.subscribe((callback) =\u003e {\n  console.log(\"Removed subscriber:\", callback);\n});\n\nconst callback = function (dt: number) {\n  console.log(dt);\n};\n\n/* Subscribe a callback. This will trigger all `onSubscribe` callbacks. */\nevent.subscribe(callback);\n\n/* Unsubscribe the callback. This will trigger all `onUnsubscribe` callbacks. */\nevent.unsubscribe(callback);\n```\n\n## License\n\n```\nCopyright (c) 2023 Hendrik Mans\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n\"Software\"), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\nLIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\nOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\nWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhmans%2Feventery","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhmans%2Feventery","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhmans%2Feventery/lists"}