{"id":18534788,"url":"https://github.com/atomicojs/channel","last_synced_at":"2025-04-09T15:31:50.273Z","repository":{"id":57099555,"uuid":"376566090","full_name":"atomicojs/channel","owner":"atomicojs","description":null,"archived":false,"fork":false,"pushed_at":"2022-05-08T20:56:34.000Z","size":71,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-29T09:52:24.729Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/atomicojs.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":"2021-06-13T14:38:18.000Z","updated_at":"2022-05-08T20:56:37.000Z","dependencies_parsed_at":"2022-08-20T17:31:36.704Z","dependency_job_id":null,"html_url":"https://github.com/atomicojs/channel","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atomicojs%2Fchannel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atomicojs%2Fchannel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atomicojs%2Fchannel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atomicojs%2Fchannel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/atomicojs","download_url":"https://codeload.github.com/atomicojs/channel/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247795868,"owners_count":20997485,"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":[],"created_at":"2024-11-06T19:16:56.771Z","updated_at":"2025-04-09T15:31:50.223Z","avatar_url":"https://github.com/atomicojs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @atomico/channel\n\n`@atomico/channel` allows sharing states between WebComponents or DOM easily.\n\n![Example](https://i.ibb.co/DfWvg85/Grupo-38.png)\n\nThis API is inspired by the objectives of React Context, but eliminates the complexity and is an agnostic implementation.\n\n## What is a channel?\n\nA channel is a sender and a receiver of status through the native event system of the DOM, a channel has the following logic:\n\n1. read the context of parent\n2. modify the context for children\n\n## Example\n\nThis is an example where the webcomponent subscribes to the parent node:\n\n```js\nimport { Channel } from \"@atomico/channel\";\n\nconst CHANNEL = \"MyChannel\";\n// Parent channel\nconst parentChannel = new Channel(document.body, CHANNEL);\n\nclass MyComponent extends HTMLElement {\n    constructor() {\n        super();\n        // Child channel\n        this.channel = new Channel(this, CHANNEL);\n    }\n    connectedcallback() {\n        this.channel.connected(\n            (data) =\u003e (this.textContent = JSON.stringify(data))\n        );\n    }\n    disconnectedCallback() {\n        this.channel.disconnect();\n    }\n}\n\n// Connect the channel to the native DOM event system\nparentChannel.connect();\n\nparentChannel.cast(\"I'm your father\");\n```\n\n## API\n\n### Channel()\n\n```js\nconst channel = new Channel(\n    // Element\n    host,\n    // string\n    \"idString\",\n    // associates the composed option to the event\n    // this allows bypassing the shadowDOM when connecting the channels\n    true\n);\n```\n\n### channel.connect()\n\n```js\nchannel.connect(optionalCallback);\n```\n\nWhere:\n\n1. `optionalCallback`: optional callback that allows to read the transmissions of the parent.\n\n### channel.disconect()\n\nRemove subscriptions\n\n### channel.cast()\n\nIssues a new broadcast to the child channels\n\n```js\nchannel.cast(10);\nchannel.cast({ data });\n```\n\nExecuting this method prevents any transmission from the parent from spreading to the children of this channel.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatomicojs%2Fchannel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fatomicojs%2Fchannel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatomicojs%2Fchannel/lists"}