{"id":21543081,"url":"https://github.com/yongwangd/rx-event","last_synced_at":"2026-05-21T07:40:55.569Z","repository":{"id":126866775,"uuid":"120331670","full_name":"yongwangd/rx-event","owner":"yongwangd","description":"A very simple but powerful event pub/sub package with only 6 lines of source code.","archived":false,"fork":false,"pushed_at":"2018-02-05T18:21:58.000Z","size":43,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-24T08:43:49.027Z","etag":null,"topics":["eventemitter","eventemitter4","javascript","node","nodejs","pubsub","rxjs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/yongwangd.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":"2018-02-05T16:35:53.000Z","updated_at":"2018-04-18T09:54:53.000Z","dependencies_parsed_at":"2023-06-18T12:02:37.325Z","dependency_job_id":null,"html_url":"https://github.com/yongwangd/rx-event","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/yongwangd%2Frx-event","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yongwangd%2Frx-event/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yongwangd%2Frx-event/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yongwangd%2Frx-event/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yongwangd","download_url":"https://codeload.github.com/yongwangd/rx-event/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244130283,"owners_count":20402753,"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":["eventemitter","eventemitter4","javascript","node","nodejs","pubsub","rxjs"],"created_at":"2024-11-24T05:12:49.198Z","updated_at":"2026-05-21T07:40:55.536Z","avatar_url":"https://github.com/yongwangd.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rx-event\n\nA very simple but powerful event pub/sub package with only 6 lines of source code. This package is built on top of `Rxjs`, so all the awesome `Rxjs` operators like `filter`, `debounce` are available. I find it much simpler to use than `EventEmitter`\n\n### Installing\n\n```\nnpm i rx-event --save\n```\n\nOr if you use `yarn`\n\n```\nyarn add rx-event\n```\n\n## How to use\n\nThis package comes with 3 named exports and 1 default export\n\n`emitEvent` : emit an event with optional payload\n\n```js\nemitEvent('user-request', 'john');\nemitEvent('user-fetched', { name: 'John Doe', age: 26 });\nemitEvent('user-fetched', { name: 'Jack Davis', age: 40 });\nemitEvent('scroll-down');\n```\n\n`eventPayloadOfType$`: filter the `event$` to only get the payload of a specific event type\n\n```js\neventPayloadOfType$('user-fetched');\n// {name: 'John Doe', age: 26} .\n// { name: 'Jack Davis', age: 40}\n```\n\n`eventOfTypes$`: filter the `event$` to only get the events whose type is includes in the argument list\n\n```js\neventOfTypes$('click', 'scroll', 'mousedown');\n```\n\n`event$`: default export, it's the underlying event stream, which is basiclly a `Rxjs Subject` instance\n\n# Complete examples\n\n```js\nimport event$, {\n  emitEvent,\n  eventPayloadOfType$,\n  eventOfTypes$\n} from 'rx-event';\n\nfunction emitSomeEvents() {\n  emitEvent('user-request', 'john');\n  emitEvent('user-fetched', { name: 'John Doe', age: 26 });\n  emitEvent('user-fetched', { name: 'Jack Davis', age: 40 });\n  emitEvent('scroll-down');\n}\n\neventPayloadOfType$('user-fetched')\n  .map(user =\u003e user.name)\n  .subscribe(name =\u003e console.log(name));\n/*\n    John Doe\n    Jack Davis\n*/\n\neventOfTypes$('user-request', 'user-fetched').subscribe(events =\u003e\n  console.log(events)\n);\n/* output:\n{ type: 'user-request', payload: 'john' }\n{ type: 'user-fetched', payload: { name: 'John Doe', age: 26 } }\n{ type: 'user-fetched', payload: { name: 'Jack Davis', age: 40 } }\n*/\n\n//get the events without payload\nevent$.filter(event =\u003e !event.payload).subscribe(user =\u003e console.log(user));\n// { type: 'scroll-down' }\n\n//emit an event on page scroll\nwindow.addEventListener('scroll', e =\u003e emitEvent('scroll', e));\n//debounce the scroll events with 300ms\neventPayloadOfType$('scroll')\n  .debounceTime(300)\n  .subscribe(e =\u003e console.log(e));\n\n//autocomplete example.\ndocument\n  .getElementById('#search')\n  .addEventListener('change', e =\u003e emitEvent('search-changed', e.value));\n\neventPayloadOfType$('search-changed')\n  .debounceTime(500)\n  .distinctUntilChanged()\n  .switchMap(searchValue =\u003e searchWikiPedia(searchValue));\n\n//call the function to emit some events\nemitSomeEvents();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyongwangd%2Frx-event","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyongwangd%2Frx-event","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyongwangd%2Frx-event/lists"}