{"id":13520452,"url":"https://github.com/psaia/fast-observer","last_synced_at":"2026-01-20T08:38:19.826Z","repository":{"id":53389486,"uuid":"214931215","full_name":"psaia/fast-observer","owner":"psaia","description":"A blazingly fast asynchronous O(1)-capable event dispatcher.","archived":false,"fork":false,"pushed_at":"2022-12-30T18:51:23.000Z","size":38,"stargazers_count":1,"open_issues_count":3,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-08-02T05:23:37.109Z","etag":null,"topics":["event-dispatcher","observer","pubsub","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/fast-observer","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/psaia.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":"2019-10-14T02:31:42.000Z","updated_at":"2019-10-19T20:03:18.000Z","dependencies_parsed_at":"2023-01-31T13:30:23.843Z","dependency_job_id":null,"html_url":"https://github.com/psaia/fast-observer","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/psaia%2Ffast-observer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/psaia%2Ffast-observer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/psaia%2Ffast-observer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/psaia%2Ffast-observer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/psaia","download_url":"https://codeload.github.com/psaia/fast-observer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222670691,"owners_count":17020513,"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":["event-dispatcher","observer","pubsub","typescript"],"created_at":"2024-08-01T05:02:21.125Z","updated_at":"2026-01-20T08:38:19.820Z","avatar_url":"https://github.com/psaia.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# Fast Observer [![Build Status](https://travis-ci.org/psaia/fast-observer.svg?branch=master)](https://travis-ci.org/psaia/fast-observer)\n\n**Does the world need another event dispatcher library?**\n\nMost event dispatchers are O(N). Fast Observer is a lightweight O(1) and\nasynchronous library. This is useful when:\n\n* Performance matters (think mouse events or `requestAnimationFrame()`)\n* You want to work with async/await on publishing\n* You care about file size\n* Convenience features such as namespaces aren't necessary\n* Works in the browser, on the server, and when doing SSR\n\nSome extra tidbits:\n\n* There are zero-dependencies\n* It's well tested with benchmarks @see [Performance](#performance)\n\n### Installation\n\n```\nnpm i --save fast-observer\n```\n\n### Performance\n\nIt's unnecessary to profile the `publishFast` method. It's going to be as fast\nas calling a function directly.\n\nHowever, the O(N) `publish()` method is 14.5 times faster the most popular\nevent dispatcher library called [PubSub-js](https://github.com/mroderick/PubSubJS).\n\n* fast-observer: `Executed 10000000 times in 436 ms`\n* PubSub-js: `Executed 10000000 times in 6341 ms`\n\nSee benchmarks [here](benchmark/). I'd be happy to adjust or add more\nbenchmarks if requested.\n\n### Usage\n\n```typescript\nimport Observer from \"fast-observer\";\n\nconst o = new Observer();\n\n// Define some O(N) subscriptions (nothing new here).\no.subscribe(\"launch ship\", launchTheShip);\no.subscribe(\"launch ship\", launchTheOtherShip);\no.subscribe(\"launch ship\", launchTheOtherShip);\n\nawait o.publish(\"launch ship\"); // Wait for all the ships to launch.\n\n// Define O(1) subscription.\no.subscribeFast(\"engine propulsion\", handlePropulsion);\n\nawait o.publishFast(\"engine propulsion\"); // Similar to publish, is a promise.\n```\n\nThe major caveat of `subscribeFast` is that there can only be one. If there are\nmultiple, they will override each other. There's no magic here -\n`subscribeFast` and `publishFast` is just more of structured way to call a\nfunction.\n\n### API\n\n* `subscribe(eventName: string, (payload?: any) =\u003e void | Promise\u003cvoid\u003e): void`\n* `unsubscribe(eventName: string, fn): void`\n* `subscribeFast(eventName: string, (payload?: any) =\u003e void | Promise\u003cvoid\u003e): void`\n* `unsubscribeFast(eventName: string): void`\n* `publish(eventName: string): Promise\u003cvoid\u003e`\n* `publishFast(eventName: string): Promise\u003cvoid\u003e`\n\n### Development\n\n1. `npm i \u0026\u0026 tsc -w` to install dev-deps \u0026 watch\n2. `npm test` to run tests\n\n## License\n\nApache Version 2.0\n\nSee [LICENSE](https://github.com/psaia/fast-observer/blob/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpsaia%2Ffast-observer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpsaia%2Ffast-observer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpsaia%2Ffast-observer/lists"}