# ready-mixin

> Ready mixin for classes with async constructor

Latest version **2.0.0** (published 2015-10-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install ready-mixin
pnpm add ready-mixin
yarn add ready-mixin
bun add ready-mixin
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2015-10-02 |
| First published | 2015-05-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Kirill Fomichev |
| Maintainers | fanatid |
| Keywords | ready, mixin, promise |

## Links

- npm: https://www.npmjs.com/package/ready-mixin
- Repository: https://github.com/fanatid/ready-mixin
- Homepage: https://github.com/fanatid/ready-mixin#readme
- Issues: https://github.com/fanatid/ready-mixin/issues
- npm.io page: https://npm.io/package/ready-mixin

## Dependencies (1)

- [babel-runtime](https://npm.io/package/babel-runtime.md) ^5.8.20

## Recent versions

- 2.0.0 (latest) — 2015-10-02
- 1.0.0 — 2015-08-29
- 0.1.0 — 2015-08-08
- 0.0.5 — 2015-05-29
- 0.0.4 — 2015-05-26
- 0.0.3 — 2015-05-15
- 0.0.2 — 2015-05-14
- 0.0.1 — 2015-05-14

## README

# ready-mixin

[![build status](https://img.shields.io/travis/fanatid/ready-mixin.svg?branch=master&style=flat-square)](http://travis-ci.org/fanatid/ready-mixin)
[![Coverage Status](https://img.shields.io/coveralls/fanatid/ready-mixin.svg?style=flat-square)](https://coveralls.io/r/fanatid/ready-mixin)
[![Dependency status](https://img.shields.io/david/fanatid/ready-mixin.svg?style=flat-square)](https://david-dm.org/fanatid/ready-mixin#info=dependencies)
[![Dev Dependency status](https://img.shields.io/david/fanatid/ready-mixin.svg?style=flat-square)](https://david-dm.org/fanatid/ready-mixin#info=devDependencies)

[![NPM](https://nodei.co/npm/ready-mixin.png?downloads=true)](https://www.npmjs.com/package/ready-mixin)
[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)

You have class with async constructor and you don't want use callback in constructor or make inheritance from some event emitter? Try [ready-mixin](https://github.com/fanatid/ready-mixin)!

## Installation

```
npm install ready-mixin
```

## API

### _ready(err, ...)

Resolve or reject ready promise.

### ready()

Return ready promise.

**return**: `Promise`

### onReady(callback, opts)

  * `function` callback is node-style callback function
  * `Object` [opts]
    * `boolean` [spread]

### isReady()

Return current ready status.

**return**: `boolean`

## Examples

###

```js
import { mixin } from 'core-decorators'
import ReadyMixin from 'ready-mixin'

@mixin(ReadyMixin)
class User {
  constructor (userId) {
    db.load(userId, (err, data) => {
      if (err === null) {
        this._data = data
      }

      this._ready(err)
    })
  }
}

let user = new User(0)
user.ready
  .then(() => {
    console.log('user was loaded!')
  }, (err) => {
    console.log('error on loading user!', err)
  })
```

### spread in onReady

```js
import { mixin } from 'core-decorators'
import ReadyMixin from 'ready-mixin'

@mixin(ReadyMixin)
class A {
  constructor () {
    setTimeout(() => { this._ready(null, 1, 2, 3) }, 1000)
  }
}

let a = new A()
a.onReady((err, v1, v2, v3) => {
  console.log(`Sum: ${v1 + v2 + v3}`) // Sum: 6
}, {spread: true})
```

## License

Code released under [the MIT license](LICENSE).

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