{"id":21747470,"url":"https://github.com/charlespascoe/typed-event","last_synced_at":"2026-05-16T09:35:22.355Z","repository":{"id":57383347,"uuid":"102726579","full_name":"charlespascoe/typed-event","owner":"charlespascoe","description":"Strongly-Typed Events for TypeScript","archived":false,"fork":false,"pushed_at":"2017-12-08T12:51:31.000Z","size":32,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"develop","last_synced_at":"2026-01-30T09:24:59.529Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/charlespascoe.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":"2017-09-07T10:59:29.000Z","updated_at":"2017-09-09T09:10:28.000Z","dependencies_parsed_at":"2022-09-26T16:50:22.745Z","dependency_job_id":null,"html_url":"https://github.com/charlespascoe/typed-event","commit_stats":null,"previous_names":["cpascoe95/typed-event"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/charlespascoe/typed-event","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charlespascoe%2Ftyped-event","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charlespascoe%2Ftyped-event/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charlespascoe%2Ftyped-event/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charlespascoe%2Ftyped-event/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/charlespascoe","download_url":"https://codeload.github.com/charlespascoe/typed-event/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charlespascoe%2Ftyped-event/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33097012,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-16T04:41:52.686Z","status":"ssl_error","status_checked_at":"2026-05-16T04:41:52.009Z","response_time":115,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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":[],"created_at":"2024-11-26T08:09:14.929Z","updated_at":"2026-05-16T09:35:22.336Z","avatar_url":"https://github.com/charlespascoe.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Strongly-Typed Events for TypeScript\n\nBrings C#-like events to TypeScript, as classic JavaScript events mechanisms like EventEmitter aren't type safe.\n\nThe events optionally support weak-referenced handlers, which can help prevent memory leaks by allowing the garbage collector to delete objects when there's only an event referencing it.\n\n# Installation\n\n`$ npm install --save typed-event`\n\n# Usage\n\nA simple event on a class:\n\n```typescript\n\nimport { Event } from 'typed-event';\n\nclass Foo {\n  public readonly barEvent: Event = new Event();\n\n  public bar() {\n    this.barEvent.emit();\n  }\n}\n\nlet foo = new Foo();\n\nfoo.barEvent.register(() =\u003e console.log('bar!'));\n\nfoo.bar();\n\n// Outputs:\n// bar!\n```\n\nYou can also specify an event that has an argument:\n\n```typescript\nimport { EventWithArgs } from 'typed-event';\n\nclass FooArg {\n  public readonly barEvent: EventWithArgs\u003cstring\u003e = new EventWithArgs\u003cstring\u003e();\n\n  public bar(msg: string) {\n    this.barEvent.emit(msg);\n  }\n}\n\nlet fooArg = new FooArg();\n\nfooArg.barEvent.register((msg: string) =\u003e console.log(msg));\n\nfooArg.bar('Hello, world!');\n\n// Outputs:\n// Hello, world!\n```\n\nYou can also register event handlers that only get run once:\n\n```typescript\nlet foo = new Foo();\n\nfoo.barEvent.once(() =\u003e console.log('This will only get run once!'))\n\nfoo.bar();\nfoo.bar();\nfoo.bar();\n```\n\nTo unregister an event, pass the event handler function into `unregister`. If you're using lambdas, `register` and `once` will return the handler.\n\n```typescript\nlet foo = new Foo();\n\nlet handler = foo.barEvent.register(() =\u003e console.log('Handler!'));\n\nfoo.bar();\n\nfoo.barEvent.unregister(handler);\n\nfoo.bar();\n```\n\n## Weak Referencing\n\nEvents currently default to [weakly referencing](https://en.wikipedia.org/wiki/Weak_reference) event handlers if the platform supports it, otherwise falling back to strong referencing. This allows the handlers and objects associated with them to be removed by the garbage collector if there are no strong references to them. However, you may want strong referencing for self-contained event handlers such as loggers. To disable weak referencing, pass in `false` to the event handler constructor:\n\n```typescript\nEvent barEvent: Event = new Event(false);\nEvent bargEvent: EventWithArgs\u003cT\u003e = new EventWithArgs\u003cT\u003e(false);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcharlespascoe%2Ftyped-event","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcharlespascoe%2Ftyped-event","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcharlespascoe%2Ftyped-event/lists"}