# poolparty

> poolparty.js was created to reduce the overhead of creating expensive objects such as views, dom elements, etc. It's used in [paperclip.js](/classdojo/paperclip.js), and [mojo.js](/classdojo/mojo.js).

Latest version **0.0.9** (published 2014-03-27) · BSD license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.9 |
| Published | 2014-03-27 |
| First published | 2013-03-25 |
| Weekly downloads | 0 |
| License | BSD |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | architectd |

## Links

- npm: https://www.npmjs.com/package/poolparty
- Repository: https://github.com/classdojo/poolparty.js
- Issues: https://github.com/classdojo/poolparty.js/issues
- npm.io page: https://npm.io/package/poolparty

## Dependencies (2)

- [boojs](https://npm.io/package/boojs.md) 0.0.7
- [protoclass](https://npm.io/package/protoclass.md) 0.0.x

## Recent versions

- 0.0.9 (latest) — 2014-03-27
- 0.0.8 — 2014-02-28
- 0.0.5 — 2014-01-04
- 0.0.4 — 2014-01-04
- 0.0.3 — 2013-12-01
- 0.0.2 — 2013-03-26
- 0.0.1 — 2013-03-26
- 0.0.0 — 2013-03-25

## README

### Object Pooling & Recycling [![Alt ci](https://travis-ci.org/classdojo/poolparty.js.png)](https://travis-ci.org/classdojo/poolparty.js)

poolparty.js was created to reduce the overhead of creating expensive objects such as views, dom elements, etc. It's used in [paperclip.js](/classdojo/paperclip.js), and [mojo.js](/classdojo/mojo.js).


First create an object that you want to add to the pool party:

```javascript

var poolParty = require("poolparty");

function SomeView (options) {
  this.reset(options);
}


SomeView.prototype.render = function () {
  // do something
}

SomeView.prototype.reset = function (options) {
  // reset options on the view
}

SomeView.prototype.dispose = function () {
  SomeView.pool.add(this);
}


SomeView.pool = poolParty({
  create: function (options) {
    return new SomeView(options);
  },
  recycle: function (someView, options) {
    someView.reset(options);
  }
});


module.exports = SomeView;
```

Next, use it:

```javascript
var SomeView = require("./someView");

// create the view
var view = SomeView.pool.create({});

// do stuff
view.render();

// we're done with the view, dispose it
view.dispose();

// call "create" again - it's the same view.
console.log(SomeView.pool.create({}) === view); // true
```


### API

#### pool poolparty(options)

- `max` - the max number of objects allowed in a pool
- `min` - minimum number of items to use in the pool
- `keepAliveTimeout` - the number of MS before destroying a stale object
- `factory` - the function which creates a pool object
- `recycle` - called whenever an object is recycled


### pool.size()

returns the size of the pool

### pool.drip()

removes one item from the pool

### pool.drain()

removes all items from the pool except the min

### object pool.add(item)

Adds an object to the pool

### object pool.create(options)

creates, or uses a recycled object


### object.dispose()

disposes the object, and adds it back to the object pool

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