{"id":21531917,"url":"https://github.com/matrixai/js-events","last_synced_at":"2026-03-07T12:35:40.588Z","repository":{"id":191105033,"uuid":"683714422","full_name":"MatrixAI/js-events","owner":"MatrixAI","description":"Events for push-flow abstractions","archived":false,"fork":false,"pushed_at":"2025-05-29T05:29:55.000Z","size":928,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"staging","last_synced_at":"2025-11-23T10:09:00.957Z","etag":null,"topics":["events"],"latest_commit_sha":null,"homepage":"https://polykey.com","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MatrixAI.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-08-27T13:25:51.000Z","updated_at":"2025-05-29T05:24:31.000Z","dependencies_parsed_at":"2024-05-14T09:54:47.556Z","dependency_job_id":"ea6c2204-cb6a-43ca-9cb4-f2e8b87b0e02","html_url":"https://github.com/MatrixAI/js-events","commit_stats":null,"previous_names":["matrixai/js-events"],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/MatrixAI/js-events","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatrixAI%2Fjs-events","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatrixAI%2Fjs-events/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatrixAI%2Fjs-events/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatrixAI%2Fjs-events/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MatrixAI","download_url":"https://codeload.github.com/MatrixAI/js-events/tar.gz/refs/heads/staging","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatrixAI%2Fjs-events/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30213192,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-07T12:15:00.571Z","status":"ssl_error","status_checked_at":"2026-03-07T12:15:00.217Z","response_time":53,"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":["events"],"created_at":"2024-11-24T02:18:11.598Z","updated_at":"2026-03-07T12:35:40.499Z","avatar_url":"https://github.com/MatrixAI.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# js-events\n\nEvents for push-flow abstractions.\n\n### `AbstractEvent`\n\n```ts\n// For when you just want a regular event without `detail`\n// Note that the `detail` type is `undefined`, unlike `CustomEvent`\nclass Event1 extends AbstractEvent {}\n\n// For when you want a event with `detail`\nclass Event2 extends AbstractEvent\u003cstring\u003e {}\n\n// Allow caller to customise the `detail` type\n// Note that the `detail` type is `unknown`\n// This would be rare to use, prefer `Event4`\nclass Event3\u003cT\u003e extends AbstractEvent\u003cT\u003e {}\n\n// Allow caller to customise the `detail` type\nclass Event4\u003cT extends Event = Event\u003e extends AbstractEvent\u003cT\u003e {}\n\n// When you need to customise the constructor signature\nclass Event5 extends AbstractEvent\u003cstring\u003e {\n  constructor(options: EventInit \u0026 { detail: string }) {\n    // Make sure you pass `arguments`!\n    super(Event5.name, options, arguments);\n  }\n}\n```\n\nWhen redispatching an event, you must call `event.clone()`. The same instance\ncannot be redispatched. When the event is cloned, all constructor parameters are\nshallow-copied.\n\n### `Evented`\n\nWe combine `Evented` with `AbstractEvent` to gain type-safety and convenience of\nthe wildcard any handler.\n\n```ts\nclass EventCustom extends AbstractEvent {}\n\ninterface X extends Evented {}\n@Evented()\nclass X {}\n\nconst x = new X();\n\n// Handle specific event, use the `name` property as the key\nx.addEventListener(EventCustom.name, (e) =\u003e {\n  console.log(e as EventCustom);\n});\n\n// Handle unhandled events\nx.addEventListener(EventDefault.name, (e) =\u003e {\n  // This is the wrapped underlying event\n  console.log((e as EventDefault).detail);\n});\n\n// Handle all events\nx.addEventListener(EventAll.name, (e) =\u003e {\n  // This is the wrapped underlying event\n  console.log((e as EventAny).detail);\n});\n```\n\nYou can use this style to handle relevant events to perform side-effects, as\nwell as propagate upwards irrelevant events.\n\nNote that some side-effects you perform may trigger an infinite loop by causing\nsomething to emit the specific event type that you are handling. In these cases\nyou should specialise handling of those events with a `once: true` option, so\nthat they are only handled once.\n\n```ts\nx.addEventListener(\n  EventInfinite.name,\n  (e) =\u003e {\n    console.log(e as EventInfinite);\n    performActionThatMayTriggerEventInfinite();\n  },\n  { once: true },\n);\n```\n\nThis will terminate the infinite loop on the first time it gets handled.\n\nTherefore it is a good idea to always be as specific with your event types as\npossible.\n\nFurthermore any unhandled rejections or uncaught exceptions will be redispatched\nas `EventError`. However if there's no listener registered for this, it will be\nthrown up as an uncaught exception.\n\n## Installation\n\n```sh\nnpm install --save @matrixai/events\n```\n\n## Development\n\nRun `nix develop`, and once you're inside, you can use:\n\n```sh\n# install (or reinstall packages from package.json)\nnpm install\n# build the dist\nnpm run build\n# run the repl (this allows you to import from ./src)\nnpm run ts-node\n# run the tests\nnpm run test\n# lint the source code\nnpm run lint\n# automatically fix the source\nnpm run lintfix\n```\n\n### Docs Generation\n\n```sh\nnpm run docs\n```\n\nSee the docs at: https://matrixai.github.io/js-events/\n\n### Publishing\n\nPublishing is handled automatically by the staging pipeline.\n\nPrerelease:\n\n```sh\n# npm login\nnpm version prepatch --preid alpha # premajor/preminor/prepatch\ngit push --follow-tags\n```\n\nRelease:\n\n```sh\n# npm login\nnpm version patch # major/minor/patch\ngit push --follow-tags\n```\n\nManually:\n\n```sh\n# npm login\nnpm version patch # major/minor/patch\nnpm run build\nnpm publish --access public\ngit push\ngit push --tags\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatrixai%2Fjs-events","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatrixai%2Fjs-events","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatrixai%2Fjs-events/lists"}