2.0.1 • Published 6 years ago

dom-callcount v2.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

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 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 from ivi.

Installation

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

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.

2.0.1

6 years ago

2.0.0

6 years ago

1.1.1

6 years ago

1.1.0

7 years ago

1.0.0

7 years ago