# dom-batch

> Eliminates layout thrashing by batching DOM read/write interactions

Latest version **0.3.1** (published 2013-08-26) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities; high maintenance score.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.3.1 |
| Published | 2013-08-26 |
| First published | 2013-08-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6912 |
| Author | Wilson Page |
| Maintainers | wilsonpage |

## Links

- npm: https://www.npmjs.com/package/dom-batch
- Repository: https://github.com/wilsonpage/dom-batch
- npm.io page: https://npm.io/package/dom-batch

## Recent versions

- 0.3.1 (latest) — 2013-08-26

## README

# dom-batch [![Build Status](https://travis-ci.org/wilsonpage/dom-batch.png?branch=master)](https://travis-ci.org/wilsonpage/dom-batch)

Eliminates layout thrashing by batching DOM read/write interactions.

```js
var dom = new DomBatch();

dom.read(function() {
  console.log('<DOM Read>');
});

dom.write(function() {
  console.log('<DOM Write>');
});

dom.read(function() {
  console.log('<DOM Read>');
});

dom.write(function() {
  console.log('<DOM Write>');
});

// Output:

<DOM Read>
<DOM Read>
<DOM Write>
<DOM Write>
```

## API

### DomBatch#read(callback[, context])

Schedules a task for the 'read' queue.

```js
dom.read(function() {
  var width = element.clientWidth;
});
```

### DomBatch#write(callback[, context])

Schedules a task for the 'write' queue.

```js
dom.write(function() {
  element.style.width = width + 'px';
});
```

### DomBatch#clearRead(callback)

Removes a task from the 'read' queue.

```js
var fn = function(){};

dom.read(fn);
dom.clearRead(fn);
```

### DomBatch#clearWrite(callback)

Removes a task from the 'write' queue.

```js
var fn = function(){};

dom.write(fn);
dom.clearWrite(fn);
```

## Tests

#### With PhantomJS

```
$ npm install
$ npm test
```

#### Without PhantomJS

```
$ node_modules/.bin/buster-static
```

...then visit http://localhost:8282/ in browser

## Author

- **Wilson Page** - [@wilsonpage](http://github.com/wilsonpage)

## Contributors

- **Wilson Page** - [@wilsonpage](http://github.com/wilsonpage)
- **George Crawford** - [@georgecrawford](http://github.com/georgecrawford)

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