{"id":15650726,"url":"https://github.com/luwes/disco","last_synced_at":"2025-09-12T14:32:04.400Z","repository":{"id":42917139,"uuid":"248363966","full_name":"luwes/disco","owner":"luwes","description":"Easy and universal way to react to elements being disconnected and connected from the DOM aka lifecycle methods.","archived":false,"fork":false,"pushed_at":"2024-09-11T13:01:23.000Z","size":1421,"stargazers_count":34,"open_issues_count":16,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-03T05:47:53.373Z","etag":null,"topics":["connected","disconnected","dom","lifecycle","universal"],"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/luwes.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":"2020-03-18T23:16:19.000Z","updated_at":"2023-09-18T08:59:50.000Z","dependencies_parsed_at":"2024-10-03T12:37:36.835Z","dependency_job_id":"65b6d2c1-8884-40ba-ac33-da240b14a2dd","html_url":"https://github.com/luwes/disco","commit_stats":{"total_commits":10,"total_committers":1,"mean_commits":10.0,"dds":0.0,"last_synced_commit":"b9068c31e48d106330bc820147e545137f25a8ba"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luwes%2Fdisco","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luwes%2Fdisco/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luwes%2Fdisco/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luwes%2Fdisco/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/luwes","download_url":"https://codeload.github.com/luwes/disco/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232747700,"owners_count":18570504,"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":["connected","disconnected","dom","lifecycle","universal"],"created_at":"2024-10-03T12:35:38.728Z","updated_at":"2025-01-06T16:09:25.995Z","avatar_url":"https://github.com/luwes.png","language":"JavaScript","readme":"# Disco 🕺\n\n[![Version](https://img.shields.io/npm/v/disco.svg?color=success\u0026style=flat-square)](https://www.npmjs.com/package/disco)\n![Badge size](https://img.badgesize.io/https://unpkg.com/disco/dist/disco.min.js?v=1\u0026compression=gzip\u0026label=gzip\u0026style=flat-square\u0026v=1)\n\n\n**npm**: `npm i disco`  \n**cdn**: https://unpkg.com/disco  \n\nEasy and universal way to react to elements being `disconnected` and `connected` via native DOM events.\n\nObserve via a direct node reference, an array of nodes or a string selector that internally makes use of `Element.matches(selectorString)`. It's recommended to keep the observed scope as small as possible for the best performance. \n\n\n## Example\n\n```js\nimport { observe } from 'disco';\n\n/**\n * Observe one specific div element\n */\nconst div = document.createElement('div');\nobserve(div);\n\ndiv.addEventListener('connected', () =\u003e console.log('connected!'));\ndocument.body.append(div);\n\n/******************************************************************/\n\n/**\n * Observe all (future) h1 elements.\n */\nobserve('h1');\nconst firstH1 = document.createElement('h1');\nconst lastH1 = document.createElement('h1');\n\nfirstH1.addEventListener('connected', () =\u003e console.log('connected!'));\nlastH1.addEventListener('connected', () =\u003e console.log('connected!'));\n\ndocument.body.append(firstH1, lastH1);\n\n/******************************************************************/\n\n/**\n * Observe all section elements in the document for removal.\n */\nconst sections = document.querySelectorAll('section');\nobserve(...sections);\n[...sections].forEach(section =\u003e\n  section.addEventListener('disconnected', () =\u003e console.log('🕺')))\n```\n\n## API\n\n\u003cdl\u003e\n\u003cdt\u003e\u003ca href=\"#observe\"\u003eobserve(...nodesOrSelectors)\u003c/a\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003eObserve a node, array of nodes or an element selector for dis-connected events.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#unobserve\"\u003eunobserve([...nodesOrSelectors])\u003c/a\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003eUnobserve for dis-connected events.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\n\u003ca name=\"observe\"\u003e\u003c/a\u003e\n\n## observe(...nodesOrSelectors)\nObserve a node, array of nodes or an element selector for dis-connected events.\n\n**Kind**: global function\n\n| Param | Type |\n| --- | --- |\n| ...nodesOrSelectors | \u003ccode\u003eNode\u003c/code\u003e \\| \u003ccode\u003eString\u003c/code\u003e |\n\n\u003ca name=\"unobserve\"\u003e\u003c/a\u003e\n\n## unobserve([...nodesOrSelectors])\nUnobserve for dis-connected events.\n\n**Kind**: global function\n\n| Param | Type |\n| --- | --- |\n| [...nodesOrSelectors] | \u003ccode\u003eNode\u003c/code\u003e \\| \u003ccode\u003eString\u003c/code\u003e |\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluwes%2Fdisco","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fluwes%2Fdisco","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluwes%2Fdisco/lists"}