# dom-callcount

> Track callcount of dom apis. Useful for vdom-testing.

Latest version **2.0.1** (published 2017-12-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install dom-callcount
pnpm add dom-callcount
yarn add dom-callcount
bun add dom-callcount
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2017-12-05 |
| First published | 2017-07-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Marvin Hagemeister |
| Maintainers | marvinhagemeister |

## Links

- npm: https://www.npmjs.com/package/dom-callcount
- Repository: https://github.com/marvinhagemeister/dom-callcount
- Homepage: https://github.com/marvinhagemeister/dom-callcount#readme
- Issues: https://github.com/marvinhagemeister/dom-callcount/issues
- npm.io page: https://npm.io/package/dom-callcount

## Recent versions

- 2.0.1 (latest) — 2017-12-05
- 2.0.0 — 2017-12-05
- 1.1.1 — 2017-12-05
- 1.1.0 — 2017-07-03
- 1.0.0 — 2017-07-02

## README

# DOM CallCount

`dom-callcount` is a tiny library to track calls to the `DOM`. The main use
case is for developers of virtual-dom libraries which want to minimize dom
operations as much as possible.

If you're testing in a real browser you should use a [MutationObserver](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver) instead. This library is mainly for environments where `MutationObserver` is not available, because the latter is quite hard to polyfill.

This library is heavily inspired by these [utils](https://github.com/ivijs/ivi/blob/bef9db3205e168c00a4e2242ae2c7166b2b7be88/packages/ivi/tests/utils/dom.ts) from [ivi](https://github.com/ivijs/ivi).

## Installation

```bash
# npm
npm install --save-dev dom-callcount

# yarn
yarn add --dev dom-callcount
```

## Usage

Under the hood it works by spying on the `prototype` of `Node` and `Document`.
After the callback is called, these are restored to their previous state and
all spies are removed.

```js
import observe from "dom-callcount";

const result = observe(() => {
  const div = document.createElement("div");
  const text = document.createTextNode("foo");
  div.appendChild(text);
});

console.log(result);
// Logs:
// {
//   createElement: 1,
//   createTextNode: 1,
//   appendChild: 1,
// }
```

## License

MIT, see [License](LICENSE.md).

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