{"id":13561620,"url":"https://github.com/mia1024/cross-context-events","last_synced_at":"2025-04-06T12:11:47.041Z","repository":{"id":57210755,"uuid":"388695894","full_name":"mia1024/cross-context-events","owner":"mia1024","description":null,"archived":false,"fork":false,"pushed_at":"2024-02-19T04:16:55.000Z","size":2497,"stargazers_count":234,"open_issues_count":0,"forks_count":10,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-30T08:08:53.206Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mia1024.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":"2021-07-23T06:11:40.000Z","updated_at":"2024-12-31T09:45:36.000Z","dependencies_parsed_at":"2024-08-01T13:17:24.585Z","dependency_job_id":"a4903427-99a4-4ff3-85dc-3a8923a34870","html_url":"https://github.com/mia1024/cross-context-events","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mia1024%2Fcross-context-events","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mia1024%2Fcross-context-events/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mia1024%2Fcross-context-events/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mia1024%2Fcross-context-events/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mia1024","download_url":"https://codeload.github.com/mia1024/cross-context-events/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247478324,"owners_count":20945266,"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-08-01T13:00:59.233Z","updated_at":"2025-04-06T12:11:47.023Z","avatar_url":"https://github.com/mia1024.png","language":"TypeScript","funding_links":[],"categories":["Uncategorized"],"sub_categories":["Uncategorized"],"readme":"# Cross Context Events\n\n![](https://badgen.net/npm/v/cross-context-events)\n![](https://badgen.net/bundlephobia/min/cross-context-events)\n![](https://badgen.net/bundlephobia/minzip/cross-context-events)\n![](https://badgen.net/bundlephobia/dependency-count/cross-context-events)\n![](https://badgen.net/npm/types/cross-context-events)\n![](https://badgen.net/npm/license/cross-context-events)\n\nCross context events is a robust, lightweight package providing the option to\nsend and receive events across JS execution context.\n\nYou asked, what does this mean, exactly? Well, it means that when you emit an\nevent in your script, the same event will also be emitted in all other linked\nexecution contexts (i.e. other tabs, windows, processes), even on different\ncomputers if you want to! All you need to do is writing a few lines of code to\nlink them together.\n\n![demo](docs/demos/frames-and-windows/demo.gif)\n\n[Try the demo here](https://mia1024.github.io/cross-context-events/demos/frames-and-windows/)\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;  [Source code for the demo](https://github.com/mia1024/cross-context-events/tree/main/docs/demos/frames-and-windows)\n\n## Documentations\n\nSee [here](https://mia1024.github.io/cross-context-events/).\n\n## Features\n\n- Lightweight\n- No runtime dependency\n-\n\nComprehensive [documentations](https://mia1024.github.io/cross-context-events/)\n\n- Containerization\n    - Support for named and anonymous containers to provide isolation if you\n      need\n- Unified interface\n    - Works the same way whether you are using browser, service worker, node, or\n      even electron.\n- Cross Context\n    - Capable of sending events across execution context (e.g. from one tab to\n      another tab in browser or from one process to another process in Node)\n      with minimal setup, so long as an IPC channel can be established between\n      the sending context and receiving context.\n    - Relay support: events can be optionally relayed across the network if you\n      have one.\n- Typescript support\n    - Written completely in typescript completely with strong type inferences.\n- Comprehensive testing\n    - All core functions are unittested\n- Namespaced events and bubbling\n    - If you emit an event for `event.context.new`, then listeners for\n      `event.context` and `event` are also notified (but `event.context2` is\n      not). This behavior can be disabled if desired.\n      See [event bubbling](events?id=event-bubbling).\n- Event relaying\n    - Even if you have a network of nested iframes like the image below, and you\n      emit an event in iframe 9 (or any frame or the parent window for that\n      matter), it will be emitted in all frames and the parent window. This also\n      applies to a chain or child processes or workers or any other combinations\n      of communication channels.\n      See [event relaying](transports?id=event-relaying).\n\n      ![](docs/imgs/frametree.svg)\n\n## Installation\n\nUnpkg\n\n```html\n\n\u003cscript src=\"https://unpkg.com/cross-context-events/dist/cross-context-events.min.js\"\u003e\u003c/script\u003e\n```\n\njsDelivr\n\n```html\n\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/cross-context-events/dist/cross-context-events.min.js\"\u003e\u003c/script\u003e\n```\n\nyarn\n\n```bash\nyarn add cross-context-events\n```\n\nnpm\n\n```bash \nnpm install cross-context-events\n```\n\n## Getting started\n\nThis example uses the\n[WebWorker API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API)\n, but it can be easily switched to Node processes, iFrames, or others by simply\nchanging the transport used. For details, please refer\nto [transports](https://mia1024.github.io/cross-context-events/#/transports).\n\n```js\n// index.js\n\nimport {\n    useGlobalTransport,\n    createDefaultTransport,\n    createEvent\n} from \"cross-context-events\";\n\nconst OnlineEvent = createEvent(\"worker.online\")\nOnlineEvent.addListener(() =\u003e console.log(\"Worker is now online ＼(＾▽＾)／\"))\n\nlet worker = new Worker(\"worker.js\")\n\nuseGlobalTransport(createDefaultTransport({\n    type: \"worker\",\n    target: worker\n}))\n```\n\n```js\n// worker.js\n\nimport {\n    useGlobalTransport,\n    createDefaultTransport,\n    createEvent\n} from \"cross-context-events\";\n\nuseGlobalTransport(createDefaultTransport({\n    type: \"worker\",\n    target: self\n}))\n\nconst OnlineEvent = createEvent(\"worker.online\")\nnew OnlineEvent().emit()\n```\n\nAs you can see, `Worker is now online ＼(＾▽＾)／` has been logged to the console\nfrom the main thread. Yay!\n\nPlease refer to the\n[documentation](https://mia1024.github.io/cross-context-events/#/quickstart)\nfor more information. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmia1024%2Fcross-context-events","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmia1024%2Fcross-context-events","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmia1024%2Fcross-context-events/lists"}