# disconnected

> Enables `connected` and `disconnected` element's listeners.

Latest version **0.2.1** (published 2019-05-24) · ISC license · 0 weekly downloads

## Install

```sh
npm install disconnected
pnpm add disconnected
yarn add disconnected
bun add disconnected
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2019-05-24 |
| First published | 2018-11-15 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 39 |
| Author | Andrea Giammarchi |
| Maintainers | webreflection |
| Keywords | connected, disconnected, dom, events |

## Links

- npm: https://www.npmjs.com/package/disconnected
- Repository: https://github.com/WebReflection/disconnected
- Homepage: https://github.com/WebReflection/disconnected#readme
- Issues: https://github.com/WebReflection/disconnected/issues
- npm.io page: https://npm.io/package/disconnected

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 0.2.1 (latest) — 2019-05-24
- 0.2.0 — 2019-05-24
- 0.1.6 — 2018-11-30
- 0.1.5 — 2018-11-18
- 0.1.4 — 2018-11-16
- 0.1.3 — 2018-11-16
- 0.1.2 — 2018-11-16
- 0.1.1 — 2018-11-16
- 0.1.0 — 2018-11-15
- 0.0.0 — 2018-11-15

## README

# disconnected

[![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)

In 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.

The 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.

```js
// requires both modern Event and WeakSet
import disconnected from 'disconnected';
const observe = disconnected({Event, WeakSet});

observe(mainElement);
mainElement.addEventListener('connected', () => {
  console.log('I am alive ;-)');
});
mainElement.addEventListener('disconnected', () => {
  console.log('but now I am out O_O');
});

observe(subElement);
observe(topElement);
observe(anyElement);
```


### Compatibility

[Even IE9](https://webreflection.github.io/disconnected/test/), as long as a usable `Event` and `WeakSet` are provided.


### What about `attributechanged` ?

You [got it](https://github.com/WebReflection/attributechanged), sharing same API, needing same `Event` poly, if necessary.


### DOM Level 0 Like events ?

Using [with-level-0](https://github.com/WebReflection/with-level-0) would make it possible to have `el.onconnected = ...` simplification too.
```js
withLevel0('connected');
withLevel0('disconnected');

// remember to observe the node
var div = observe(document.createElement('div'));

// add your Level 0 listener
div.onconnected = function () {
  div.textContent = 'Level 0';
};

// that's it!
document.body.appendChild(div);

// feel free to clean it up via
div.onconnected = null;
```

---
_Source: https://npm.io/package/disconnected · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
