{"id":20513744,"url":"https://github.com/webreflection/disconnected","last_synced_at":"2026-03-08T14:31:33.894Z","repository":{"id":57212417,"uuid":"157767981","full_name":"WebReflection/disconnected","owner":"WebReflection","description":"Enables `connected` and `disconnected` element's listeners.","archived":false,"fork":false,"pushed_at":"2020-05-27T10:39:54.000Z","size":19,"stargazers_count":38,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-11T15:50:14.885Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://webreflection.github.io/disconnected/test/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WebReflection.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":"2018-11-15T20:22:54.000Z","updated_at":"2024-11-03T10:13:42.000Z","dependencies_parsed_at":"2022-08-29T02:30:17.910Z","dependency_job_id":null,"html_url":"https://github.com/WebReflection/disconnected","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Fdisconnected","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Fdisconnected/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Fdisconnected/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Fdisconnected/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WebReflection","download_url":"https://codeload.github.com/WebReflection/disconnected/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248799931,"owners_count":21163403,"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-15T21:12:53.215Z","updated_at":"2025-10-06T17:14:38.361Z","avatar_url":"https://github.com/WebReflection.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# disconnected\n\n[![Build Status](https://travis-ci.com/WebReflection/disconnected.svg?branch=master)](https://travis-ci.com/WebReflection/disconnected) [![Greenkeeper badge](https://badges.greenkeeper.io/WebReflection/disconnected.svg)](https://greenkeeper.io/) ![WebReflection status](https://offline.report/status/webreflection.svg)\n\nIn less than 0.5K, it enables `connected` and `disconnected` element's listeners in [hyperHTML](https://github.com/WebReflection/hyperHTML#hyperhtml), but it can also be used with any other library/vanilla JS.\n\nThe only optional dependencies it has are constructable `Event` and the `WeakSet`. Both must be passed along as configuration object, and polyfills might be needed only for legacy browsers.\n\n```js\n// requires both modern Event and WeakSet\nimport disconnected from 'disconnected';\nconst observe = disconnected({Event, WeakSet});\n\nobserve(mainElement);\nmainElement.addEventListener('connected', () =\u003e {\n  console.log('I am alive ;-)');\n});\nmainElement.addEventListener('disconnected', () =\u003e {\n  console.log('but now I am out O_O');\n});\n\nobserve(subElement);\nobserve(topElement);\nobserve(anyElement);\n```\n\n\n### Compatibility\n\n[Even IE9](https://webreflection.github.io/disconnected/test/), as long as a usable `Event` and `WeakSet` are provided.\n\n\n### What about `attributechanged` ?\n\nYou [got it](https://github.com/WebReflection/attributechanged), sharing same API, needing same `Event` poly, if necessary.\n\n\n### DOM Level 0 Like events ?\n\nUsing [with-level-0](https://github.com/WebReflection/with-level-0) would make it possible to have `el.onconnected = ...` simplification too.\n```js\nwithLevel0('connected');\nwithLevel0('disconnected');\n\n// remember to observe the node\nvar div = observe(document.createElement('div'));\n\n// add your Level 0 listener\ndiv.onconnected = function () {\n  div.textContent = 'Level 0';\n};\n\n// that's it!\ndocument.body.appendChild(div);\n\n// feel free to clean it up via\ndiv.onconnected = null;\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebreflection%2Fdisconnected","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebreflection%2Fdisconnected","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebreflection%2Fdisconnected/lists"}