{"id":13540757,"url":"https://github.com/vitalets/chnl","last_synced_at":"2025-04-28T16:23:32.988Z","repository":{"id":57198159,"uuid":"58473461","full_name":"vitalets/chnl","owner":"vitalets","description":"JavaScript event channels compatible with Chrome extensions API","archived":false,"fork":false,"pushed_at":"2020-07-16T10:03:10.000Z","size":1725,"stargazers_count":19,"open_issues_count":4,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-15T11:52:05.458Z","etag":null,"topics":["event-emitter","eventbus","eventemitter","events","listener","pubsub","subscription"],"latest_commit_sha":null,"homepage":"https://vitalets.github.io/chnl","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/vitalets.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}},"created_at":"2016-05-10T15:37:19.000Z","updated_at":"2023-04-29T13:56:12.000Z","dependencies_parsed_at":"2022-09-16T13:12:30.514Z","dependency_job_id":null,"html_url":"https://github.com/vitalets/chnl","commit_stats":null,"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitalets%2Fchnl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitalets%2Fchnl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitalets%2Fchnl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitalets%2Fchnl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vitalets","download_url":"https://codeload.github.com/vitalets/chnl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251343368,"owners_count":21574349,"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-emitter","eventbus","eventemitter","events","listener","pubsub","subscription"],"created_at":"2024-08-01T10:00:32.326Z","updated_at":"2025-04-28T16:23:32.970Z","avatar_url":"https://github.com/vitalets.png","language":"JavaScript","funding_links":[],"categories":["Tools"],"sub_categories":["Development"],"readme":"# chnl\n[![Actions Status](https://github.com/vitalets/chnl/workflows/autotests/badge.svg)](https://github.com/vitalets/chnl/actions)\n[![npm version](https://badge.fury.io/js/chnl.svg)](https://badge.fury.io/js/chnl)\n[![license](https://img.shields.io/npm/l/chnl.svg)](https://www.npmjs.com/package/chnl)\n\nImplementation of event channels (aka pub/sub, dispatcher, emitter) inspired and\ncompatible with [Chrome extensions Events API](https://developer.chrome.com/extensions/events#type-Event).\n\n## Install\n```\nnpm i chnl\n```\n\n## Docs\nhttps://vitalets.github.io/chnl\n\n## Usage\n**foo.js**\n```js\nimport Channel from 'chnl';\n\n// create channel\nexport const onData = new Channel();\n\n// subscribe to channel\nonData.addListener(data =\u003e console.log(data));\n```\n\n**bar.js**\n```js\nimport {onData} from './foo';\n\n// dispatch event to channel\nonData.dispatch({foo: 'bar'});\n```\n\n### Adding/removing listeners in dispatching loop\nChnl makes a copy of the listeners before starting dispatching loop.\nSo modifying listeners list (adding/removing) in dispatching loop will affect only the next dispatch:\n```js\nconst onData = new Channel();\nconst listener1 = () =\u003e console.log(1);\nconst listener2 = () =\u003e {\n  console.log(2);\n  onData.addListener(listener3);\n};\nconst listener3 = () =\u003e console.log(3);\nonData.addListener(listener1);\nonData.addListener(listener2);\n\nonData.dispatch();\n// 1\n// 2\nonData.dispatch();\n// 1\n// 2\n// 3\n```\n\n## License\nMIT @ [Vitaliy Potapov](https://github.com/vitalets)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvitalets%2Fchnl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvitalets%2Fchnl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvitalets%2Fchnl/lists"}