# uconnect

> An essential connected/disconnected DOM helper

Latest version **0.3.0** (published 2021-05-06) · ISC license · 0 weekly downloads

## Install

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

## 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.3.0 |
| Published | 2021-05-06 |
| First published | 2020-12-16 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 15 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 20 |
| Author | Andrea Giammarchi |
| Maintainers | webreflection |
| Keywords | DOM, connected, disconnected, events |

## Links

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

## 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.3.0 (latest) — 2021-05-06
- 0.2.8 — 2021-02-20
- 0.2.7 — 2020-12-19
- 0.2.5 — 2020-12-17
- 0.2.4 — 2020-12-17
- 0.2.3 — 2020-12-17
- 0.2.2 — 2020-12-17
- 0.2.1 — 2020-12-17
- 0.2.0 — 2020-12-17
- 0.1.4 — 2020-12-17
- 0.1.3 — 2020-12-17
- 0.1.2 — 2020-12-17
- 0.1.1 — 2020-12-16
- 0.1.0 — 2020-12-16
- 0.0.4 — 2020-12-16
- … 4 more at https://npm.io/package/uconnect/versions

## README

# <em>µ</em>connect

[![CSP strict](https://webreflection.github.io/csp/strict.svg)](https://webreflection.github.io/csp/#-csp-strict)

<sup>**Social Media Photo by [JOHN TOWNER](https://unsplash.com/@heytowner) on [Unsplash](https://unsplash.com/)**</sup>

A modern take at [disconnected](https://github.com/WebReflection/disconnected#readme) module, dropping IE < 11 support and providing a much better API.

**[Live demo](https://codepen.io/WebReflection/pen/zYKwbgR?editors=0011)**

```js
import {observe} from 'uconnect';

const observer = observe(
  root = document,      // the default root node to observe
  parse = 'children',   // the kind of nodes to parse: children or childNodes
  CE = CustomEvent,     // the default Event/CustomEvent constructor to use
  MO = MutationObserver // the default MutationObserver constructor to use
);

const node = document.createElement('button');

observer.connect(node, {
  connected(event) {
    // node is connected
    console.log(`node is ${event.type}`);
  },
  disconnected(event) {
    // node is disconnected
    console.log(`node is ${event.type}`);
  }
});

// will trigger connected(event)
document.body.appendChild(node);

setTimeout(() => {
  // will trigger disconnect(event)
  node.remove();

  setTimeout(() => {
    // will stop observing this specific node
    // after removing connecetd/disconnected listeners
    observer.disconnect(node);

    // will stop observing all nodes
    // and disconnect the MutationObserver
    observer.kill();
  });
});
```

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